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

Side by Side Diff: components/webdata/common/web_data_request_manager.cc

Issue 2087583002: Remove calls to MessageLoop::current() in components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test error Created 4 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
« no previous file with comments | « components/webdata/common/web_data_request_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "components/webdata/common/web_data_request_manager.h" 5 #include "components/webdata/common/web_data_request_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/profiler/scoped_tracker.h" 11 #include "base/profiler/scoped_tracker.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/threading/thread_task_runner_handle.h"
15 14
16 //////////////////////////////////////////////////////////////////////////////// 15 ////////////////////////////////////////////////////////////////////////////////
17 // 16 //
18 // WebDataRequest implementation. 17 // WebDataRequest implementation.
19 // 18 //
20 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
21 20
22 WebDataRequest::WebDataRequest(WebDataServiceConsumer* consumer, 21 WebDataRequest::WebDataRequest(WebDataServiceConsumer* consumer,
23 WebDataRequestManager* manager) 22 WebDataRequestManager* manager)
24 : manager_(manager), cancelled_(false), consumer_(consumer) { 23 : manager_(manager), cancelled_(false), consumer_(consumer) {
25 handle_ = manager_->GetNextRequestHandle(); 24 handle_ = manager_->GetNextRequestHandle();
26 message_loop_ = base::MessageLoop::current(); 25 task_runner_ = base::ThreadTaskRunnerHandle::Get();
27 manager_->RegisterRequest(this); 26 manager_->RegisterRequest(this);
28 } 27 }
29 28
30 WebDataRequest::~WebDataRequest() { 29 WebDataRequest::~WebDataRequest() {
31 if (manager_) { 30 if (manager_) {
32 manager_->CancelRequest(handle_); 31 manager_->CancelRequest(handle_);
33 } 32 }
34 if (result_.get()) { 33 if (result_.get()) {
35 result_->Destroy(); 34 result_->Destroy();
36 } 35 }
37 } 36 }
38 37
39 WebDataServiceBase::Handle WebDataRequest::GetHandle() const { 38 WebDataServiceBase::Handle WebDataRequest::GetHandle() const {
40 return handle_; 39 return handle_;
41 } 40 }
42 41
43 WebDataServiceConsumer* WebDataRequest::GetConsumer() const { 42 WebDataServiceConsumer* WebDataRequest::GetConsumer() const {
44 return consumer_; 43 return consumer_;
45 } 44 }
46 45
47 base::MessageLoop* WebDataRequest::GetMessageLoop() const { 46 scoped_refptr<base::SingleThreadTaskRunner> WebDataRequest::GetTaskRunner()
48 return message_loop_; 47 const {
48 return task_runner_;
49 } 49 }
50 50
51 bool WebDataRequest::IsCancelled() const { 51 bool WebDataRequest::IsCancelled() const {
52 base::AutoLock l(cancel_lock_); 52 base::AutoLock l(cancel_lock_);
53 return cancelled_; 53 return cancelled_;
54 } 54 }
55 55
56 void WebDataRequest::Cancel() { 56 void WebDataRequest::Cancel() {
57 base::AutoLock l(cancel_lock_); 57 base::AutoLock l(cancel_lock_);
58 cancelled_ = true; 58 cancelled_ = true;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (i == pending_requests_.end()) { 107 if (i == pending_requests_.end()) {
108 NOTREACHED() << "Canceling a nonexistent web data service request"; 108 NOTREACHED() << "Canceling a nonexistent web data service request";
109 return; 109 return;
110 } 110 }
111 i->second->Cancel(); 111 i->second->Cancel();
112 pending_requests_.erase(i); 112 pending_requests_.erase(i);
113 } 113 }
114 114
115 void WebDataRequestManager::RequestCompleted( 115 void WebDataRequestManager::RequestCompleted(
116 std::unique_ptr<WebDataRequest> request) { 116 std::unique_ptr<WebDataRequest> request) {
117 base::MessageLoop* loop = request->GetMessageLoop(); 117 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
118 loop->task_runner()->PostTask( 118 request->GetTaskRunner();
119 task_runner->PostTask(
119 FROM_HERE, base::Bind(&WebDataRequestManager::RequestCompletedOnThread, 120 FROM_HERE, base::Bind(&WebDataRequestManager::RequestCompletedOnThread,
120 this, base::Passed(&request))); 121 this, base::Passed(&request)));
121 } 122 }
122 123
123 void WebDataRequestManager::RequestCompletedOnThread( 124 void WebDataRequestManager::RequestCompletedOnThread(
124 std::unique_ptr<WebDataRequest> request) { 125 std::unique_ptr<WebDataRequest> request) {
125 if (request->IsCancelled()) 126 if (request->IsCancelled())
126 return; 127 return;
127 128
128 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 129 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
(...skipping 24 matching lines...) Expand all
153 if (!request->IsCancelled()) { 154 if (!request->IsCancelled()) {
154 WebDataServiceConsumer* consumer = request->GetConsumer(); 155 WebDataServiceConsumer* consumer = request->GetConsumer();
155 request->OnComplete(); 156 request->OnComplete();
156 if (consumer) { 157 if (consumer) {
157 std::unique_ptr<WDTypedResult> r = request->GetResult(); 158 std::unique_ptr<WDTypedResult> r = request->GetResult();
158 consumer->OnWebDataServiceRequestDone(request->GetHandle(), r.get()); 159 consumer->OnWebDataServiceRequestDone(request->GetHandle(), r.get());
159 } 160 }
160 } 161 }
161 162
162 } 163 }
OLDNEW
« no previous file with comments | « components/webdata/common/web_data_request_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698