OLD | NEW |
---|---|
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" |
11 #include "base/string_piece.h" | |
11 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
14 #include "dbus/message.h" | 15 #include "dbus/message.h" |
15 #include "dbus/object_proxy.h" | 16 #include "dbus/object_proxy.h" |
16 #include "dbus/scoped_dbus_error.h" | 17 #include "dbus/scoped_dbus_error.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
21 const char kErrorServiceUnknown[] = "org.freedesktop.DBus.Error.ServiceUnknown"; | |
22 | |
20 // Used for success ratio histograms. 1 for success, 0 for failure. | 23 // Used for success ratio histograms. 1 for success, 0 for failure. |
21 const int kSuccessRatioHistogramMaxValue = 2; | 24 const int kSuccessRatioHistogramMaxValue = 2; |
22 | 25 |
23 // Gets the absolute signal name by concatenating the interface name and | 26 // Gets the absolute signal name by concatenating the interface name and |
24 // the signal name. Used for building keys for method_table_ in | 27 // the signal name. Used for building keys for method_table_ in |
25 // ObjectProxy. | 28 // ObjectProxy. |
26 std::string GetAbsoluteSignalName( | 29 std::string GetAbsoluteSignalName( |
27 const std::string& interface_name, | 30 const std::string& interface_name, |
28 const std::string& signal_name) { | 31 const std::string& signal_name) { |
29 return interface_name + "." + signal_name; | 32 return interface_name + "." + signal_name; |
30 } | 33 } |
31 | 34 |
32 // An empty function used for ObjectProxy::EmptyResponseCallback(). | 35 // An empty function used for ObjectProxy::EmptyResponseCallback(). |
33 void EmptyResponseCallbackBody(dbus::Response* unused_response) { | 36 void EmptyResponseCallbackBody(dbus::Response* unused_response) { |
34 } | 37 } |
35 | 38 |
36 } // namespace | 39 } // namespace |
37 | 40 |
38 namespace dbus { | 41 namespace dbus { |
39 | 42 |
40 ObjectProxy::ObjectProxy(Bus* bus, | 43 ObjectProxy::ObjectProxy(Bus* bus, |
41 const std::string& service_name, | 44 const std::string& service_name, |
42 const std::string& object_path) | 45 const std::string& object_path, |
46 int options) | |
43 : bus_(bus), | 47 : bus_(bus), |
44 service_name_(service_name), | 48 service_name_(service_name), |
45 object_path_(object_path), | 49 object_path_(object_path), |
46 filter_added_(false) { | 50 filter_added_(false), |
51 log_unknown_service_errors_( | |
52 !(options & IGNORE_SERVICE_UNKNOWN_ERRORS)) { | |
47 } | 53 } |
48 | 54 |
49 ObjectProxy::~ObjectProxy() { | 55 ObjectProxy::~ObjectProxy() { |
50 } | 56 } |
51 | 57 |
52 // Originally we tried to make |method_call| a const reference, but we | 58 // Originally we tried to make |method_call| a const reference, but we |
53 // gave up as dbus_connection_send_with_reply_and_block() takes a | 59 // gave up as dbus_connection_send_with_reply_and_block() takes a |
54 // non-const pointer of DBusMessage as the second parameter. | 60 // non-const pointer of DBusMessage as the second parameter. |
55 Response* ObjectProxy::CallMethodAndBlock(MethodCall* method_call, | 61 Response* ObjectProxy::CallMethodAndBlock(MethodCall* method_call, |
56 int timeout_ms) { | 62 int timeout_ms) { |
(...skipping 11 matching lines...) Expand all Loading... | |
68 // Send the message synchronously. | 74 // Send the message synchronously. |
69 const base::TimeTicks start_time = base::TimeTicks::Now(); | 75 const base::TimeTicks start_time = base::TimeTicks::Now(); |
70 DBusMessage* response_message = | 76 DBusMessage* response_message = |
71 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error.get()); | 77 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error.get()); |
72 // Record if the method call is successful, or not. 1 if successful. | 78 // Record if the method call is successful, or not. 1 if successful. |
73 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess", | 79 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess", |
74 response_message ? 1 : 0, | 80 response_message ? 1 : 0, |
75 kSuccessRatioHistogramMaxValue); | 81 kSuccessRatioHistogramMaxValue); |
76 | 82 |
77 if (!response_message) { | 83 if (!response_message) { |
78 LOG(ERROR) << "Failed to call method: " | 84 base::StringPiece error_name(error.is_set() ? error.name() : ""); |
satorux1
2012/02/10 18:09:01
Cool. StringPiece is cheap. :)
| |
79 << (error.is_set() ? error.message() : ""); | 85 if (log_unknown_service_errors_ || error_name == kErrorServiceUnknown) { |
86 LOG(ERROR) << "Failed to call method: " | |
87 << (error.is_set() ? error.message() : ""); | |
88 } | |
80 return NULL; | 89 return NULL; |
81 } | 90 } |
82 // Record time spent for the method call. Don't include failures. | 91 // Record time spent for the method call. Don't include failures. |
83 UMA_HISTOGRAM_TIMES("DBus.SyncMethodCallTime", | 92 UMA_HISTOGRAM_TIMES("DBus.SyncMethodCallTime", |
84 base::TimeTicks::Now() - start_time); | 93 base::TimeTicks::Now() - start_time); |
85 | 94 |
86 return Response::FromRawMessage(response_message); | 95 return Response::FromRawMessage(response_message); |
87 } | 96 } |
88 | 97 |
89 void ObjectProxy::CallMethod(MethodCall* method_call, | 98 void ObjectProxy::CallMethod(MethodCall* method_call, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 if (!response_message) { | 236 if (!response_message) { |
228 // The response is not received. | 237 // The response is not received. |
229 response_callback.Run(NULL); | 238 response_callback.Run(NULL); |
230 } else if (dbus_message_get_type(response_message) == | 239 } else if (dbus_message_get_type(response_message) == |
231 DBUS_MESSAGE_TYPE_ERROR) { | 240 DBUS_MESSAGE_TYPE_ERROR) { |
232 // This will take |response_message| and release (unref) it. | 241 // This will take |response_message| and release (unref) it. |
233 scoped_ptr<dbus::ErrorResponse> error_response( | 242 scoped_ptr<dbus::ErrorResponse> error_response( |
234 dbus::ErrorResponse::FromRawMessage(response_message)); | 243 dbus::ErrorResponse::FromRawMessage(response_message)); |
235 // Error message may contain the error message as string. | 244 // Error message may contain the error message as string. |
236 dbus::MessageReader reader(error_response.get()); | 245 dbus::MessageReader reader(error_response.get()); |
237 std::string error_message; | 246 std::string error_name = error_response->GetErrorName(); |
238 reader.PopString(&error_message); | 247 if (log_unknown_service_errors_ || error_name != kErrorServiceUnknown) { |
239 LOG(ERROR) << "Failed to call method: " << error_response->GetErrorName() | 248 std::string error_message; |
240 << ": " << error_message; | 249 reader.PopString(&error_message); |
250 LOG(ERROR) << "Failed to call method: " << error_name | |
251 << ": " << error_message; | |
252 } | |
241 // We don't give the error message to the callback. | 253 // We don't give the error message to the callback. |
242 response_callback.Run(NULL); | 254 response_callback.Run(NULL); |
243 } else { | 255 } else { |
244 // This will take |response_message| and release (unref) it. | 256 // This will take |response_message| and release (unref) it. |
245 scoped_ptr<dbus::Response> response( | 257 scoped_ptr<dbus::Response> response( |
246 dbus::Response::FromRawMessage(response_message)); | 258 dbus::Response::FromRawMessage(response_message)); |
247 // The response is successfully received. | 259 // The response is successfully received. |
248 response_callback.Run(response.get()); | 260 response_callback.Run(response.get()); |
249 method_call_successful = true; | 261 method_call_successful = true; |
250 // Record time spent for the method call. Don't include failures. | 262 // Record time spent for the method call. Don't include failures. |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 | 422 |
411 DBusHandlerResult ObjectProxy::HandleMessageThunk( | 423 DBusHandlerResult ObjectProxy::HandleMessageThunk( |
412 DBusConnection* connection, | 424 DBusConnection* connection, |
413 DBusMessage* raw_message, | 425 DBusMessage* raw_message, |
414 void* user_data) { | 426 void* user_data) { |
415 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data); | 427 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data); |
416 return self->HandleMessage(connection, raw_message); | 428 return self->HandleMessage(connection, raw_message); |
417 } | 429 } |
418 | 430 |
419 } // namespace dbus | 431 } // namespace dbus |
OLD | NEW |