Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: base/threading/post_task_and_reply_impl_unittest.cc

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: s/base::ResetAndReturn/std::move/ Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/threading/post_task_and_reply_impl.h" 5 #include "base/threading/post_task_and_reply_impl.h"
6 6
7 #include <utility>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
11 #include "base/test/test_simple_task_runner.h" 13 #include "base/test/test_simple_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
13 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 using ::testing::_; 18 using ::testing::_;
17 19
18 namespace base { 20 namespace base {
19 namespace internal { 21 namespace internal {
20 22
21 namespace { 23 namespace {
22 24
23 class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl { 25 class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl {
24 public: 26 public:
25 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination) 27 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination)
26 : destination_(destination) {} 28 : destination_(destination) {}
27 29
28 private: 30 private:
29 bool PostTask(const tracked_objects::Location& from_here, 31 bool PostTask(const tracked_objects::Location& from_here,
30 const Closure& task) override { 32 Closure task) override {
31 return destination_->PostTask(from_here, task); 33 return destination_->PostTask(from_here, std::move(task));
32 } 34 }
33 35
34 // Non-owning. 36 // Non-owning.
35 TaskRunner* const destination_; 37 TaskRunner* const destination_;
36 }; 38 };
37 39
38 class ObjectToDelete : public RefCounted<ObjectToDelete> { 40 class ObjectToDelete : public RefCounted<ObjectToDelete> {
39 public: 41 public:
40 // |delete_flag| is set to true when this object is deleted 42 // |delete_flag| is set to true when this object is deleted
41 ObjectToDelete(bool* delete_flag) : delete_flag_(delete_flag) { 43 ObjectToDelete(bool* delete_flag) : delete_flag_(delete_flag) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 testing::Mock::VerifyAndClear(&mock_object); 110 testing::Mock::VerifyAndClear(&mock_object);
109 EXPECT_TRUE(delete_flag); 111 EXPECT_TRUE(delete_flag);
110 112
111 // Expect no pending task in |post_runner| and |reply_runner|. 113 // Expect no pending task in |post_runner| and |reply_runner|.
112 EXPECT_FALSE(post_runner->HasPendingTask()); 114 EXPECT_FALSE(post_runner->HasPendingTask());
113 EXPECT_FALSE(reply_runner->HasPendingTask()); 115 EXPECT_FALSE(reply_runner->HasPendingTask());
114 } 116 }
115 117
116 } // namespace internal 118 } // namespace internal
117 } // namespace base 119 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698