OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_DBUS_FLIMFLAM_CLIENT_HELPER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_DBUS_FLIMFLAM_CLIENT_HELPER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/callback.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "chrome/browser/chromeos/dbus/dbus_method_call_status.h" | |
14 | |
15 namespace base { | |
16 | |
17 class Value; | |
18 class DictionaryValue; | |
19 | |
20 } // namespace base | |
21 | |
22 namespace dbus { | |
23 | |
24 class MethodCall; | |
25 class ObjectProxy; | |
26 class Response; | |
27 class Signal; | |
28 | |
29 } // namespace dbus | |
30 | |
31 namespace chromeos { | |
32 | |
33 // A class to help implement Flimflam clients. | |
34 class FlimflamClientHelper { | |
35 public: | |
36 explicit FlimflamClientHelper(dbus::ObjectProxy* proxy); | |
37 | |
38 virtual ~FlimflamClientHelper(); | |
39 | |
40 // A callback to handle PropertyChanged signals. | |
41 typedef base::Callback<void(const std::string& name, | |
42 const base::Value& value)> PropertyChangedHandler; | |
43 | |
44 // A callback to handle responses for methods without results. | |
45 typedef base::Callback<void(DBusMethodCallStatus call_status)> VoidCallback; | |
46 | |
47 // A callback to handle responses for methods with DictionaryValue results. | |
48 typedef base::Callback<void( | |
49 DBusMethodCallStatus call_status, | |
50 const base::DictionaryValue& result)> DictionaryValueCallback; | |
51 | |
52 // Sets PropertyChanged signal handler. | |
53 void SetPropertyChangedHandler(const PropertyChangedHandler& handler); | |
54 | |
55 // Resets PropertyChanged signal handler. | |
56 void ResetPropertyChangedHandler(); | |
57 | |
58 // Starts monitoring PropertyChanged signal. | |
59 void MonitorPropertyChanged(const std::string& interface_name); | |
60 | |
61 // Calls a method without results. | |
62 void CallVoidMethod(dbus::MethodCall* method_call, | |
63 const VoidCallback& callback); | |
64 | |
65 // Calls a method with a dictionary value result. | |
66 void CallDictionaryValueMethod(dbus::MethodCall* method_call, | |
67 const DictionaryValueCallback& callback); | |
68 | |
69 private: | |
70 // Handles the result of signal connection setup. | |
71 void OnSignalConnected(const std::string& interface, | |
72 const std::string& signal, | |
73 bool success); | |
74 | |
75 // Handles PropertyChanged signal. | |
76 void OnPropertyChanged(dbus::Signal* signal); | |
77 | |
78 // Handles responses for methods without results. | |
79 void OnVoidMethod(const VoidCallback& callback, dbus::Response* response); | |
80 | |
81 // Handles responses for methods with DictionaryValue results. | |
82 void OnDictionaryValueMethod(const DictionaryValueCallback& callback, | |
83 dbus::Response* response); | |
84 | |
85 base::WeakPtrFactory<FlimflamClientHelper> weak_ptr_factory_; | |
86 dbus::ObjectProxy* proxy_; | |
87 PropertyChangedHandler property_changed_handler_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(FlimflamClientHelper); | |
90 }; | |
91 | |
92 } // namespace chromeos | |
93 | |
94 #endif // CHROME_BROWSER_CHROMEOS_DBUS_FLIMFLAM_CLIENT_HELPER_H_ | |
OLD | NEW |