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

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

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/base/file_stream_unittest.cc ('k') | net/base/upload_bytes_element_reader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/threading/worker_pool.h" 10 #include "base/threading/worker_pool.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 callback_.Run(kMagicResult); 87 callback_.Run(kMagicResult);
88 } 88 }
89 89
90 ExampleEmployer::ExampleEmployer() { 90 ExampleEmployer::ExampleEmployer() {
91 } 91 }
92 92
93 ExampleEmployer::~ExampleEmployer() { 93 ExampleEmployer::~ExampleEmployer() {
94 } 94 }
95 95
96 bool ExampleEmployer::DoSomething(const net::CompletionCallback& callback) { 96 bool ExampleEmployer::DoSomething(const net::CompletionCallback& callback) {
97 DCHECK(!request_) << "already in use"; 97 DCHECK(!request_.get()) << "already in use";
98 98
99 request_ = new ExampleWorker(this, callback); 99 request_ = new ExampleWorker(this, callback);
100 100
101 // Dispatch to worker thread... 101 // Dispatch to worker thread...
102 if (!base::WorkerPool::PostTask( 102 if (!base::WorkerPool::PostTask(
103 FROM_HERE, 103 FROM_HERE,
104 base::Bind(&ExampleWorker::DoWork, request_.get()), 104 base::Bind(&ExampleWorker::DoWork, request_.get()),
105 true)) { 105 true)) {
106 NOTREACHED(); 106 NOTREACHED();
107 request_ = NULL; 107 request_ = NULL;
108 return false; 108 return false;
109 } 109 }
110 110
111 return true; 111 return true;
112 } 112 }
113 113
114 TEST_F(TestCompletionCallbackTest, Simple) { 114 TEST_F(TestCompletionCallbackTest, Simple) {
115 ExampleEmployer boss; 115 ExampleEmployer boss;
116 net::TestCompletionCallback callback; 116 net::TestCompletionCallback callback;
117 bool queued = boss.DoSomething(callback.callback()); 117 bool queued = boss.DoSomething(callback.callback());
118 EXPECT_EQ(queued, true); 118 EXPECT_EQ(queued, true);
119 int result = callback.WaitForResult(); 119 int result = callback.WaitForResult();
120 EXPECT_EQ(result, kMagicResult); 120 EXPECT_EQ(result, kMagicResult);
121 } 121 }
122 122
123 // TODO: test deleting ExampleEmployer while work outstanding 123 // TODO: test deleting ExampleEmployer while work outstanding
OLDNEW
« no previous file with comments | « net/base/file_stream_unittest.cc ('k') | net/base/upload_bytes_element_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698