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

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

Issue 12319145: Using the new Network*Handlers in networkingPrivate Extension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Steven's comments. Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/shill_service_client_stub.h" 5 #include "chromeos/dbus/shill_service_client_stub.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path, 73 void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path,
74 const std::string& name, 74 const std::string& name,
75 const base::Value& value, 75 const base::Value& value,
76 const base::Closure& callback, 76 const base::Closure& callback,
77 const ErrorCallback& error_callback) { 77 const ErrorCallback& error_callback) {
78 base::DictionaryValue* dict = NULL; 78 base::DictionaryValue* dict = NULL;
79 if (!stub_services_.GetDictionaryWithoutPathExpansion( 79 if (!stub_services_.GetDictionaryWithoutPathExpansion(
80 service_path.value(), &dict)) { 80 service_path.value(), &dict)) {
81 error_callback.Run("StubError", "Service not found"); 81 error_callback.Run("Error.InvalidService", "Invalid Service");
82 return; 82 return;
83 } 83 }
84 if (name == flimflam::kStateProperty) { 84 if (name == flimflam::kStateProperty) {
85 // If we connect to a service, then we move it to the top of the list in 85 // If we connect to a service, then we move it to the top of the list in
86 // the manager client. 86 // the manager client.
87 std::string state; 87 std::string state;
88 if (value.GetAsString(&state) && state == flimflam::kStateOnline) { 88 if (value.GetAsString(&state) && state == flimflam::kStateOnline) {
89 ShillManagerClient* manager_client = 89 ShillManagerClient* manager_client =
90 DBusThreadManager::Get()->GetShillManagerClient(); 90 DBusThreadManager::Get()->GetShillManagerClient();
91 manager_client->GetTestInterface()->RemoveService(service_path.value()); 91 manager_client->GetTestInterface()->RemoveService(service_path.value());
(...skipping 12 matching lines...) Expand all
104 } 104 }
105 105
106 void ShillServiceClientStub::ClearProperty( 106 void ShillServiceClientStub::ClearProperty(
107 const dbus::ObjectPath& service_path, 107 const dbus::ObjectPath& service_path,
108 const std::string& name, 108 const std::string& name,
109 const base::Closure& callback, 109 const base::Closure& callback,
110 const ErrorCallback& error_callback) { 110 const ErrorCallback& error_callback) {
111 base::DictionaryValue* dict = NULL; 111 base::DictionaryValue* dict = NULL;
112 if (!stub_services_.GetDictionaryWithoutPathExpansion( 112 if (!stub_services_.GetDictionaryWithoutPathExpansion(
113 service_path.value(), &dict)) { 113 service_path.value(), &dict)) {
114 error_callback.Run("StubError", "Service not found"); 114 error_callback.Run("Error.InvalidService", "Invalid Service");
115 return; 115 return;
116 } 116 }
117 dict->Remove(name, NULL); 117 dict->Remove(name, NULL);
118 MessageLoop::current()->PostTask( 118 MessageLoop::current()->PostTask(
119 FROM_HERE, 119 FROM_HERE,
120 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, 120 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged,
121 weak_ptr_factory_.GetWeakPtr(), service_path, name)); 121 weak_ptr_factory_.GetWeakPtr(), service_path, name));
122 if (callback.is_null()) 122 if (callback.is_null())
123 return; 123 return;
124 MessageLoop::current()->PostTask(FROM_HERE, callback); 124 MessageLoop::current()->PostTask(FROM_HERE, callback);
125 } 125 }
126 126
127 void ShillServiceClientStub::ClearProperties( 127 void ShillServiceClientStub::ClearProperties(
128 const dbus::ObjectPath& service_path, 128 const dbus::ObjectPath& service_path,
129 const std::vector<std::string>& names, 129 const std::vector<std::string>& names,
130 const ListValueCallback& callback, 130 const ListValueCallback& callback,
131 const ErrorCallback& error_callback) { 131 const ErrorCallback& error_callback) {
132 base::DictionaryValue* dict = NULL; 132 base::DictionaryValue* dict = NULL;
133 if (!stub_services_.GetDictionaryWithoutPathExpansion( 133 if (!stub_services_.GetDictionaryWithoutPathExpansion(
134 service_path.value(), &dict)) { 134 service_path.value(), &dict)) {
135 error_callback.Run("StubError", "Service not found"); 135 error_callback.Run("Error.InvalidService", "Invalid Service");
136 return; 136 return;
137 } 137 }
138 scoped_ptr<base::ListValue> results(new base::ListValue); 138 scoped_ptr<base::ListValue> results(new base::ListValue);
139 for (std::vector<std::string>::const_iterator iter = names.begin(); 139 for (std::vector<std::string>::const_iterator iter = names.begin();
140 iter != names.end(); ++iter) { 140 iter != names.end(); ++iter) {
141 dict->Remove(*iter, NULL); 141 dict->Remove(*iter, NULL);
142 results->AppendBoolean(true); 142 results->AppendBoolean(true);
143 } 143 }
144 for (std::vector<std::string>::const_iterator iter = names.begin(); 144 for (std::vector<std::string>::const_iterator iter = names.begin();
145 iter != names.end(); ++iter) { 145 iter != names.end(); ++iter) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 online_value, 182 online_value,
183 base::Bind(&base::DoNothing), 183 base::Bind(&base::DoNothing),
184 error_callback), 184 error_callback),
185 base::TimeDelta::FromSeconds(kConnectDelaySeconds)); 185 base::TimeDelta::FromSeconds(kConnectDelaySeconds));
186 callback.Run(); 186 callback.Run();
187 } 187 }
188 188
189 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, 189 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path,
190 const base::Closure& callback, 190 const base::Closure& callback,
191 const ErrorCallback& error_callback) { 191 const ErrorCallback& error_callback) {
192 base::Value* service;
193 if (!stub_services_.Get(service_path.value(), &service)) {
194 error_callback.Run("Error.InvalidService", "Invalid Service");
195 return;
196 }
192 // Set Idle after a delay 197 // Set Idle after a delay
193 const int kConnectDelaySeconds = 2; 198 const int kConnectDelaySeconds = 2;
194 base::StringValue idle_value(flimflam::kStateIdle); 199 base::StringValue idle_value(flimflam::kStateIdle);
195 MessageLoop::current()->PostDelayedTask( 200 MessageLoop::current()->PostDelayedTask(
196 FROM_HERE, 201 FROM_HERE,
197 base::Bind(&ShillServiceClientStub::SetProperty, 202 base::Bind(&ShillServiceClientStub::SetProperty,
198 weak_ptr_factory_.GetWeakPtr(), 203 weak_ptr_factory_.GetWeakPtr(),
199 service_path, 204 service_path,
200 flimflam::kStateProperty, 205 flimflam::kStateProperty,
201 idle_value, 206 idle_value,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 AddService("stub_ethernet", "eth0", 307 AddService("stub_ethernet", "eth0",
303 flimflam::kTypeEthernet, 308 flimflam::kTypeEthernet,
304 flimflam::kStateOnline, 309 flimflam::kStateOnline,
305 add_to_watchlist); 310 add_to_watchlist);
306 } 311 }
307 312
308 AddService("stub_wifi1", "wifi1", 313 AddService("stub_wifi1", "wifi1",
309 flimflam::kTypeWifi, 314 flimflam::kTypeWifi,
310 flimflam::kStateOnline, 315 flimflam::kStateOnline,
311 add_to_watchlist); 316 add_to_watchlist);
317 SetServiceProperty("stub_wifi1",
318 flimflam::kSecurityProperty,
319 base::StringValue(flimflam::kSecurityWep));
312 320
313 AddService("stub_wifi2", "wifi2_PSK", 321 AddService("stub_wifi2", "wifi2_PSK",
314 flimflam::kTypeWifi, 322 flimflam::kTypeWifi,
315 flimflam::kStateIdle, 323 flimflam::kStateIdle,
316 add_to_watchlist); 324 add_to_watchlist);
317 base::StringValue psk_value(flimflam::kSecurityPsk);
318 SetServiceProperty("stub_wifi2", 325 SetServiceProperty("stub_wifi2",
319 flimflam::kSecurityProperty, 326 flimflam::kSecurityProperty,
320 psk_value); 327 base::StringValue(flimflam::kSecurityPsk));
321 base::FundamentalValue strength_value(80); 328 base::FundamentalValue strength_value(80);
322 SetServiceProperty("stub_wifi2", 329 SetServiceProperty("stub_wifi2",
323 flimflam::kSignalStrengthProperty, 330 flimflam::kSignalStrengthProperty,
324 strength_value); 331 strength_value);
325 332
326 AddService("stub_cellular1", "cellular1", 333 AddService("stub_cellular1", "cellular1",
327 flimflam::kTypeCellular, 334 flimflam::kTypeCellular,
328 flimflam::kStateIdle, 335 flimflam::kStateIdle,
329 add_to_watchlist); 336 add_to_watchlist);
330 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); 337 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm);
331 SetServiceProperty("stub_cellular1", 338 SetServiceProperty("stub_cellular1",
332 flimflam::kNetworkTechnologyProperty, 339 flimflam::kNetworkTechnologyProperty,
333 technology_value); 340 technology_value);
334 base::StringValue activation_value(flimflam::kActivationStateActivated);
335 SetServiceProperty("stub_cellular1", 341 SetServiceProperty("stub_cellular1",
336 flimflam::kActivationStateProperty, 342 flimflam::kActivationStateProperty,
337 activation_value); 343 base::StringValue(flimflam::kActivationStateNotActivated));
344 SetServiceProperty("stub_cellular1",
345 flimflam::kRoamingStateProperty,
346 base::StringValue(flimflam::kRoamingStateHome));
stevenjb 2013/03/05 17:59:18 These changes are fine, but don't rely on them for
pneubeck (no reviews) 2013/03/07 15:53:02 Done after that CL was committed.
338 } 347 }
339 348
340 void ShillServiceClientStub::PassStubServiceProperties( 349 void ShillServiceClientStub::PassStubServiceProperties(
341 const dbus::ObjectPath& service_path, 350 const dbus::ObjectPath& service_path,
342 const DictionaryValueCallback& callback) { 351 const DictionaryValueCallback& callback) {
343 base::DictionaryValue* dict = NULL; 352 base::DictionaryValue* dict = NULL;
344 if (!stub_services_.GetDictionaryWithoutPathExpansion( 353 if (!stub_services_.GetDictionaryWithoutPathExpansion(
345 service_path.value(), &dict)) { 354 service_path.value(), &dict)) {
346 base::DictionaryValue empty_dictionary; 355 base::DictionaryValue empty_dictionary;
347 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); 356 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = 395 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter =
387 observer_list_.find(device_path); 396 observer_list_.find(device_path);
388 if (iter != observer_list_.end()) 397 if (iter != observer_list_.end())
389 return *(iter->second); 398 return *(iter->second);
390 PropertyObserverList* observer_list = new PropertyObserverList(); 399 PropertyObserverList* observer_list = new PropertyObserverList();
391 observer_list_[device_path] = observer_list; 400 observer_list_[device_path] = observer_list;
392 return *observer_list; 401 return *observer_list;
393 } 402 }
394 403
395 } // namespace chromeos 404 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698