Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: chrome/browser/chromeos/dbus/flimflam_profile_client.cc

Issue 9838085: Move files inside chrome/browser/chromeos/dbus to chromeos/dbus (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "chrome/browser/chromeos/dbus/flimflam_profile_client.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "dbus/bus.h"
10 #include "dbus/message.h"
11 #include "dbus/object_path.h"
12 #include "dbus/object_proxy.h"
13 #include "dbus/values_util.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h"
15
16 namespace chromeos {
17
18 namespace {
19
20 // The FlimflamProfileClient implementation.
21 class FlimflamProfileClientImpl : public FlimflamProfileClient {
22 public:
23 explicit FlimflamProfileClientImpl(dbus::Bus* bus);
24
25 // FlimflamProfileClient overrides:
26 virtual void SetPropertyChangedHandler(
27 const PropertyChangedHandler& handler) OVERRIDE;
28 virtual void ResetPropertyChangedHandler() OVERRIDE;
29 virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE;
30 virtual void GetEntry(const dbus::ObjectPath& path,
31 const DictionaryValueCallback& callback) OVERRIDE;
32 virtual void DeleteEntry(const dbus::ObjectPath& path,
33 const VoidCallback& callback) OVERRIDE;
34
35 private:
36 // Handles the result of signal connection setup.
37 void OnSignalConnected(const std::string& interface,
38 const std::string& signal,
39 bool success);
40 // Handles PropertyChanged signal.
41 void OnPropertyChanged(dbus::Signal* signal);
42 // Handles responses for methods without results.
43 void OnVoidMethod(const VoidCallback& callback, dbus::Response* response);
44 // Handles responses for methods with DictionaryValue results.
45 void OnDictionaryValueMethod(const DictionaryValueCallback& callback,
46 dbus::Response* response);
47
48 dbus::ObjectProxy* proxy_;
49 FlimflamClientHelper helper_;
50
51 DISALLOW_COPY_AND_ASSIGN(FlimflamProfileClientImpl);
52 };
53
54 FlimflamProfileClientImpl::FlimflamProfileClientImpl(dbus::Bus* bus)
55 : proxy_(bus->GetObjectProxy(
56 flimflam::kFlimflamServiceName,
57 dbus::ObjectPath(flimflam::kFlimflamServicePath))),
58 helper_(proxy_) {
59 helper_.MonitorPropertyChanged(flimflam::kFlimflamProfileInterface);
60 }
61
62 void FlimflamProfileClientImpl::SetPropertyChangedHandler(
63 const PropertyChangedHandler& handler) {
64 helper_.SetPropertyChangedHandler(handler);
65 }
66
67 void FlimflamProfileClientImpl::ResetPropertyChangedHandler() {
68 helper_.ResetPropertyChangedHandler();
69 }
70
71 void FlimflamProfileClientImpl::GetProperties(
72 const DictionaryValueCallback& callback) {
73 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
74 flimflam::kGetPropertiesFunction);
75 helper_.CallDictionaryValueMethod(&method_call, callback);
76 }
77
78 void FlimflamProfileClientImpl::GetEntry(
79 const dbus::ObjectPath& path,
80 const DictionaryValueCallback& callback) {
81 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
82 flimflam::kGetEntryFunction);
83 dbus::MessageWriter writer(&method_call);
84 writer.AppendObjectPath(path);
85 helper_.CallDictionaryValueMethod(&method_call, callback);
86 }
87
88 void FlimflamProfileClientImpl::DeleteEntry(const dbus::ObjectPath& path,
89 const VoidCallback& callback) {
90 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
91 flimflam::kDeleteEntryFunction);
92 dbus::MessageWriter writer(&method_call);
93 writer.AppendObjectPath(path);
94 helper_.CallVoidMethod(&method_call, callback);
95 }
96
97 // A stub implementation of FlimflamProfileClient.
98 class FlimflamProfileClientStubImpl : public FlimflamProfileClient {
99 public:
100 FlimflamProfileClientStubImpl() : weak_ptr_factory_(this) {}
101
102 virtual ~FlimflamProfileClientStubImpl() {}
103
104 // FlimflamProfileClient override.
105 virtual void SetPropertyChangedHandler(
106 const PropertyChangedHandler& handler) OVERRIDE {}
107
108 // FlimflamProfileClient override.
109 virtual void ResetPropertyChangedHandler() OVERRIDE {}
110
111 // FlimflamProfileClient override.
112 virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE {
113 MessageLoop::current()->PostTask(
114 FROM_HERE,
115 base::Bind(&FlimflamProfileClientStubImpl::PassEmptyDictionaryValue,
116 weak_ptr_factory_.GetWeakPtr(),
117 callback));
118 }
119
120 // FlimflamProfileClient override.
121 virtual void GetEntry(const dbus::ObjectPath& path,
122 const DictionaryValueCallback& callback) OVERRIDE {
123 MessageLoop::current()->PostTask(
124 FROM_HERE,
125 base::Bind(&FlimflamProfileClientStubImpl::PassEmptyDictionaryValue,
126 weak_ptr_factory_.GetWeakPtr(),
127 callback));
128 }
129
130 // FlimflamProfileClient override.
131 virtual void DeleteEntry(const dbus::ObjectPath& path,
132 const VoidCallback& callback) OVERRIDE {
133 MessageLoop::current()->PostTask(FROM_HERE,
134 base::Bind(callback,
135 DBUS_METHOD_CALL_SUCCESS));
136 }
137
138 private:
139 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const {
140 base::DictionaryValue dictionary;
141 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary);
142 }
143
144 base::WeakPtrFactory<FlimflamProfileClientStubImpl> weak_ptr_factory_;
145
146 DISALLOW_COPY_AND_ASSIGN(FlimflamProfileClientStubImpl);
147 };
148
149 } // namespace
150
151 FlimflamProfileClient::FlimflamProfileClient() {}
152
153 FlimflamProfileClient::~FlimflamProfileClient() {}
154
155 // static
156 FlimflamProfileClient* FlimflamProfileClient::Create(
157 DBusClientImplementationType type,
158 dbus::Bus* bus) {
159 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
160 return new FlimflamProfileClientImpl(bus);
161 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
162 return new FlimflamProfileClientStubImpl();
163 }
164
165 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/flimflam_profile_client.h ('k') | chrome/browser/chromeos/dbus/image_burner_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698