| 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/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "dbus/bus.h" | 9 #include "dbus/bus.h" |
| 10 #include "dbus/object_proxy.h" | 10 #include "dbus/object_proxy.h" |
| 11 | 11 |
| 12 namespace chromeos { | 12 namespace chromeos { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // This function is a part of CallMethodAndBlock implementation. | 16 // This function is a part of CallMethodAndBlock implementation. |
| 17 void CallMethodAndBlockInternal( | 17 void CallMethodAndBlockInternal( |
| 18 dbus::Response** response, | 18 scoped_ptr<dbus::Response>* response, |
| 19 base::ScopedClosureRunner* signaler, | 19 base::ScopedClosureRunner* signaler, |
| 20 dbus::ObjectProxy* proxy, | 20 dbus::ObjectProxy* proxy, |
| 21 dbus::MethodCall* method_call) { | 21 dbus::MethodCall* method_call) { |
| 22 *response = proxy->CallMethodAndBlock( | 22 *response = proxy->CallMethodAndBlock( |
| 23 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); | 23 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 BlockingMethodCaller::BlockingMethodCaller(dbus::Bus* bus, | 28 BlockingMethodCaller::BlockingMethodCaller(dbus::Bus* bus, |
| 29 dbus::ObjectProxy* proxy) | 29 dbus::ObjectProxy* proxy) |
| 30 : bus_(bus), | 30 : bus_(bus), |
| 31 proxy_(proxy), | 31 proxy_(proxy), |
| 32 on_blocking_method_call_(false /* manual_reset */, | 32 on_blocking_method_call_(false /* manual_reset */, |
| 33 false /* initially_signaled */) { | 33 false /* initially_signaled */) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 BlockingMethodCaller::~BlockingMethodCaller() { | 36 BlockingMethodCaller::~BlockingMethodCaller() { |
| 37 } | 37 } |
| 38 | 38 |
| 39 dbus::Response* BlockingMethodCaller::CallMethodAndBlock( | 39 scoped_ptr<dbus::Response> BlockingMethodCaller::CallMethodAndBlock( |
| 40 dbus::MethodCall* method_call) { | 40 dbus::MethodCall* method_call) { |
| 41 // on_blocking_method_call_->Signal() will be called when |signaler| is | 41 // on_blocking_method_call_->Signal() will be called when |signaler| is |
| 42 // destroyed. | 42 // destroyed. |
| 43 base::Closure signal_task( | 43 base::Closure signal_task( |
| 44 base::Bind(&base::WaitableEvent::Signal, | 44 base::Bind(&base::WaitableEvent::Signal, |
| 45 base::Unretained(&on_blocking_method_call_))); | 45 base::Unretained(&on_blocking_method_call_))); |
| 46 base::ScopedClosureRunner* signaler = | 46 base::ScopedClosureRunner* signaler = |
| 47 new base::ScopedClosureRunner(signal_task); | 47 new base::ScopedClosureRunner(signal_task); |
| 48 | 48 |
| 49 dbus::Response* response = NULL; | 49 scoped_ptr<dbus::Response> response; |
| 50 bus_->PostTaskToDBusThread( | 50 bus_->PostTaskToDBusThread( |
| 51 FROM_HERE, | 51 FROM_HERE, |
| 52 base::Bind(&CallMethodAndBlockInternal, | 52 base::Bind(&CallMethodAndBlockInternal, |
| 53 &response, | 53 &response, |
| 54 base::Owned(signaler), | 54 base::Owned(signaler), |
| 55 base::Unretained(proxy_), | 55 base::Unretained(proxy_), |
| 56 method_call)); | 56 method_call)); |
| 57 // http://crbug.com/125360 | 57 // http://crbug.com/125360 |
| 58 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 58 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 59 on_blocking_method_call_.Wait(); | 59 on_blocking_method_call_.Wait(); |
| 60 return response; | 60 return response.Pass(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace chromeos | 63 } // namespace chromeos |
| OLD | NEW |