OLD | NEW |
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/bus.h" | 5 #include "dbus/bus.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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 ObjectProxy::~ObjectProxy() { | 56 ObjectProxy::~ObjectProxy() { |
57 } | 57 } |
58 | 58 |
59 // Originally we tried to make |method_call| a const reference, but we | 59 // Originally we tried to make |method_call| a const reference, but we |
60 // gave up as dbus_connection_send_with_reply_and_block() takes a | 60 // gave up as dbus_connection_send_with_reply_and_block() takes a |
61 // non-const pointer of DBusMessage as the second parameter. | 61 // non-const pointer of DBusMessage as the second parameter. |
62 Response* ObjectProxy::CallMethodAndBlock(MethodCall* method_call, | 62 Response* ObjectProxy::CallMethodAndBlock(MethodCall* method_call, |
63 int timeout_ms) { | 63 int timeout_ms) { |
64 bus_->AssertOnDBusThread(); | 64 bus_->AssertOnDBusThread(); |
65 | 65 |
66 if (!bus_->Connect()) | 66 if (!bus_->Connect() || |
| 67 !method_call->SetDestination(service_name_) || |
| 68 !method_call->SetPath(object_path_)) |
67 return NULL; | 69 return NULL; |
68 | 70 |
69 method_call->SetDestination(service_name_); | |
70 method_call->SetPath(object_path_); | |
71 DBusMessage* request_message = method_call->raw_message(); | 71 DBusMessage* request_message = method_call->raw_message(); |
72 | 72 |
73 ScopedDBusError error; | 73 ScopedDBusError error; |
74 | 74 |
75 // Send the message synchronously. | 75 // Send the message synchronously. |
76 const base::TimeTicks start_time = base::TimeTicks::Now(); | 76 const base::TimeTicks start_time = base::TimeTicks::Now(); |
77 DBusMessage* response_message = | 77 DBusMessage* response_message = |
78 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error.get()); | 78 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error.get()); |
79 // Record if the method call is successful, or not. 1 if successful. | 79 // Record if the method call is successful, or not. 1 if successful. |
80 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess", | 80 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess", |
(...skipping 20 matching lines...) Expand all Loading... |
101 this, | 101 this, |
102 callback)); | 102 callback)); |
103 } | 103 } |
104 | 104 |
105 void ObjectProxy::CallMethodWithErrorCallback(MethodCall* method_call, | 105 void ObjectProxy::CallMethodWithErrorCallback(MethodCall* method_call, |
106 int timeout_ms, | 106 int timeout_ms, |
107 ResponseCallback callback, | 107 ResponseCallback callback, |
108 ErrorCallback error_callback) { | 108 ErrorCallback error_callback) { |
109 bus_->AssertOnOriginThread(); | 109 bus_->AssertOnOriginThread(); |
110 | 110 |
111 method_call->SetDestination(service_name_); | 111 const base::TimeTicks start_time = base::TimeTicks::Now(); |
112 method_call->SetPath(object_path_); | 112 |
| 113 if (!method_call->SetDestination(service_name_) || |
| 114 !method_call->SetPath(object_path_)) { |
| 115 // In case of a failure, run the error callback with NULL. |
| 116 DBusMessage* response_message = NULL; |
| 117 base::Closure task = base::Bind(&ObjectProxy::RunResponseCallback, |
| 118 this, |
| 119 callback, |
| 120 error_callback, |
| 121 start_time, |
| 122 response_message); |
| 123 bus_->PostTaskToOriginThread(FROM_HERE, task); |
| 124 return; |
| 125 } |
| 126 |
113 // Increment the reference count so we can safely reference the | 127 // Increment the reference count so we can safely reference the |
114 // underlying request message until the method call is complete. This | 128 // underlying request message until the method call is complete. This |
115 // will be unref'ed in StartAsyncMethodCall(). | 129 // will be unref'ed in StartAsyncMethodCall(). |
116 DBusMessage* request_message = method_call->raw_message(); | 130 DBusMessage* request_message = method_call->raw_message(); |
117 dbus_message_ref(request_message); | 131 dbus_message_ref(request_message); |
118 | 132 |
119 const base::TimeTicks start_time = base::TimeTicks::Now(); | |
120 base::Closure task = base::Bind(&ObjectProxy::StartAsyncMethodCall, | 133 base::Closure task = base::Bind(&ObjectProxy::StartAsyncMethodCall, |
121 this, | 134 this, |
122 timeout_ms, | 135 timeout_ms, |
123 request_message, | 136 request_message, |
124 callback, | 137 callback, |
125 error_callback, | 138 error_callback, |
126 start_time); | 139 start_time); |
127 // Wait for the response in the D-Bus thread. | 140 // Wait for the response in the D-Bus thread. |
128 bus_->PostTaskToDBusThread(FROM_HERE, task); | 141 bus_->PostTaskToDBusThread(FROM_HERE, task); |
129 } | 142 } |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 // Error message may contain the error message as string. | 463 // Error message may contain the error message as string. |
451 dbus::MessageReader reader(error_response); | 464 dbus::MessageReader reader(error_response); |
452 std::string error_message; | 465 std::string error_message; |
453 reader.PopString(&error_message); | 466 reader.PopString(&error_message); |
454 LogMethodCallFailure(error_response->GetErrorName(), error_message); | 467 LogMethodCallFailure(error_response->GetErrorName(), error_message); |
455 } | 468 } |
456 response_callback.Run(NULL); | 469 response_callback.Run(NULL); |
457 } | 470 } |
458 | 471 |
459 } // namespace dbus | 472 } // namespace dbus |
OLD | NEW |