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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/blocking_method_caller.h"
8 #include "base/location.h"
9 #include "base/threading/thread_restrictions.h"
11 #include "dbus/object_proxy.h"
17 // This function is a part of CallMethodAndBlock implementation.
18 void CallMethodAndBlockInternal(
19 scoped_ptr
<dbus::Response
>* response
,
20 base::ScopedClosureRunner
* signaler
,
21 dbus::ObjectProxy
* proxy
,
22 dbus::MethodCall
* method_call
) {
23 *response
= proxy
->CallMethodAndBlock(
24 method_call
, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT
);
29 BlockingMethodCaller::BlockingMethodCaller(dbus::Bus
* bus
,
30 dbus::ObjectProxy
* proxy
)
33 on_blocking_method_call_(false /* manual_reset */,
34 false /* initially_signaled */) {
37 BlockingMethodCaller::~BlockingMethodCaller() {
40 scoped_ptr
<dbus::Response
> BlockingMethodCaller::CallMethodAndBlock(
41 dbus::MethodCall
* method_call
) {
42 // on_blocking_method_call_->Signal() will be called when |signaler| is
44 base::Closure
signal_task(
45 base::Bind(&base::WaitableEvent::Signal
,
46 base::Unretained(&on_blocking_method_call_
)));
47 base::ScopedClosureRunner
* signaler
=
48 new base::ScopedClosureRunner(signal_task
);
50 scoped_ptr
<dbus::Response
> response
;
51 bus_
->PostTaskToDBusThread(
53 base::Bind(&CallMethodAndBlockInternal
,
55 base::Owned(signaler
),
56 base::Unretained(proxy_
),
58 // http://crbug.com/125360
59 base::ThreadRestrictions::ScopedAllowWait allow_wait
;
60 on_blocking_method_call_
.Wait();
61 return response
.Pass();
64 } // namespace chromeos