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

Side by Side Diff: chrome/browser/common/cancelable_request.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/common/cancelable_request.h" 5 #include "chrome/browser/common/cancelable_request.h"
6 6
7 CancelableRequestProvider::CancelableRequestProvider() 7 CancelableRequestProvider::CancelableRequestProvider()
8 : next_handle_(1) { 8 : next_handle_(1) {
9 } 9 }
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 template class CancelableRequestConsumerTSimple<int>; 86 template class CancelableRequestConsumerTSimple<int>;
87 87
88 // And the most common subclass of it. 88 // And the most common subclass of it.
89 template class CancelableRequestConsumerT<int, 0>; 89 template class CancelableRequestConsumerT<int, 0>;
90 #endif 90 #endif
91 91
92 CancelableRequestBase::CancelableRequestBase() 92 CancelableRequestBase::CancelableRequestBase()
93 : provider_(NULL), 93 : provider_(NULL),
94 consumer_(NULL), 94 consumer_(NULL),
95 handle_(0) { 95 handle_(0) {
96 callback_thread_ = MessageLoop::current(); 96 callback_thread_ = base::MessageLoop::current();
97 } 97 }
98 98
99 CancelableRequestBase::~CancelableRequestBase() { 99 CancelableRequestBase::~CancelableRequestBase() {
100 } 100 }
101 101
102 void CancelableRequestBase::Init(CancelableRequestProvider* provider, 102 void CancelableRequestBase::Init(CancelableRequestProvider* provider,
103 CancelableRequestProvider::Handle handle, 103 CancelableRequestProvider::Handle handle,
104 CancelableRequestConsumerBase* consumer) { 104 CancelableRequestConsumerBase* consumer) {
105 DCHECK(handle_ == 0 && provider_ == NULL && consumer_ == NULL); 105 DCHECK(handle_ == 0 && provider_ == NULL && consumer_ == NULL);
106 provider_ = provider; 106 provider_ = provider;
107 consumer_ = consumer; 107 consumer_ = consumer;
108 handle_ = handle; 108 handle_ = handle;
109 } 109 }
110 110
111 void CancelableRequestBase::DoForward(const base::Closure& forwarded_call, 111 void CancelableRequestBase::DoForward(const base::Closure& forwarded_call,
112 bool force_async) { 112 bool force_async) {
113 if (force_async || callback_thread_ != MessageLoop::current()) { 113 if (force_async || callback_thread_ != base::MessageLoop::current()) {
114 callback_thread_->PostTask( 114 callback_thread_->PostTask(
115 FROM_HERE, 115 FROM_HERE,
116 base::Bind(&CancelableRequestBase::ExecuteCallback, this, 116 base::Bind(&CancelableRequestBase::ExecuteCallback, this,
117 forwarded_call)); 117 forwarded_call));
118 } else { 118 } else {
119 // We can do synchronous callbacks when we're on the same thread. 119 // We can do synchronous callbacks when we're on the same thread.
120 ExecuteCallback(forwarded_call); 120 ExecuteCallback(forwarded_call);
121 } 121 }
122 } 122 }
123 123
124 void CancelableRequestBase::ExecuteCallback( 124 void CancelableRequestBase::ExecuteCallback(
125 const base::Closure& forwarded_call) { 125 const base::Closure& forwarded_call) {
126 DCHECK_EQ(callback_thread_, MessageLoop::current()); 126 DCHECK_EQ(callback_thread_, base::MessageLoop::current());
127 127
128 if (!canceled_.IsSet()) { 128 if (!canceled_.IsSet()) {
129 WillExecute(); 129 WillExecute();
130 130
131 // Execute the callback. 131 // Execute the callback.
132 forwarded_call.Run(); 132 forwarded_call.Run();
133 } 133 }
134 134
135 // Notify the provider that the request is complete. The provider will 135 // Notify the provider that the request is complete. The provider will
136 // notify the consumer for us. Note that it is possible for the callback to 136 // notify the consumer for us. Note that it is possible for the callback to
137 // cancel this request; we must check canceled again. 137 // cancel this request; we must check canceled again.
138 if (!canceled_.IsSet()) 138 if (!canceled_.IsSet())
139 NotifyCompleted(); 139 NotifyCompleted();
140 } 140 }
OLDNEW
« no previous file with comments | « chrome/browser/common/cancelable_request.h ('k') | chrome/browser/component_updater/test/component_installers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698