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 ignore_service_unknown_errors_( | 56 ignore_service_unknown_errors_( |
57 options & IGNORE_SERVICE_UNKNOWN_ERRORS) { | 57 options & IGNORE_SERVICE_UNKNOWN_ERRORS) { |
58 } | 58 } |
59 | 59 |
60 ObjectProxy::~ObjectProxy() { | 60 ObjectProxy::~ObjectProxy() { |
61 } | 61 } |
62 | 62 |
63 // Originally we tried to make |method_call| a const reference, but we | 63 // Originally we tried to make |method_call| a const reference, but we |
64 // gave up as dbus_connection_send_with_reply_and_block() takes a | 64 // gave up as dbus_connection_send_with_reply_and_block() takes a |
65 // non-const pointer of DBusMessage as the second parameter. | 65 // non-const pointer of DBusMessage as the second parameter. |
66 Response* ObjectProxy::CallMethodAndBlock(MethodCall* method_call, | 66 scoped_ptr<Response> ObjectProxy::CallMethodAndBlock(MethodCall* method_call, |
67 int timeout_ms) { | 67 int timeout_ms) { |
68 bus_->AssertOnDBusThread(); | 68 bus_->AssertOnDBusThread(); |
69 | 69 |
70 if (!bus_->Connect() || | 70 if (!bus_->Connect() || |
71 !method_call->SetDestination(service_name_) || | 71 !method_call->SetDestination(service_name_) || |
72 !method_call->SetPath(object_path_)) | 72 !method_call->SetPath(object_path_)) |
73 return NULL; | 73 return scoped_ptr<Response>(); |
74 | 74 |
75 DBusMessage* request_message = method_call->raw_message(); | 75 DBusMessage* request_message = method_call->raw_message(); |
76 | 76 |
77 ScopedDBusError error; | 77 ScopedDBusError error; |
78 | 78 |
79 // Send the message synchronously. | 79 // Send the message synchronously. |
80 const base::TimeTicks start_time = base::TimeTicks::Now(); | 80 const base::TimeTicks start_time = base::TimeTicks::Now(); |
81 DBusMessage* response_message = | 81 DBusMessage* response_message = |
82 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error.get()); | 82 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error.get()); |
83 // Record if the method call is successful, or not. 1 if successful. | 83 // Record if the method call is successful, or not. 1 if successful. |
84 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess", | 84 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess", |
85 response_message ? 1 : 0, | 85 response_message ? 1 : 0, |
86 kSuccessRatioHistogramMaxValue); | 86 kSuccessRatioHistogramMaxValue); |
87 statistics::AddBlockingSentMethodCall(service_name_, | 87 statistics::AddBlockingSentMethodCall(service_name_, |
88 method_call->GetInterface(), | 88 method_call->GetInterface(), |
89 method_call->GetMember()); | 89 method_call->GetMember()); |
90 | 90 |
91 if (!response_message) { | 91 if (!response_message) { |
92 LogMethodCallFailure(method_call->GetInterface(), | 92 LogMethodCallFailure(method_call->GetInterface(), |
93 method_call->GetMember(), | 93 method_call->GetMember(), |
94 error.is_set() ? error.name() : "unknown error type", | 94 error.is_set() ? error.name() : "unknown error type", |
95 error.is_set() ? error.message() : ""); | 95 error.is_set() ? error.message() : ""); |
96 return NULL; | 96 return scoped_ptr<Response>(); |
97 } | 97 } |
98 // Record time spent for the method call. Don't include failures. | 98 // Record time spent for the method call. Don't include failures. |
99 UMA_HISTOGRAM_TIMES("DBus.SyncMethodCallTime", | 99 UMA_HISTOGRAM_TIMES("DBus.SyncMethodCallTime", |
100 base::TimeTicks::Now() - start_time); | 100 base::TimeTicks::Now() - start_time); |
101 | 101 |
102 return Response::FromRawMessage(response_message); | 102 return Response::FromRawMessage(response_message); |
103 } | 103 } |
104 | 104 |
105 void ObjectProxy::CallMethod(MethodCall* method_call, | 105 void ObjectProxy::CallMethod(MethodCall* method_call, |
106 int timeout_ms, | 106 int timeout_ms, |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 } | 663 } |
664 } | 664 } |
665 } | 665 } |
666 | 666 |
667 // Always return unhandled to let other object proxies handle the same | 667 // Always return unhandled to let other object proxies handle the same |
668 // signal. | 668 // signal. |
669 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 669 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
670 } | 670 } |
671 | 671 |
672 } // namespace dbus | 672 } // namespace dbus |
OLD | NEW |