Add move support for scoped_refptr.

scoped_ptr has
- move constructor.
- move assignment operator.
- .Pass().

This CL adds the same support for scoped_refptr.
The main benefit is reducing unnecessary reference counter updates.

// Example 1

class Foo {
  // Without .Pass(), a copy constructor would be called, which
  // increments and decrements the reference counter unnecessarily.
  // With .Pass(), a move constructor is called which doesn't update
  // the reference counter
  Foo(scoped_refptr<T> t) : t_(t.Pass()) {}

  const scoped_refptr<T> t_;
};

// Example 2

scoped_refptr<Foo> func() {
  return scoped_refptr<Foo>(new Foo());
}

main() {
  scoped_refptr<Foo> foo;

  // The following would be done by a copy assignment operator before,
  // but now a move assignment operator will be used instead.
  foo = func();
}

// Example 3

class Foo : public base::RefCountedThreadSafe<Foo> {
  ...
}

void func(scoped_refptr<Foo> foo) {
  ...
}

main() {
  scoped_refptr<Foo> foo(...);

  // Because it's moved, the reference counter won't be updated.
  massage_loop->PostTask(FROM_HERE,
      base::Bind(&func, base::Passed(foo)));
}

Review URL: https://codereview.chromium.org/1076953002

Cr-Commit-Position: refs/heads/master@{#324910}
3 files changed