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

Side by Side Diff: dbus/object_proxy.cc

Issue 2889683006: Misc refactoring of SessionManagerClient. (Closed)
Patch Set: 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;
141 base::Closure task = base::Bind(&ObjectProxy::RunResponseCallback, 140 base::Closure task = base::Bind(&ObjectProxy::RunResponseCallback,
142 this, 141 this,
143 callback, 142 callback,
144 error_callback, 143 error_callback,
145 start_time, 144 start_time,
146 response_message); 145 nullptr /* response_message */);
147 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task); 146 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task);
148 return; 147 return;
149 } 148 }
150 149
151 // Increment the reference count so we can safely reference the 150 // Increment the reference count so we can safely reference the
152 // underlying request message until the method call is complete. This 151 // underlying request message until the method call is complete. This
153 // will be unref'ed in StartAsyncMethodCall(). 152 // will be unref'ed in StartAsyncMethodCall().
154 DBusMessage* request_message = method_call->raw_message(); 153 DBusMessage* request_message = method_call->raw_message();
155 dbus_message_ref(request_message); 154 dbus_message_ref(request_message);
156 155
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ObjectProxy* in_object_proxy, 239 ObjectProxy* in_object_proxy,
241 ResponseCallback in_response_callback, 240 ResponseCallback in_response_callback,
242 ErrorCallback in_error_callback, 241 ErrorCallback in_error_callback,
243 base::TimeTicks in_start_time) 242 base::TimeTicks in_start_time)
244 : object_proxy(in_object_proxy), 243 : object_proxy(in_object_proxy),
245 response_callback(in_response_callback), 244 response_callback(in_response_callback),
246 error_callback(in_error_callback), 245 error_callback(in_error_callback),
247 start_time(in_start_time) { 246 start_time(in_start_time) {
248 } 247 }
249 248
250 ObjectProxy::OnPendingCallIsCompleteData::~OnPendingCallIsCompleteData() { 249 ObjectProxy::OnPendingCallIsCompleteData::~OnPendingCallIsCompleteData()
251 } 250 = default;
252 251
253 void ObjectProxy::StartAsyncMethodCall(int timeout_ms, 252 void ObjectProxy::StartAsyncMethodCall(int timeout_ms,
254 DBusMessage* request_message, 253 DBusMessage* request_message,
255 ResponseCallback response_callback, 254 ResponseCallback response_callback,
256 ErrorCallback error_callback, 255 ErrorCallback error_callback,
257 base::TimeTicks start_time) { 256 base::TimeTicks start_time) {
258 bus_->AssertOnDBusThread(); 257 bus_->AssertOnDBusThread();
259 258
260 if (!bus_->Connect() || !bus_->SetUpAsyncOperations()) { 259 if (!bus_->Connect() || !bus_->SetUpAsyncOperations()) {
261 // In case of a failure, run the error callback with NULL. 260 // In case of a failure, run the error callback with nullptr.
262 DBusMessage* response_message = NULL;
263 base::Closure task = base::Bind(&ObjectProxy::RunResponseCallback, 261 base::Closure task = base::Bind(&ObjectProxy::RunResponseCallback,
264 this, 262 this,
265 response_callback, 263 response_callback,
266 error_callback, 264 error_callback,
267 start_time, 265 start_time,
268 response_message); 266 nullptr /* response_message */);
269 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task); 267 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task);
270 268
271 dbus_message_unref(request_message); 269 dbus_message_unref(request_message);
272 return; 270 return;
273 } 271 }
274 272
275 DBusPendingCall* pending_call = NULL; 273 DBusPendingCall* pending_call = nullptr;
276
277 bus_->SendWithReply(request_message, &pending_call, timeout_ms); 274 bus_->SendWithReply(request_message, &pending_call, timeout_ms);
278 275
279 // Prepare the data we'll be passing to OnPendingCallIsCompleteThunk(). 276 // Prepare the data we'll be passing to OnPendingCallIsCompleteThunk().
280 // The data will be deleted in OnPendingCallIsCompleteThunk(). 277 // The data will be deleted in OnPendingCallIsCompleteThunk().
281 OnPendingCallIsCompleteData* data = 278 OnPendingCallIsCompleteData* data =
282 new OnPendingCallIsCompleteData(this, response_callback, error_callback, 279 new OnPendingCallIsCompleteData(this, response_callback, error_callback,
283 start_time); 280 start_time);
284 281
285 // This returns false only when unable to allocate memory. 282 // This returns false only when unable to allocate memory.
286 const bool success = dbus_pending_call_set_notify( 283 const bool success = dbus_pending_call_set_notify(
(...skipping 30 matching lines...) Expand all
317 314
318 void ObjectProxy::RunResponseCallback(ResponseCallback response_callback, 315 void ObjectProxy::RunResponseCallback(ResponseCallback response_callback,
319 ErrorCallback error_callback, 316 ErrorCallback error_callback,
320 base::TimeTicks start_time, 317 base::TimeTicks start_time,
321 DBusMessage* response_message) { 318 DBusMessage* response_message) {
322 bus_->AssertOnOriginThread(); 319 bus_->AssertOnOriginThread();
323 320
324 bool method_call_successful = false; 321 bool method_call_successful = false;
325 if (!response_message) { 322 if (!response_message) {
326 // The response is not received. 323 // The response is not received.
327 error_callback.Run(NULL); 324 error_callback.Run(nullptr);
328 } else if (dbus_message_get_type(response_message) == 325 } else if (dbus_message_get_type(response_message) ==
329 DBUS_MESSAGE_TYPE_ERROR) { 326 DBUS_MESSAGE_TYPE_ERROR) {
330 // This will take |response_message| and release (unref) it. 327 // This will take |response_message| and release (unref) it.
331 std::unique_ptr<ErrorResponse> error_response( 328 std::unique_ptr<ErrorResponse> error_response(
332 ErrorResponse::FromRawMessage(response_message)); 329 ErrorResponse::FromRawMessage(response_message));
333 error_callback.Run(error_response.get()); 330 error_callback.Run(error_response.get());
334 // Delete the message on the D-Bus thread. See below for why. 331 // Delete the message on the D-Bus thread. See below for why.
335 bus_->GetDBusTaskRunner()->PostTask( 332 bus_->GetDBusTaskRunner()->PostTask(
336 FROM_HERE, 333 FROM_HERE,
337 base::Bind(&base::DeletePointer<ErrorResponse>, 334 base::Bind(&base::DeletePointer<ErrorResponse>,
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if (error_name == kErrorObjectUnknown) 576 if (error_name == kErrorObjectUnknown)
580 LOG(WARNING) << msg.str(); 577 LOG(WARNING) << msg.str();
581 else 578 else
582 LOG(ERROR) << msg.str(); 579 LOG(ERROR) << msg.str();
583 } 580 }
584 581
585 void ObjectProxy::OnCallMethodError(const std::string& interface_name, 582 void ObjectProxy::OnCallMethodError(const std::string& interface_name,
586 const std::string& method_name, 583 const std::string& method_name,
587 ResponseCallback response_callback, 584 ResponseCallback response_callback,
588 ErrorResponse* error_response) { 585 ErrorResponse* error_response) {
586 std::string error_name;
587 std::string error_message;
589 if (error_response) { 588 if (error_response) {
590 // Error message may contain the error message as string. 589 // Error message may contain the error message as string.
590 error_name = error_response->GetErrorName();
591 MessageReader reader(error_response); 591 MessageReader reader(error_response);
592 std::string error_message;
593 reader.PopString(&error_message); 592 reader.PopString(&error_message);
594 LogMethodCallFailure(interface_name, 593 } else {
595 method_name, 594 error_name = "(noname)";
hashimoto 2017/05/19 11:02:46 How about making this more readable? (e.g. "No err
hidehiko 2017/05/19 12:32:04 Used "unknown error type" to be consistent with L1
596 error_response->GetErrorName(), 595 error_message = "(nomessage)";
hashimoto 2017/05/19 11:02:46 error_massage is empty when error_response is non-
hidehiko 2017/05/19 12:32:03 Done.
597 error_message);
598 } 596 }
599 response_callback.Run(NULL); 597 LogMethodCallFailure(
598 interface_name, method_name, error_name, error_message);
599
600 response_callback.Run(nullptr);
600 } 601 }
601 602
602 bool ObjectProxy::AddMatchRuleWithCallback( 603 bool ObjectProxy::AddMatchRuleWithCallback(
603 const std::string& match_rule, 604 const std::string& match_rule,
604 const std::string& absolute_signal_name, 605 const std::string& absolute_signal_name,
605 SignalCallback signal_callback) { 606 SignalCallback signal_callback) {
606 DCHECK(!match_rule.empty()); 607 DCHECK(!match_rule.empty());
607 DCHECK(!absolute_signal_name.empty()); 608 DCHECK(!absolute_signal_name.empty());
608 bus_->AssertOnDBusThread(); 609 bus_->AssertOnDBusThread();
609 610
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 bool service_is_available) { 708 bool service_is_available) {
708 bus_->AssertOnOriginThread(); 709 bus_->AssertOnOriginThread();
709 710
710 std::vector<WaitForServiceToBeAvailableCallback> callbacks; 711 std::vector<WaitForServiceToBeAvailableCallback> callbacks;
711 callbacks.swap(wait_for_service_to_be_available_callbacks_); 712 callbacks.swap(wait_for_service_to_be_available_callbacks_);
712 for (size_t i = 0; i < callbacks.size(); ++i) 713 for (size_t i = 0; i < callbacks.size(); ++i)
713 callbacks[i].Run(service_is_available); 714 callbacks[i].Run(service_is_available);
714 } 715 }
715 716
716 } // namespace dbus 717 } // 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