[go: nahoru, domu]

Discourage use of base::Passed().

See discussion thread: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8PJU6CEyGwg

No-Try: true
Bug: 812523
Change-Id: Ie021ad6803dbbaf02a4caba37c6b8a50a006b251
Reviewed-on: https://chromium-review.googlesource.com/919066
Commit-Queue: Max Morin <maxmorin@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537637}
diff --git a/base/bind.h b/base/bind.h
index d1723b1e..b57a969c 100644
--- a/base/bind.h
+++ b/base/bind.h
@@ -364,13 +364,16 @@
 // argument will CHECK() because the first invocation would have already
 // transferred ownership to the target function.
 //
+// Note that Passed() is not necessary with BindOnce(), as std::move() does the
+// same thing. Avoid Passed() in favor of std::move() with BindOnce().
+//
 // EXAMPLE OF Passed():
 //
 //   void TakesOwnership(std::unique_ptr<Foo> arg) { }
-//   std::unique_ptr<Foo> CreateFoo() { return std::unique_ptr<Foo>(new Foo());
+//   std::unique_ptr<Foo> CreateFoo() { return std::make_unique<Foo>();
 //   }
 //
-//   std::unique_ptr<Foo> f(new Foo());
+//   auto f = std::make_unique<Foo>();
 //
 //   // |cb| is given ownership of Foo(). |f| is now NULL.
 //   // You can use std::move(f) in place of &f, but it's more verbose.
@@ -388,11 +391,6 @@
 //   cb.Run();  // Foo() is now transferred to |arg| and deleted.
 //   cb.Run();  // This CHECK()s since Foo() already been used once.
 //
-// Passed() is particularly useful with PostTask() when you are transferring
-// ownership of an argument into a task, but don't necessarily know if the
-// task will always be executed. This can happen if the task is cancellable
-// or if it is posted to a TaskRunner.
-//
 // We offer 2 syntaxes for calling Passed().  The first takes an rvalue and
 // is best suited for use with the return value of a function or other temporary
 // rvalues. The second takes a pointer to the scoper and is just syntactic sugar