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/threading/thread_restrictions.h"
10 #include "dbus/object_proxy.h"
16 // This function is a part of CallMethodAndBlock implementation.
17 void CallMethodAndBlockInternal(
18 dbus::Response
** response
,
19 base::ScopedClosureRunner
* signaler
,
20 dbus::ObjectProxy
* proxy
,
21 dbus::MethodCall
* method_call
) {
22 *response
= proxy
->CallMethodAndBlock(
23 method_call
, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT
);
28 BlockingMethodCaller::BlockingMethodCaller(dbus::Bus
* bus
,
29 dbus::ObjectProxy
* proxy
)
32 on_blocking_method_call_(false /* manual_reset */,
33 false /* initially_signaled */) {
36 BlockingMethodCaller::~BlockingMethodCaller() {
39 dbus::Response
* BlockingMethodCaller::CallMethodAndBlock(
40 dbus::MethodCall
* method_call
) {
41 // on_blocking_method_call_->Signal() will be called when |signaler| is
43 base::Closure
signal_task(
44 base::Bind(&base::WaitableEvent::Signal
,
45 base::Unretained(&on_blocking_method_call_
)));
46 base::ScopedClosureRunner
* signaler
=
47 new base::ScopedClosureRunner(signal_task
);
49 dbus::Response
* response
= NULL
;
50 bus_
->PostTaskToDBusThread(
52 base::Bind(&CallMethodAndBlockInternal
,
54 base::Owned(signaler
),
55 base::Unretained(proxy_
),
57 // http://crbug.com/125360
58 base::ThreadRestrictions::ScopedAllowWait allow_wait
;
59 on_blocking_method_call_
.Wait();
63 } // namespace chromeos