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

Side by Side Diff: dbus/object_proxy.cc

Issue 563763004: Add ObjectProxy::CallMethodAndBlockWithErrorDetails methods (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed review comment Created 6 years, 3 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 | « 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) 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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 ignore_service_unknown_errors_( 59 ignore_service_unknown_errors_(
60 options & IGNORE_SERVICE_UNKNOWN_ERRORS) { 60 options & IGNORE_SERVICE_UNKNOWN_ERRORS) {
61 } 61 }
62 62
63 ObjectProxy::~ObjectProxy() { 63 ObjectProxy::~ObjectProxy() {
64 } 64 }
65 65
66 // Originally we tried to make |method_call| a const reference, but we 66 // Originally we tried to make |method_call| a const reference, but we
67 // gave up as dbus_connection_send_with_reply_and_block() takes a 67 // gave up as dbus_connection_send_with_reply_and_block() takes a
68 // non-const pointer of DBusMessage as the second parameter. 68 // non-const pointer of DBusMessage as the second parameter.
69 scoped_ptr<Response> ObjectProxy::CallMethodAndBlock(MethodCall* method_call, 69 scoped_ptr<Response> ObjectProxy::CallMethodAndBlockWithErrorDetails(
70 int timeout_ms) { 70 MethodCall* method_call, int timeout_ms, ScopedDBusError* error) {
71 bus_->AssertOnDBusThread(); 71 bus_->AssertOnDBusThread();
72 72
73 if (!bus_->Connect() || 73 if (!bus_->Connect() ||
74 !method_call->SetDestination(service_name_) || 74 !method_call->SetDestination(service_name_) ||
75 !method_call->SetPath(object_path_)) 75 !method_call->SetPath(object_path_))
76 return scoped_ptr<Response>(); 76 return scoped_ptr<Response>();
77 77
78 DBusMessage* request_message = method_call->raw_message(); 78 DBusMessage* request_message = method_call->raw_message();
79 79
80 ScopedDBusError error;
81
82 // Send the message synchronously. 80 // Send the message synchronously.
83 const base::TimeTicks start_time = base::TimeTicks::Now(); 81 const base::TimeTicks start_time = base::TimeTicks::Now();
84 DBusMessage* response_message = 82 DBusMessage* response_message =
85 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error.get()); 83 bus_->SendWithReplyAndBlock(request_message, timeout_ms, error->get());
86 // Record if the method call is successful, or not. 1 if successful. 84 // Record if the method call is successful, or not. 1 if successful.
87 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess", 85 UMA_HISTOGRAM_ENUMERATION("DBus.SyncMethodCallSuccess",
88 response_message ? 1 : 0, 86 response_message ? 1 : 0,
89 kSuccessRatioHistogramMaxValue); 87 kSuccessRatioHistogramMaxValue);
90 statistics::AddBlockingSentMethodCall(service_name_, 88 statistics::AddBlockingSentMethodCall(service_name_,
91 method_call->GetInterface(), 89 method_call->GetInterface(),
92 method_call->GetMember()); 90 method_call->GetMember());
93 91
94 if (!response_message) { 92 if (!response_message) {
95 LogMethodCallFailure(method_call->GetInterface(), 93 LogMethodCallFailure(method_call->GetInterface(),
96 method_call->GetMember(), 94 method_call->GetMember(),
97 error.is_set() ? error.name() : "unknown error type", 95 error->is_set() ? error->name() : "unknown error type",
98 error.is_set() ? error.message() : ""); 96 error->is_set() ? error->message() : "");
99 return scoped_ptr<Response>(); 97 return scoped_ptr<Response>();
100 } 98 }
101 // Record time spent for the method call. Don't include failures. 99 // Record time spent for the method call. Don't include failures.
102 UMA_HISTOGRAM_TIMES("DBus.SyncMethodCallTime", 100 UMA_HISTOGRAM_TIMES("DBus.SyncMethodCallTime",
103 base::TimeTicks::Now() - start_time); 101 base::TimeTicks::Now() - start_time);
104 102
105 return Response::FromRawMessage(response_message); 103 return Response::FromRawMessage(response_message);
106 } 104 }
107 105
106 scoped_ptr<Response> ObjectProxy::CallMethodAndBlock(MethodCall* method_call,
107 int timeout_ms) {
108 ScopedDBusError error;
109 return CallMethodAndBlockWithErrorDetails(method_call, timeout_ms, &error);
110 }
111
108 void ObjectProxy::CallMethod(MethodCall* method_call, 112 void ObjectProxy::CallMethod(MethodCall* method_call,
109 int timeout_ms, 113 int timeout_ms,
110 ResponseCallback callback) { 114 ResponseCallback callback) {
111 CallMethodWithErrorCallback(method_call, timeout_ms, callback, 115 CallMethodWithErrorCallback(method_call, timeout_ms, callback,
112 base::Bind(&ObjectProxy::OnCallMethodError, 116 base::Bind(&ObjectProxy::OnCallMethodError,
113 this, 117 this,
114 method_call->GetInterface(), 118 method_call->GetInterface(),
115 method_call->GetMember(), 119 method_call->GetMember(),
116 callback)); 120 callback));
117 } 121 }
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 bool service_is_available) { 699 bool service_is_available) {
696 bus_->AssertOnOriginThread(); 700 bus_->AssertOnOriginThread();
697 701
698 std::vector<WaitForServiceToBeAvailableCallback> callbacks; 702 std::vector<WaitForServiceToBeAvailableCallback> callbacks;
699 callbacks.swap(wait_for_service_to_be_available_callbacks_); 703 callbacks.swap(wait_for_service_to_be_available_callbacks_);
700 for (size_t i = 0; i < callbacks.size(); ++i) 704 for (size_t i = 0; i < callbacks.size(); ++i)
701 callbacks[i].Run(service_is_available); 705 callbacks[i].Run(service_is_available);
702 } 706 }
703 707
704 } // namespace dbus 708 } // 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