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

Side by Side Diff: dbus/exported_object.cc

Issue 24554002: dbus: Replace PostTaskTo*Thread methods with Get*TaskRunner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | « dbus/end_to_end_async_unittest.cc ('k') | dbus/mock_bus.h » ('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) 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 "dbus/exported_object.h" 5 #include "dbus/exported_object.h"
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/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 MethodCallCallback method_call_callback, 77 MethodCallCallback method_call_callback,
78 OnExportedCallback on_exported_calback) { 78 OnExportedCallback on_exported_calback) {
79 bus_->AssertOnOriginThread(); 79 bus_->AssertOnOriginThread();
80 80
81 base::Closure task = base::Bind(&ExportedObject::ExportMethodInternal, 81 base::Closure task = base::Bind(&ExportedObject::ExportMethodInternal,
82 this, 82 this,
83 interface_name, 83 interface_name,
84 method_name, 84 method_name,
85 method_call_callback, 85 method_call_callback,
86 on_exported_calback); 86 on_exported_calback);
87 bus_->PostTaskToDBusThread(FROM_HERE, task); 87 bus_->GetDBusTaskRunner()->PostTask(FROM_HERE, task);
88 } 88 }
89 89
90 void ExportedObject::SendSignal(Signal* signal) { 90 void ExportedObject::SendSignal(Signal* signal) {
91 // For signals, the object path should be set to the path to the sender 91 // For signals, the object path should be set to the path to the sender
92 // object, which is this exported object here. 92 // object, which is this exported object here.
93 CHECK(signal->SetPath(object_path_)); 93 CHECK(signal->SetPath(object_path_));
94 94
95 // Increment the reference count so we can safely reference the 95 // Increment the reference count so we can safely reference the
96 // underlying signal message until the signal sending is complete. This 96 // underlying signal message until the signal sending is complete. This
97 // will be unref'ed in SendSignalInternal(). 97 // will be unref'ed in SendSignalInternal().
98 DBusMessage* signal_message = signal->raw_message(); 98 DBusMessage* signal_message = signal->raw_message();
99 dbus_message_ref(signal_message); 99 dbus_message_ref(signal_message);
100 100
101 const base::TimeTicks start_time = base::TimeTicks::Now(); 101 const base::TimeTicks start_time = base::TimeTicks::Now();
102 bus_->PostTaskToDBusThread(FROM_HERE, 102 bus_->GetDBusTaskRunner()->PostTask(
103 base::Bind(&ExportedObject::SendSignalInternal, 103 FROM_HERE,
104 this, 104 base::Bind(&ExportedObject::SendSignalInternal,
105 start_time, 105 this,
106 signal_message)); 106 start_time,
107 signal_message));
107 } 108 }
108 109
109 void ExportedObject::Unregister() { 110 void ExportedObject::Unregister() {
110 bus_->AssertOnDBusThread(); 111 bus_->AssertOnDBusThread();
111 112
112 if (!object_is_registered_) 113 if (!object_is_registered_)
113 return; 114 return;
114 115
115 bus_->UnregisterObjectPath(object_path_); 116 bus_->UnregisterObjectPath(object_path_);
116 object_is_registered_ = false; 117 object_is_registered_ = false;
117 } 118 }
118 119
119 void ExportedObject::ExportMethodInternal( 120 void ExportedObject::ExportMethodInternal(
120 const std::string& interface_name, 121 const std::string& interface_name,
121 const std::string& method_name, 122 const std::string& method_name,
122 MethodCallCallback method_call_callback, 123 MethodCallCallback method_call_callback,
123 OnExportedCallback on_exported_calback) { 124 OnExportedCallback on_exported_calback) {
124 bus_->AssertOnDBusThread(); 125 bus_->AssertOnDBusThread();
125 126
126 const bool success = ExportMethodAndBlock(interface_name, 127 const bool success = ExportMethodAndBlock(interface_name,
127 method_name, 128 method_name,
128 method_call_callback); 129 method_call_callback);
129 bus_->PostTaskToOriginThread(FROM_HERE, 130 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE,
130 base::Bind(&ExportedObject::OnExported, 131 base::Bind(&ExportedObject::OnExported,
131 this, 132 this,
132 on_exported_calback, 133 on_exported_calback,
133 interface_name, 134 interface_name,
134 method_name, 135 method_name,
135 success)); 136 success));
136 } 137 }
137 138
138 void ExportedObject::OnExported(OnExportedCallback on_exported_callback, 139 void ExportedObject::OnExported(OnExportedCallback on_exported_callback,
139 const std::string& interface_name, 140 const std::string& interface_name,
140 const std::string& method_name, 141 const std::string& method_name,
141 bool success) { 142 bool success) {
142 bus_->AssertOnOriginThread(); 143 bus_->AssertOnOriginThread();
143 144
144 on_exported_callback.Run(interface_name, method_name, success); 145 on_exported_callback.Run(interface_name, method_name, success);
145 } 146 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 MethodTable::const_iterator iter = method_table_.find(absolute_method_name); 208 MethodTable::const_iterator iter = method_table_.find(absolute_method_name);
208 if (iter == method_table_.end()) { 209 if (iter == method_table_.end()) {
209 // Don't know about the method. 210 // Don't know about the method.
210 LOG(WARNING) << "Unknown method: " << method_call->ToString(); 211 LOG(WARNING) << "Unknown method: " << method_call->ToString();
211 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 212 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
212 } 213 }
213 214
214 const base::TimeTicks start_time = base::TimeTicks::Now(); 215 const base::TimeTicks start_time = base::TimeTicks::Now();
215 if (bus_->HasDBusThread()) { 216 if (bus_->HasDBusThread()) {
216 // Post a task to run the method in the origin thread. 217 // Post a task to run the method in the origin thread.
217 bus_->PostTaskToOriginThread(FROM_HERE, 218 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE,
218 base::Bind(&ExportedObject::RunMethod, 219 base::Bind(&ExportedObject::RunMethod,
219 this, 220 this,
220 iter->second, 221 iter->second,
221 base::Passed(&method_call), 222 base::Passed(&method_call),
222 start_time)); 223 start_time));
223 } else { 224 } else {
224 // If the D-Bus thread is not used, just call the method directly. 225 // If the D-Bus thread is not used, just call the method directly.
225 MethodCall* method = method_call.get(); 226 MethodCall* method = method_call.get();
226 iter->second.Run(method, 227 iter->second.Run(method,
227 base::Bind(&ExportedObject::SendResponse, 228 base::Bind(&ExportedObject::SendResponse,
228 this, 229 this,
229 start_time, 230 start_time,
230 base::Passed(&method_call))); 231 base::Passed(&method_call)));
231 } 232 }
232 233
(...skipping 12 matching lines...) Expand all
245 this, 246 this,
246 start_time, 247 start_time,
247 base::Passed(&method_call))); 248 base::Passed(&method_call)));
248 } 249 }
249 250
250 void ExportedObject::SendResponse(base::TimeTicks start_time, 251 void ExportedObject::SendResponse(base::TimeTicks start_time,
251 scoped_ptr<MethodCall> method_call, 252 scoped_ptr<MethodCall> method_call,
252 scoped_ptr<Response> response) { 253 scoped_ptr<Response> response) {
253 DCHECK(method_call); 254 DCHECK(method_call);
254 if (bus_->HasDBusThread()) { 255 if (bus_->HasDBusThread()) {
255 bus_->PostTaskToDBusThread(FROM_HERE, 256 bus_->GetDBusTaskRunner()->PostTask(
256 base::Bind(&ExportedObject::OnMethodCompleted, 257 FROM_HERE,
257 this, 258 base::Bind(&ExportedObject::OnMethodCompleted,
258 base::Passed(&method_call), 259 this,
259 base::Passed(&response), 260 base::Passed(&method_call),
260 start_time)); 261 base::Passed(&response),
262 start_time));
261 } else { 263 } else {
262 OnMethodCompleted(method_call.Pass(), response.Pass(), start_time); 264 OnMethodCompleted(method_call.Pass(), response.Pass(), start_time);
263 } 265 }
264 } 266 }
265 267
266 void ExportedObject::OnMethodCompleted(scoped_ptr<MethodCall> method_call, 268 void ExportedObject::OnMethodCompleted(scoped_ptr<MethodCall> method_call,
267 scoped_ptr<Response> response, 269 scoped_ptr<Response> response,
268 base::TimeTicks start_time) { 270 base::TimeTicks start_time) {
269 bus_->AssertOnDBusThread(); 271 bus_->AssertOnDBusThread();
270 272
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return self->HandleMessage(connection, raw_message); 310 return self->HandleMessage(connection, raw_message);
309 } 311 }
310 312
311 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, 313 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection,
312 void* user_data) { 314 void* user_data) {
313 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); 315 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data);
314 return self->OnUnregistered(connection); 316 return self->OnUnregistered(connection);
315 } 317 }
316 318
317 } // namespace dbus 319 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/end_to_end_async_unittest.cc ('k') | dbus/mock_bus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698