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

Side by Side Diff: chromeos/dbus/shill_service_client.cc

Issue 10915106: Renaming instances of "flimflam" with "shill", now that we're only (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Upload after merge Created 8 years, 3 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
« no previous file with comments | « chromeos/dbus/shill_service_client.h ('k') | chromeos/dbus/shill_service_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/flimflam_service_client.h" 5 #include "chromeos/dbus/shill_service_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/chromeos/chromeos_version.h" 8 #include "base/chromeos/chromeos_version.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "dbus/bus.h" 12 #include "dbus/bus.h"
13 #include "dbus/message.h" 13 #include "dbus/message.h"
14 #include "dbus/object_proxy.h" 14 #include "dbus/object_proxy.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 16
17 namespace chromeos { 17 namespace chromeos {
18 18
19 namespace { 19 namespace {
20 20
21 // Error callback for GetProperties. 21 // Error callback for GetProperties.
22 void OnGetPropertiesError( 22 void OnGetPropertiesError(
23 const dbus::ObjectPath& service_path, 23 const dbus::ObjectPath& service_path,
24 const FlimflamServiceClient::DictionaryValueCallback& callback, 24 const ShillServiceClient::DictionaryValueCallback& callback,
25 const std::string& error_name, 25 const std::string& error_name,
26 const std::string& error_message) { 26 const std::string& error_message) {
27 const std::string log_string = 27 const std::string log_string =
28 "Failed to call org.chromium.flimflam.Service.GetProperties for: " + 28 "Failed to call org.chromium.shill.Service.GetProperties for: " +
29 service_path.value() + ": " + error_name + ": " + error_message; 29 service_path.value() + ": " + error_name + ": " + error_message;
30 30
31 // Suppress ERROR log if error name is 31 // Suppress ERROR log if error name is
32 // "org.freedesktop.DBus.Error.UnknownMethod". crbug.com/130660 32 // "org.freedesktop.DBus.Error.UnknownMethod". crbug.com/130660
33 if (error_name == DBUS_ERROR_UNKNOWN_METHOD) 33 if (error_name == DBUS_ERROR_UNKNOWN_METHOD)
34 VLOG(1) << log_string; 34 VLOG(1) << log_string;
35 else 35 else
36 LOG(ERROR) << log_string; 36 LOG(ERROR) << log_string;
37 37
38 base::DictionaryValue empty_dictionary; 38 base::DictionaryValue empty_dictionary;
39 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); 39 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary);
40 } 40 }
41 41
42 // The FlimflamServiceClient implementation. 42 // The ShillServiceClient implementation.
43 class FlimflamServiceClientImpl : public FlimflamServiceClient { 43 class ShillServiceClientImpl : public ShillServiceClient {
44 public: 44 public:
45 explicit FlimflamServiceClientImpl(dbus::Bus* bus) 45 explicit ShillServiceClientImpl(dbus::Bus* bus)
46 : bus_(bus), 46 : bus_(bus),
47 helpers_deleter_(&helpers_) { 47 helpers_deleter_(&helpers_) {
48 } 48 }
49 49
50 // FlimflamServiceClient override. 50 // ShillServiceClient override.
51 virtual void SetPropertyChangedHandler( 51 virtual void SetPropertyChangedHandler(
52 const dbus::ObjectPath& service_path, 52 const dbus::ObjectPath& service_path,
53 const PropertyChangedHandler& handler) OVERRIDE { 53 const PropertyChangedHandler& handler) OVERRIDE {
54 GetHelper(service_path)->SetPropertyChangedHandler(handler); 54 GetHelper(service_path)->SetPropertyChangedHandler(handler);
55 } 55 }
56 56
57 // FlimflamServiceClient override. 57 // ShillServiceClient override.
58 virtual void ResetPropertyChangedHandler( 58 virtual void ResetPropertyChangedHandler(
59 const dbus::ObjectPath& service_path) OVERRIDE { 59 const dbus::ObjectPath& service_path) OVERRIDE {
60 GetHelper(service_path)->ResetPropertyChangedHandler(); 60 GetHelper(service_path)->ResetPropertyChangedHandler();
61 } 61 }
62 62
63 // FlimflamServiceClient override. 63 // ShillServiceClient override.
64 virtual void GetProperties(const dbus::ObjectPath& service_path, 64 virtual void GetProperties(const dbus::ObjectPath& service_path,
65 const DictionaryValueCallback& callback) OVERRIDE { 65 const DictionaryValueCallback& callback) OVERRIDE {
66 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 66 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
67 flimflam::kGetPropertiesFunction); 67 flimflam::kGetPropertiesFunction);
68 GetHelper(service_path)->CallDictionaryValueMethodWithErrorCallback( 68 GetHelper(service_path)->CallDictionaryValueMethodWithErrorCallback(
69 &method_call, 69 &method_call,
70 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS), 70 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS),
71 base::Bind(&OnGetPropertiesError, service_path, callback)); 71 base::Bind(&OnGetPropertiesError, service_path, callback));
72 } 72 }
73 73
74 // FlimflamServiceClient override. 74 // ShillServiceClient override.
75 virtual void SetProperty(const dbus::ObjectPath& service_path, 75 virtual void SetProperty(const dbus::ObjectPath& service_path,
76 const std::string& name, 76 const std::string& name,
77 const base::Value& value, 77 const base::Value& value,
78 const VoidDBusMethodCallback& callback) OVERRIDE { 78 const VoidDBusMethodCallback& callback) OVERRIDE {
79 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 79 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
80 flimflam::kSetPropertyFunction); 80 flimflam::kSetPropertyFunction);
81 dbus::MessageWriter writer(&method_call); 81 dbus::MessageWriter writer(&method_call);
82 writer.AppendString(name); 82 writer.AppendString(name);
83 FlimflamClientHelper::AppendValueDataAsVariant(&writer, value); 83 ShillClientHelper::AppendValueDataAsVariant(&writer, value);
84 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 84 GetHelper(service_path)->CallVoidMethod(&method_call, callback);
85 } 85 }
86 86
87 // FlimflamServiceClient override. 87 // ShillServiceClient override.
88 virtual void ClearProperty(const dbus::ObjectPath& service_path, 88 virtual void ClearProperty(const dbus::ObjectPath& service_path,
89 const std::string& name, 89 const std::string& name,
90 const VoidDBusMethodCallback& callback) OVERRIDE { 90 const VoidDBusMethodCallback& callback) OVERRIDE {
91 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 91 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
92 flimflam::kClearPropertyFunction); 92 flimflam::kClearPropertyFunction);
93 dbus::MessageWriter writer(&method_call); 93 dbus::MessageWriter writer(&method_call);
94 writer.AppendString(name); 94 writer.AppendString(name);
95 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 95 GetHelper(service_path)->CallVoidMethod(&method_call, callback);
96 } 96 }
97 97
98 // FlimflamServiceClient override. 98 // ShillServiceClient override.
99 virtual void Connect(const dbus::ObjectPath& service_path, 99 virtual void Connect(const dbus::ObjectPath& service_path,
100 const base::Closure& callback, 100 const base::Closure& callback,
101 const ErrorCallback& error_callback) OVERRIDE { 101 const ErrorCallback& error_callback) OVERRIDE {
102 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 102 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
103 flimflam::kConnectFunction); 103 flimflam::kConnectFunction);
104 GetHelper(service_path)->CallVoidMethodWithErrorCallback( 104 GetHelper(service_path)->CallVoidMethodWithErrorCallback(
105 &method_call, callback, error_callback); 105 &method_call, callback, error_callback);
106 } 106 }
107 107
108 // FlimflamServiceClient override. 108 // ShillServiceClient override.
109 virtual void Disconnect(const dbus::ObjectPath& service_path, 109 virtual void Disconnect(const dbus::ObjectPath& service_path,
110 const VoidDBusMethodCallback& callback) OVERRIDE { 110 const VoidDBusMethodCallback& callback) OVERRIDE {
111 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 111 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
112 flimflam::kDisconnectFunction); 112 flimflam::kDisconnectFunction);
113 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 113 GetHelper(service_path)->CallVoidMethod(&method_call, callback);
114 } 114 }
115 115
116 // FlimflamServiceClient override. 116 // ShillServiceClient override.
117 virtual void Remove(const dbus::ObjectPath& service_path, 117 virtual void Remove(const dbus::ObjectPath& service_path,
118 const VoidDBusMethodCallback& callback) OVERRIDE { 118 const VoidDBusMethodCallback& callback) OVERRIDE {
119 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 119 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
120 flimflam::kRemoveServiceFunction); 120 flimflam::kRemoveServiceFunction);
121 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 121 GetHelper(service_path)->CallVoidMethod(&method_call, callback);
122 } 122 }
123 123
124 // FlimflamServiceClient override. 124 // ShillServiceClient override.
125 virtual void ActivateCellularModem( 125 virtual void ActivateCellularModem(
126 const dbus::ObjectPath& service_path, 126 const dbus::ObjectPath& service_path,
127 const std::string& carrier, 127 const std::string& carrier,
128 const VoidDBusMethodCallback& callback) OVERRIDE { 128 const VoidDBusMethodCallback& callback) OVERRIDE {
129 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 129 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
130 flimflam::kActivateCellularModemFunction); 130 flimflam::kActivateCellularModemFunction);
131 dbus::MessageWriter writer(&method_call); 131 dbus::MessageWriter writer(&method_call);
132 writer.AppendString(carrier); 132 writer.AppendString(carrier);
133 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 133 GetHelper(service_path)->CallVoidMethod(&method_call, callback);
134 } 134 }
135 135
136 // FlimflamServiceClient override. 136 // ShillServiceClient override.
137 virtual bool CallActivateCellularModemAndBlock( 137 virtual bool CallActivateCellularModemAndBlock(
138 const dbus::ObjectPath& service_path, 138 const dbus::ObjectPath& service_path,
139 const std::string& carrier) OVERRIDE { 139 const std::string& carrier) OVERRIDE {
140 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 140 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
141 flimflam::kActivateCellularModemFunction); 141 flimflam::kActivateCellularModemFunction);
142 dbus::MessageWriter writer(&method_call); 142 dbus::MessageWriter writer(&method_call);
143 writer.AppendString(carrier); 143 writer.AppendString(carrier);
144 return GetHelper(service_path)->CallVoidMethodAndBlock(&method_call); 144 return GetHelper(service_path)->CallVoidMethodAndBlock(&method_call);
145 } 145 }
146 146
147 private: 147 private:
148 typedef std::map<std::string, FlimflamClientHelper*> HelperMap; 148 typedef std::map<std::string, ShillClientHelper*> HelperMap;
149 149
150 // Returns the corresponding FlimflamClientHelper for the profile. 150 // Returns the corresponding ShillClientHelper for the profile.
151 FlimflamClientHelper* GetHelper(const dbus::ObjectPath& service_path) { 151 ShillClientHelper* GetHelper(const dbus::ObjectPath& service_path) {
152 HelperMap::iterator it = helpers_.find(service_path.value()); 152 HelperMap::iterator it = helpers_.find(service_path.value());
153 if (it != helpers_.end()) 153 if (it != helpers_.end())
154 return it->second; 154 return it->second;
155 155
156 // There is no helper for the profile, create it. 156 // There is no helper for the profile, create it.
157 dbus::ObjectProxy* object_proxy = 157 dbus::ObjectProxy* object_proxy =
158 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, service_path); 158 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, service_path);
159 FlimflamClientHelper* helper = new FlimflamClientHelper(bus_, object_proxy); 159 ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy);
160 helper->MonitorPropertyChanged(flimflam::kFlimflamServiceInterface); 160 helper->MonitorPropertyChanged(flimflam::kFlimflamServiceInterface);
161 helpers_.insert(HelperMap::value_type(service_path.value(), helper)); 161 helpers_.insert(HelperMap::value_type(service_path.value(), helper));
162 return helper; 162 return helper;
163 } 163 }
164 164
165 dbus::Bus* bus_; 165 dbus::Bus* bus_;
166 HelperMap helpers_; 166 HelperMap helpers_;
167 STLValueDeleter<HelperMap> helpers_deleter_; 167 STLValueDeleter<HelperMap> helpers_deleter_;
168 168
169 DISALLOW_COPY_AND_ASSIGN(FlimflamServiceClientImpl); 169 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl);
170 }; 170 };
171 171
172 // A stub implementation of FlimflamServiceClient. 172 // A stub implementation of ShillServiceClient.
173 class FlimflamServiceClientStubImpl : public FlimflamServiceClient { 173 class ShillServiceClientStubImpl : public ShillServiceClient {
174 public: 174 public:
175 FlimflamServiceClientStubImpl() : weak_ptr_factory_(this) {} 175 ShillServiceClientStubImpl() : weak_ptr_factory_(this) {}
176 176
177 virtual ~FlimflamServiceClientStubImpl() {} 177 virtual ~ShillServiceClientStubImpl() {}
178 178
179 // FlimflamServiceClient override. 179 // ShillServiceClient override.
180 virtual void SetPropertyChangedHandler( 180 virtual void SetPropertyChangedHandler(
181 const dbus::ObjectPath& service_path, 181 const dbus::ObjectPath& service_path,
182 const PropertyChangedHandler& handler) OVERRIDE {} 182 const PropertyChangedHandler& handler) OVERRIDE {}
183 183
184 // FlimflamServiceClient override. 184 // ShillServiceClient override.
185 virtual void ResetPropertyChangedHandler( 185 virtual void ResetPropertyChangedHandler(
186 const dbus::ObjectPath& service_path) OVERRIDE {} 186 const dbus::ObjectPath& service_path) OVERRIDE {}
187 187
188 // FlimflamServiceClient override. 188 // ShillServiceClient override.
189 virtual void GetProperties(const dbus::ObjectPath& service_path, 189 virtual void GetProperties(const dbus::ObjectPath& service_path,
190 const DictionaryValueCallback& callback) OVERRIDE { 190 const DictionaryValueCallback& callback) OVERRIDE {
191 MessageLoop::current()->PostTask( 191 MessageLoop::current()->PostTask(
192 FROM_HERE, 192 FROM_HERE,
193 base::Bind(&FlimflamServiceClientStubImpl::PassEmptyDictionaryValue, 193 base::Bind(&ShillServiceClientStubImpl::PassEmptyDictionaryValue,
194 weak_ptr_factory_.GetWeakPtr(), 194 weak_ptr_factory_.GetWeakPtr(),
195 callback)); 195 callback));
196 } 196 }
197 197
198 // FlimflamServiceClient override. 198 // ShillServiceClient override.
199 virtual void SetProperty(const dbus::ObjectPath& service_path, 199 virtual void SetProperty(const dbus::ObjectPath& service_path,
200 const std::string& name, 200 const std::string& name,
201 const base::Value& value, 201 const base::Value& value,
202 const VoidDBusMethodCallback& callback) OVERRIDE { 202 const VoidDBusMethodCallback& callback) OVERRIDE {
203 PostSuccessVoidCallback(callback); 203 PostSuccessVoidCallback(callback);
204 } 204 }
205 205
206 // FlimflamServiceClient override. 206 // ShillServiceClient override.
207 virtual void ClearProperty(const dbus::ObjectPath& service_path, 207 virtual void ClearProperty(const dbus::ObjectPath& service_path,
208 const std::string& name, 208 const std::string& name,
209 const VoidDBusMethodCallback& callback) OVERRIDE { 209 const VoidDBusMethodCallback& callback) OVERRIDE {
210 PostSuccessVoidCallback(callback); 210 PostSuccessVoidCallback(callback);
211 } 211 }
212 212
213 // FlimflamServiceClient override. 213 // ShillServiceClient override.
214 virtual void Connect(const dbus::ObjectPath& service_path, 214 virtual void Connect(const dbus::ObjectPath& service_path,
215 const base::Closure& callback, 215 const base::Closure& callback,
216 const ErrorCallback& error_callback) OVERRIDE { 216 const ErrorCallback& error_callback) OVERRIDE {
217 MessageLoop::current()->PostTask(FROM_HERE, callback); 217 MessageLoop::current()->PostTask(FROM_HERE, callback);
218 } 218 }
219 219
220 // FlimflamServiceClient override. 220 // ShillServiceClient override.
221 virtual void Disconnect(const dbus::ObjectPath& service_path, 221 virtual void Disconnect(const dbus::ObjectPath& service_path,
222 const VoidDBusMethodCallback& callback) OVERRIDE { 222 const VoidDBusMethodCallback& callback) OVERRIDE {
223 PostSuccessVoidCallback(callback); 223 PostSuccessVoidCallback(callback);
224 } 224 }
225 225
226 // FlimflamServiceClient override. 226 // ShillServiceClient override.
227 virtual void Remove(const dbus::ObjectPath& service_path, 227 virtual void Remove(const dbus::ObjectPath& service_path,
228 const VoidDBusMethodCallback& callback) OVERRIDE { 228 const VoidDBusMethodCallback& callback) OVERRIDE {
229 PostSuccessVoidCallback(callback); 229 PostSuccessVoidCallback(callback);
230 } 230 }
231 231
232 // FlimflamServiceClient override. 232 // ShillServiceClient override.
233 virtual void ActivateCellularModem( 233 virtual void ActivateCellularModem(
234 const dbus::ObjectPath& service_path, 234 const dbus::ObjectPath& service_path,
235 const std::string& carrier, 235 const std::string& carrier,
236 const VoidDBusMethodCallback& callback) OVERRIDE { 236 const VoidDBusMethodCallback& callback) OVERRIDE {
237 PostSuccessVoidCallback(callback); 237 PostSuccessVoidCallback(callback);
238 } 238 }
239 239
240 // FlimflamServiceClient override. 240 // ShillServiceClient override.
241 virtual bool CallActivateCellularModemAndBlock( 241 virtual bool CallActivateCellularModemAndBlock(
242 const dbus::ObjectPath& service_path, 242 const dbus::ObjectPath& service_path,
243 const std::string& carrier) OVERRIDE { 243 const std::string& carrier) OVERRIDE {
244 return true; 244 return true;
245 } 245 }
246 246
247 private: 247 private:
248 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { 248 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const {
249 base::DictionaryValue dictionary; 249 base::DictionaryValue dictionary;
250 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); 250 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary);
251 } 251 }
252 252
253 // Posts a task to run a void callback with success status code. 253 // Posts a task to run a void callback with success status code.
254 void PostSuccessVoidCallback(const VoidDBusMethodCallback& callback) { 254 void PostSuccessVoidCallback(const VoidDBusMethodCallback& callback) {
255 MessageLoop::current()->PostTask(FROM_HERE, 255 MessageLoop::current()->PostTask(FROM_HERE,
256 base::Bind(callback, 256 base::Bind(callback,
257 DBUS_METHOD_CALL_SUCCESS)); 257 DBUS_METHOD_CALL_SUCCESS));
258 } 258 }
259 259
260 // Note: This should remain the last member so it'll be destroyed and 260 // Note: This should remain the last member so it'll be destroyed and
261 // invalidate its weak pointers before any other members are destroyed. 261 // invalidate its weak pointers before any other members are destroyed.
262 base::WeakPtrFactory<FlimflamServiceClientStubImpl> weak_ptr_factory_; 262 base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_;
263 263
264 DISALLOW_COPY_AND_ASSIGN(FlimflamServiceClientStubImpl); 264 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStubImpl);
265 }; 265 };
266 266
267 } // namespace 267 } // namespace
268 268
269 FlimflamServiceClient::FlimflamServiceClient() {} 269 ShillServiceClient::ShillServiceClient() {}
270 270
271 FlimflamServiceClient::~FlimflamServiceClient() {} 271 ShillServiceClient::~ShillServiceClient() {}
272 272
273 // static 273 // static
274 FlimflamServiceClient* FlimflamServiceClient::Create( 274 ShillServiceClient* ShillServiceClient::Create(
275 DBusClientImplementationType type, 275 DBusClientImplementationType type,
276 dbus::Bus* bus) { 276 dbus::Bus* bus) {
277 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 277 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
278 return new FlimflamServiceClientImpl(bus); 278 return new ShillServiceClientImpl(bus);
279 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 279 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
280 return new FlimflamServiceClientStubImpl(); 280 return new ShillServiceClientStubImpl();
281 } 281 }
282 282
283 } // namespace chromeos 283 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/shill_service_client.h ('k') | chromeos/dbus/shill_service_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698