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

Side by Side Diff: dbus/object_proxy.cc

Issue 8536007: dbus: Add ObjectProxy::EmptyResponseCallback(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 9 years, 1 month 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/object_proxy.h ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 11 matching lines...) Expand all
22 22
23 // Gets the absolute signal name by concatenating the interface name and 23 // Gets the absolute signal name by concatenating the interface name and
24 // the signal name. Used for building keys for method_table_ in 24 // the signal name. Used for building keys for method_table_ in
25 // ObjectProxy. 25 // ObjectProxy.
26 std::string GetAbsoluteSignalName( 26 std::string GetAbsoluteSignalName(
27 const std::string& interface_name, 27 const std::string& interface_name,
28 const std::string& signal_name) { 28 const std::string& signal_name) {
29 return interface_name + "." + signal_name; 29 return interface_name + "." + signal_name;
30 } 30 }
31 31
32 // An empty function used for ObjectProxy::EmptyResponseCallback().
33 void EmptyResponseCallbackBody(dbus::Response* unused_response) {
34 }
35
32 } // namespace 36 } // namespace
33 37
34 namespace dbus { 38 namespace dbus {
35 39
36 ObjectProxy::ObjectProxy(Bus* bus, 40 ObjectProxy::ObjectProxy(Bus* bus,
37 const std::string& service_name, 41 const std::string& service_name,
38 const std::string& object_path) 42 const std::string& object_path)
39 : bus_(bus), 43 : bus_(bus),
40 service_name_(service_name), 44 service_name_(service_name),
41 object_path_(object_path), 45 object_path_(object_path),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 for (size_t i = 0; i < match_rules_.size(); ++i) { 137 for (size_t i = 0; i < match_rules_.size(); ++i) {
134 ScopedDBusError error; 138 ScopedDBusError error;
135 bus_->RemoveMatch(match_rules_[i], error.get()); 139 bus_->RemoveMatch(match_rules_[i], error.get());
136 if (error.is_set()) { 140 if (error.is_set()) {
137 // There is nothing we can do to recover, so just print the error. 141 // There is nothing we can do to recover, so just print the error.
138 LOG(ERROR) << "Failed to remove match rule: " << match_rules_[i]; 142 LOG(ERROR) << "Failed to remove match rule: " << match_rules_[i];
139 } 143 }
140 } 144 }
141 } 145 }
142 146
147 // static
148 ObjectProxy::ResponseCallback ObjectProxy::EmptyResponseCallback() {
149 return base::Bind(&EmptyResponseCallbackBody);
150 }
151
143 ObjectProxy::OnPendingCallIsCompleteData::OnPendingCallIsCompleteData( 152 ObjectProxy::OnPendingCallIsCompleteData::OnPendingCallIsCompleteData(
144 ObjectProxy* in_object_proxy, 153 ObjectProxy* in_object_proxy,
145 ResponseCallback in_response_callback, 154 ResponseCallback in_response_callback,
146 base::TimeTicks in_start_time) 155 base::TimeTicks in_start_time)
147 : object_proxy(in_object_proxy), 156 : object_proxy(in_object_proxy),
148 response_callback(in_response_callback), 157 response_callback(in_response_callback),
149 start_time(in_start_time) { 158 start_time(in_start_time) {
150 } 159 }
151 160
152 ObjectProxy::OnPendingCallIsCompleteData::~OnPendingCallIsCompleteData() { 161 ObjectProxy::OnPendingCallIsCompleteData::~OnPendingCallIsCompleteData() {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 start_time, 214 start_time,
206 response_message); 215 response_message);
207 bus_->PostTaskToOriginThread(FROM_HERE, task); 216 bus_->PostTaskToOriginThread(FROM_HERE, task);
208 } 217 }
209 218
210 void ObjectProxy::RunResponseCallback(ResponseCallback response_callback, 219 void ObjectProxy::RunResponseCallback(ResponseCallback response_callback,
211 base::TimeTicks start_time, 220 base::TimeTicks start_time,
212 DBusMessage* response_message) { 221 DBusMessage* response_message) {
213 bus_->AssertOnOriginThread(); 222 bus_->AssertOnOriginThread();
214 223
215 bool response_callback_called = false; 224 bool method_call_successful = false;
216 if (!response_message) { 225 if (!response_message) {
217 // The response is not received. 226 // The response is not received.
218 response_callback.Run(NULL); 227 response_callback.Run(NULL);
219 } else if (dbus_message_get_type(response_message) == 228 } else if (dbus_message_get_type(response_message) ==
220 DBUS_MESSAGE_TYPE_ERROR) { 229 DBUS_MESSAGE_TYPE_ERROR) {
221 // This will take |response_message| and release (unref) it. 230 // This will take |response_message| and release (unref) it.
222 scoped_ptr<dbus::ErrorResponse> error_response( 231 scoped_ptr<dbus::ErrorResponse> error_response(
223 dbus::ErrorResponse::FromRawMessage(response_message)); 232 dbus::ErrorResponse::FromRawMessage(response_message));
224 // Error message may contain the error message as string. 233 // Error message may contain the error message as string.
225 dbus::MessageReader reader(error_response.get()); 234 dbus::MessageReader reader(error_response.get());
226 std::string error_message; 235 std::string error_message;
227 reader.PopString(&error_message); 236 reader.PopString(&error_message);
228 LOG(ERROR) << "Failed to call method: " << error_response->GetErrorName() 237 LOG(ERROR) << "Failed to call method: " << error_response->GetErrorName()
229 << ": " << error_message; 238 << ": " << error_message;
230 // We don't give the error message to the callback. 239 // We don't give the error message to the callback.
231 response_callback.Run(NULL); 240 response_callback.Run(NULL);
232 } else { 241 } else {
233 // This will take |response_message| and release (unref) it. 242 // This will take |response_message| and release (unref) it.
234 scoped_ptr<dbus::Response> response( 243 scoped_ptr<dbus::Response> response(
235 dbus::Response::FromRawMessage(response_message)); 244 dbus::Response::FromRawMessage(response_message));
236 // The response is successfully received. 245 // The response is successfully received.
237 response_callback.Run(response.get()); 246 response_callback.Run(response.get());
238 response_callback_called = true; 247 method_call_successful = true;
239 // Record time spent for the method call. Don't include failures. 248 // Record time spent for the method call. Don't include failures.
240 UMA_HISTOGRAM_TIMES("DBus.AsyncMethodCallTime", 249 UMA_HISTOGRAM_TIMES("DBus.AsyncMethodCallTime",
241 base::TimeTicks::Now() - start_time); 250 base::TimeTicks::Now() - start_time);
242 } 251 }
243 // Record if the method call is successful, or not. 1 if successful. 252 // Record if the method call is successful, or not. 1 if successful.
244 UMA_HISTOGRAM_ENUMERATION("DBus.AsyncMethodCallSuccess", 253 UMA_HISTOGRAM_ENUMERATION("DBus.AsyncMethodCallSuccess",
245 response_callback_called, 254 method_call_successful,
246 kSuccessRatioHistogramMaxValue); 255 kSuccessRatioHistogramMaxValue);
247 } 256 }
248 257
249 void ObjectProxy::OnPendingCallIsCompleteThunk(DBusPendingCall* pending_call, 258 void ObjectProxy::OnPendingCallIsCompleteThunk(DBusPendingCall* pending_call,
250 void* user_data) { 259 void* user_data) {
251 OnPendingCallIsCompleteData* data = 260 OnPendingCallIsCompleteData* data =
252 reinterpret_cast<OnPendingCallIsCompleteData*>(user_data); 261 reinterpret_cast<OnPendingCallIsCompleteData*>(user_data);
253 ObjectProxy* self = data->object_proxy; 262 ObjectProxy* self = data->object_proxy;
254 self->OnPendingCallIsComplete(pending_call, 263 self->OnPendingCallIsComplete(pending_call,
255 data->response_callback, 264 data->response_callback,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 400
392 DBusHandlerResult ObjectProxy::HandleMessageThunk( 401 DBusHandlerResult ObjectProxy::HandleMessageThunk(
393 DBusConnection* connection, 402 DBusConnection* connection,
394 DBusMessage* raw_message, 403 DBusMessage* raw_message,
395 void* user_data) { 404 void* user_data) {
396 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data); 405 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data);
397 return self->HandleMessage(connection, raw_message); 406 return self->HandleMessage(connection, raw_message);
398 } 407 }
399 408
400 } // namespace dbus 409 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/object_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698