[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / chromeos / dbus / blocking_method_caller.cc
blob91c796c3a3bd1afc79e334b9629705951b7e26ed
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"
7 #include "base/bind.h"
8 #include "base/threading/thread_restrictions.h"
9 #include "dbus/bus.h"
10 #include "dbus/object_proxy.h"
12 namespace chromeos {
14 namespace {
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);
26 } // namespace
28 BlockingMethodCaller::BlockingMethodCaller(dbus::Bus* bus,
29 dbus::ObjectProxy* proxy)
30 : bus_(bus),
31 proxy_(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
42 // destroyed.
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(
51 FROM_HERE,
52 base::Bind(&CallMethodAndBlockInternal,
53 &response,
54 base::Owned(signaler),
55 base::Unretained(proxy_),
56 method_call));
57 // http://crbug.com/125360
58 base::ThreadRestrictions::ScopedAllowWait allow_wait;
59 on_blocking_method_call_.Wait();
60 return response;
63 } // namespace chromeos