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

Side by Side Diff: dbus/object_proxy.cc

Issue 2889683006: Misc refactoring of SessionManagerClient. (Closed)
Patch Set: git cl format. Created 3 years, 7 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 | « chromeos/dbus/session_manager_client.cc ('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 (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/object_proxy.h" 5 #include "dbus/object_proxy.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 void ObjectProxy::CallMethodWithErrorCallback(MethodCall* method_call, 129 void ObjectProxy::CallMethodWithErrorCallback(MethodCall* method_call,
130 int timeout_ms, 130 int timeout_ms,
131 ResponseCallback callback, 131 ResponseCallback callback,
132 ErrorCallback error_callback) { 132 ErrorCallback error_callback) {
133 bus_->AssertOnOriginThread(); 133 bus_->AssertOnOriginThread();
134 134
135 const base::TimeTicks start_time = base::TimeTicks::Now(); 135 const base::TimeTicks start_time = base::TimeTicks::Now();
136 136
137 if (!method_call->SetDestination(service_name_) || 137 if (!method_call->SetDestination(service_name_) ||
138 !method_call->SetPath(object_path_)) { 138 !method_call->SetPath(object_path_)) {
139 // In case of a failure, run the error callback with NULL. 139 // In case of a failure, run the error callback with nullptr.
140 DBusMessage* response_message = NULL; 140 base::Closure task =
141 base::Closure task = base::Bind(&ObjectProxy::RunResponseCallback, 141 base::Bind(&ObjectProxy::RunResponseCallback, this, callback,
142 this, 142 error_callback, start_time, nullptr /* response_message */);
143 callback,
144 error_callback,
145 start_time,
146 response_message);
147 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task); 143 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task);
148 return; 144 return;
149 } 145 }
150 146
151 // Increment the reference count so we can safely reference the 147 // Increment the reference count so we can safely reference the
152 // underlying request message until the method call is complete. This 148 // underlying request message until the method call is complete. This
153 // will be unref'ed in StartAsyncMethodCall(). 149 // will be unref'ed in StartAsyncMethodCall().
154 DBusMessage* request_message = method_call->raw_message(); 150 DBusMessage* request_message = method_call->raw_message();
155 dbus_message_ref(request_message); 151 dbus_message_ref(request_message);
156 152
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ObjectProxy* in_object_proxy, 236 ObjectProxy* in_object_proxy,
241 ResponseCallback in_response_callback, 237 ResponseCallback in_response_callback,
242 ErrorCallback in_error_callback, 238 ErrorCallback in_error_callback,
243 base::TimeTicks in_start_time) 239 base::TimeTicks in_start_time)
244 : object_proxy(in_object_proxy), 240 : object_proxy(in_object_proxy),
245 response_callback(in_response_callback), 241 response_callback(in_response_callback),
246 error_callback(in_error_callback), 242 error_callback(in_error_callback),
247 start_time(in_start_time) { 243 start_time(in_start_time) {
248 } 244 }
249 245
250 ObjectProxy::OnPendingCallIsCompleteData::~OnPendingCallIsCompleteData() { 246 ObjectProxy::OnPendingCallIsCompleteData::~OnPendingCallIsCompleteData() =
251 } 247 default;
252 248
253 void ObjectProxy::StartAsyncMethodCall(int timeout_ms, 249 void ObjectProxy::StartAsyncMethodCall(int timeout_ms,
254 DBusMessage* request_message, 250 DBusMessage* request_message,
255 ResponseCallback response_callback, 251 ResponseCallback response_callback,
256 ErrorCallback error_callback, 252 ErrorCallback error_callback,
257 base::TimeTicks start_time) { 253 base::TimeTicks start_time) {
258 bus_->AssertOnDBusThread(); 254 bus_->AssertOnDBusThread();
259 255
260 if (!bus_->Connect() || !bus_->SetUpAsyncOperations()) { 256 if (!bus_->Connect() || !bus_->SetUpAsyncOperations()) {
261 // In case of a failure, run the error callback with NULL. 257 // In case of a failure, run the error callback with nullptr.
262 DBusMessage* response_message = NULL; 258 base::Closure task =
263 base::Closure task = base::Bind(&ObjectProxy::RunResponseCallback, 259 base::Bind(&ObjectProxy::RunResponseCallback, this, response_callback,
264 this, 260 error_callback, start_time, nullptr /* response_message */);
265 response_callback,
266 error_callback,
267 start_time,
268 response_message);
269 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task); 261 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task);
270 262
271 dbus_message_unref(request_message); 263 dbus_message_unref(request_message);
272 return; 264 return;
273 } 265 }
274 266
275 DBusPendingCall* pending_call = NULL; 267 DBusPendingCall* pending_call = nullptr;
276
277 bus_->SendWithReply(request_message, &pending_call, timeout_ms); 268 bus_->SendWithReply(request_message, &pending_call, timeout_ms);
278 269
279 // Prepare the data we'll be passing to OnPendingCallIsCompleteThunk(). 270 // Prepare the data we'll be passing to OnPendingCallIsCompleteThunk().
280 // The data will be deleted in OnPendingCallIsCompleteThunk(). 271 // The data will be deleted in OnPendingCallIsCompleteThunk().
281 OnPendingCallIsCompleteData* data = 272 OnPendingCallIsCompleteData* data =
282 new OnPendingCallIsCompleteData(this, response_callback, error_callback, 273 new OnPendingCallIsCompleteData(this, response_callback, error_callback,
283 start_time); 274 start_time);
284 275
285 // This returns false only when unable to allocate memory. 276 // This returns false only when unable to allocate memory.
286 const bool success = dbus_pending_call_set_notify( 277 const bool success = dbus_pending_call_set_notify(
(...skipping 30 matching lines...) Expand all
317 308
318 void ObjectProxy::RunResponseCallback(ResponseCallback response_callback, 309 void ObjectProxy::RunResponseCallback(ResponseCallback response_callback,
319 ErrorCallback error_callback, 310 ErrorCallback error_callback,
320 base::TimeTicks start_time, 311 base::TimeTicks start_time,
321 DBusMessage* response_message) { 312 DBusMessage* response_message) {
322 bus_->AssertOnOriginThread(); 313 bus_->AssertOnOriginThread();
323 314
324 bool method_call_successful = false; 315 bool method_call_successful = false;
325 if (!response_message) { 316 if (!response_message) {
326 // The response is not received. 317 // The response is not received.
327 error_callback.Run(NULL); 318 error_callback.Run(nullptr);
328 } else if (dbus_message_get_type(response_message) == 319 } else if (dbus_message_get_type(response_message) ==
329 DBUS_MESSAGE_TYPE_ERROR) { 320 DBUS_MESSAGE_TYPE_ERROR) {
330 // This will take |response_message| and release (unref) it. 321 // This will take |response_message| and release (unref) it.
331 std::unique_ptr<ErrorResponse> error_response( 322 std::unique_ptr<ErrorResponse> error_response(
332 ErrorResponse::FromRawMessage(response_message)); 323 ErrorResponse::FromRawMessage(response_message));
333 error_callback.Run(error_response.get()); 324 error_callback.Run(error_response.get());
334 // Delete the message on the D-Bus thread. See below for why. 325 // Delete the message on the D-Bus thread. See below for why.
335 bus_->GetDBusTaskRunner()->PostTask( 326 bus_->GetDBusTaskRunner()->PostTask(
336 FROM_HERE, 327 FROM_HERE,
337 base::Bind(&base::DeletePointer<ErrorResponse>, 328 base::Bind(&base::DeletePointer<ErrorResponse>,
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if (error_name == kErrorObjectUnknown) 570 if (error_name == kErrorObjectUnknown)
580 LOG(WARNING) << msg.str(); 571 LOG(WARNING) << msg.str();
581 else 572 else
582 LOG(ERROR) << msg.str(); 573 LOG(ERROR) << msg.str();
583 } 574 }
584 575
585 void ObjectProxy::OnCallMethodError(const std::string& interface_name, 576 void ObjectProxy::OnCallMethodError(const std::string& interface_name,
586 const std::string& method_name, 577 const std::string& method_name,
587 ResponseCallback response_callback, 578 ResponseCallback response_callback,
588 ErrorResponse* error_response) { 579 ErrorResponse* error_response) {
580 std::string error_name;
581 std::string error_message;
589 if (error_response) { 582 if (error_response) {
590 // Error message may contain the error message as string. 583 // Error message may contain the error message as string.
584 error_name = error_response->GetErrorName();
591 MessageReader reader(error_response); 585 MessageReader reader(error_response);
592 std::string error_message;
593 reader.PopString(&error_message); 586 reader.PopString(&error_message);
594 LogMethodCallFailure(interface_name, 587 } else {
595 method_name, 588 error_name = "unknown error type";
596 error_response->GetErrorName(),
597 error_message);
598 } 589 }
599 response_callback.Run(NULL); 590 LogMethodCallFailure(interface_name, method_name, error_name, error_message);
591
592 response_callback.Run(nullptr);
600 } 593 }
601 594
602 bool ObjectProxy::AddMatchRuleWithCallback( 595 bool ObjectProxy::AddMatchRuleWithCallback(
603 const std::string& match_rule, 596 const std::string& match_rule,
604 const std::string& absolute_signal_name, 597 const std::string& absolute_signal_name,
605 SignalCallback signal_callback) { 598 SignalCallback signal_callback) {
606 DCHECK(!match_rule.empty()); 599 DCHECK(!match_rule.empty());
607 DCHECK(!absolute_signal_name.empty()); 600 DCHECK(!absolute_signal_name.empty());
608 bus_->AssertOnDBusThread(); 601 bus_->AssertOnDBusThread();
609 602
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 bool service_is_available) { 700 bool service_is_available) {
708 bus_->AssertOnOriginThread(); 701 bus_->AssertOnOriginThread();
709 702
710 std::vector<WaitForServiceToBeAvailableCallback> callbacks; 703 std::vector<WaitForServiceToBeAvailableCallback> callbacks;
711 callbacks.swap(wait_for_service_to_be_available_callbacks_); 704 callbacks.swap(wait_for_service_to_be_available_callbacks_);
712 for (size_t i = 0; i < callbacks.size(); ++i) 705 for (size_t i = 0; i < callbacks.size(); ++i)
713 callbacks[i].Run(service_is_available); 706 callbacks[i].Run(service_is_available);
714 } 707 }
715 708
716 } // namespace dbus 709 } // namespace dbus
OLDNEW
« no previous file with comments | « chromeos/dbus/session_manager_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698