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

Side by Side Diff: net/base/test_completion_callback_unittest.cc

Issue 368001: Second patch in making destructors of refcounted objects private. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // Illustrates how to use worker threads that issue completion callbacks 5 // Illustrates how to use worker threads that issue completion callbacks
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "net/base/completion_callback.h" 8 #include "net/base/completion_callback.h"
9 #include "net/base/test_completion_callback.h" 9 #include "net/base/test_completion_callback.h"
10 #include "base/worker_pool.h" 10 #include "base/worker_pool.h"
(...skipping 29 matching lines...) Expand all
40 class ExampleEmployer::ExampleWorker 40 class ExampleEmployer::ExampleWorker
41 : public base::RefCountedThreadSafe<ExampleWorker> { 41 : public base::RefCountedThreadSafe<ExampleWorker> {
42 public: 42 public:
43 ExampleWorker(ExampleEmployer* employer, CompletionCallback* callback) 43 ExampleWorker(ExampleEmployer* employer, CompletionCallback* callback)
44 : employer_(employer), callback_(callback), 44 : employer_(employer), callback_(callback),
45 origin_loop_(MessageLoop::current()) { 45 origin_loop_(MessageLoop::current()) {
46 } 46 }
47 void DoWork(); 47 void DoWork();
48 void DoCallback(); 48 void DoCallback();
49 private: 49 private:
50 friend class base::RefCountedThreadSafe<ExampleWorker>;
51
52 ~ExampleWorker() {}
53
50 // Only used on the origin thread (where DoSomething was called). 54 // Only used on the origin thread (where DoSomething was called).
51 ExampleEmployer* employer_; 55 ExampleEmployer* employer_;
52 CompletionCallback* callback_; 56 CompletionCallback* callback_;
53 // Used to post ourselves onto the origin thread. 57 // Used to post ourselves onto the origin thread.
54 Lock origin_loop_lock_; 58 Lock origin_loop_lock_;
55 MessageLoop* origin_loop_; 59 MessageLoop* origin_loop_;
56 }; 60 };
57 61
58 void ExampleEmployer::ExampleWorker::DoWork() { 62 void ExampleEmployer::ExampleWorker::DoWork() {
59 // Running on the worker thread 63 // Running on the worker thread
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 TEST_F(TestCompletionCallbackTest, Simple) { 115 TEST_F(TestCompletionCallbackTest, Simple) {
112 ExampleEmployer boss; 116 ExampleEmployer boss;
113 TestCompletionCallback callback; 117 TestCompletionCallback callback;
114 bool queued = boss.DoSomething(&callback); 118 bool queued = boss.DoSomething(&callback);
115 EXPECT_EQ(queued, true); 119 EXPECT_EQ(queued, true);
116 int result = callback.WaitForResult(); 120 int result = callback.WaitForResult();
117 EXPECT_EQ(result, kMagicResult); 121 EXPECT_EQ(result, kMagicResult);
118 } 122 }
119 123
120 // TODO: test deleting ExampleEmployer while work outstanding 124 // TODO: test deleting ExampleEmployer while work outstanding
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698