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 "chromeos/dbus/blocking_method_caller.h" | 5 #include "chromeos/dbus/blocking_method_caller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/task_runner.h" | 10 #include "base/task_runner.h" |
11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
12 #include "dbus/bus.h" | 12 #include "dbus/bus.h" |
13 #include "dbus/object_proxy.h" | 13 #include "dbus/object_proxy.h" |
| 14 #include "dbus/scoped_dbus_error.h" |
14 | 15 |
15 namespace chromeos { | 16 namespace chromeos { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // This function is a part of CallMethodAndBlock implementation. | 20 // This function is a part of CallMethodAndBlock implementation. |
20 void CallMethodAndBlockInternal(std::unique_ptr<dbus::Response>* response, | 21 void CallMethodAndBlockInternal(std::unique_ptr<dbus::Response>* response, |
21 base::ScopedClosureRunner* signaler, | 22 base::ScopedClosureRunner* signaler, |
22 dbus::ObjectProxy* proxy, | 23 dbus::ObjectProxy* proxy, |
23 dbus::MethodCall* method_call) { | 24 dbus::MethodCall* method_call, |
24 *response = proxy->CallMethodAndBlock( | 25 dbus::ScopedDBusError* error_out) { |
25 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); | 26 *response = proxy->CallMethodAndBlockWithErrorDetails( |
| 27 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, error_out); |
26 } | 28 } |
27 | 29 |
28 } // namespace | 30 } // namespace |
29 | 31 |
30 BlockingMethodCaller::BlockingMethodCaller(dbus::Bus* bus, | 32 BlockingMethodCaller::BlockingMethodCaller(dbus::Bus* bus, |
31 dbus::ObjectProxy* proxy) | 33 dbus::ObjectProxy* proxy) |
32 : bus_(bus), | 34 : bus_(bus), |
33 proxy_(proxy), | 35 proxy_(proxy), |
34 on_blocking_method_call_( | 36 on_blocking_method_call_( |
35 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 37 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
36 base::WaitableEvent::InitialState::NOT_SIGNALED) {} | 38 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
37 | 39 |
38 BlockingMethodCaller::~BlockingMethodCaller() { | 40 BlockingMethodCaller::~BlockingMethodCaller() { |
39 } | 41 } |
40 | 42 |
41 std::unique_ptr<dbus::Response> BlockingMethodCaller::CallMethodAndBlock( | 43 std::unique_ptr<dbus::Response> BlockingMethodCaller::CallMethodAndBlock( |
42 dbus::MethodCall* method_call) { | 44 dbus::MethodCall* method_call) { |
| 45 dbus::ScopedDBusError error; |
| 46 return CallMethodAndBlockWithError(method_call, &error); |
| 47 } |
| 48 |
| 49 std::unique_ptr<dbus::Response> |
| 50 BlockingMethodCaller::CallMethodAndBlockWithError( |
| 51 dbus::MethodCall* method_call, |
| 52 dbus::ScopedDBusError* error_out) { |
43 // on_blocking_method_call_->Signal() will be called when |signaler| is | 53 // on_blocking_method_call_->Signal() will be called when |signaler| is |
44 // destroyed. | 54 // destroyed. |
45 base::Closure signal_task( | 55 base::Closure signal_task( |
46 base::Bind(&base::WaitableEvent::Signal, | 56 base::Bind(&base::WaitableEvent::Signal, |
47 base::Unretained(&on_blocking_method_call_))); | 57 base::Unretained(&on_blocking_method_call_))); |
48 base::ScopedClosureRunner* signaler = | 58 base::ScopedClosureRunner* signaler = |
49 new base::ScopedClosureRunner(signal_task); | 59 new base::ScopedClosureRunner(signal_task); |
50 | 60 |
51 std::unique_ptr<dbus::Response> response; | 61 std::unique_ptr<dbus::Response> response; |
52 bus_->GetDBusTaskRunner()->PostTask( | 62 bus_->GetDBusTaskRunner()->PostTask( |
53 FROM_HERE, | 63 FROM_HERE, |
54 base::Bind(&CallMethodAndBlockInternal, | 64 base::Bind(&CallMethodAndBlockInternal, &response, base::Owned(signaler), |
55 &response, | 65 base::Unretained(proxy_), method_call, error_out)); |
56 base::Owned(signaler), | |
57 base::Unretained(proxy_), | |
58 method_call)); | |
59 // http://crbug.com/125360 | 66 // http://crbug.com/125360 |
60 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 67 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
61 on_blocking_method_call_.Wait(); | 68 on_blocking_method_call_.Wait(); |
62 return response; | 69 return response; |
63 } | 70 } |
64 | 71 |
65 } // namespace chromeos | 72 } // namespace chromeos |
OLD | NEW |