[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / chromeos / dbus / blocking_method_caller.h
blob95aa44041a99697c6674eb38c6638e56db7295ac
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 #ifndef CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_
6 #define CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_
8 #include "base/callback.h"
9 #include "base/synchronization/waitable_event.h"
10 #include "chromeos/chromeos_export.h"
12 namespace dbus {
14 class Bus;
15 class ObjectProxy;
16 class MethodCall;
17 class Response;
19 } // namespace dbus
21 namespace chromeos {
23 // A utility class to call D-Bus methods in a synchronous (blocking) way.
24 // Note: Blocking the thread until it returns is not a good idea in most cases.
25 // Avoid using this class as hard as you can.
26 class CHROMEOS_EXPORT BlockingMethodCaller {
27 public:
28 BlockingMethodCaller(dbus::Bus* bus, dbus::ObjectProxy* proxy);
29 virtual ~BlockingMethodCaller();
31 // Calls the method and blocks until it returns.
32 // The caller is responsible to delete the returned object.
33 dbus::Response* CallMethodAndBlock(dbus::MethodCall* method_call);
35 private:
36 dbus::Bus* bus_;
37 dbus::ObjectProxy* proxy_;
38 base::WaitableEvent on_blocking_method_call_;
40 DISALLOW_COPY_AND_ASSIGN(BlockingMethodCaller);
43 } // namespace chromeos
45 #endif // CHROMEOS_DBUS_BLOCKING_METHOD_CALLER_H_