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

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

Issue 181413006: Replace misc. network stub flags with more flexible ones (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Elim. shill_stub_helper and move functions to clients. Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/fake_shill_manager_client.h" 5 #include "chromeos/dbus/fake_shill_manager_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "chromeos/chromeos_switches.h" 13 #include "chromeos/chromeos_switches.h"
14 #include "chromeos/dbus/dbus_command_line_helper.h"
12 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/shill_device_client.h" 16 #include "chromeos/dbus/shill_device_client.h"
14 #include "chromeos/dbus/shill_profile_client.h" 17 #include "chromeos/dbus/shill_profile_client.h"
15 #include "chromeos/dbus/shill_property_changed_observer.h" 18 #include "chromeos/dbus/shill_property_changed_observer.h"
16 #include "chromeos/dbus/shill_service_client.h" 19 #include "chromeos/dbus/shill_service_client.h"
17 #include "dbus/bus.h" 20 #include "dbus/bus.h"
18 #include "dbus/message.h" 21 #include "dbus/message.h"
19 #include "dbus/object_path.h" 22 #include "dbus/object_path.h"
20 #include "dbus/values_util.h" 23 #include "dbus/values_util.h"
21 #include "third_party/cros_system_api/dbus/service_constants.h" 24 #include "third_party/cros_system_api/dbus/service_constants.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 state == shill::kStateConfiguration || 69 state == shill::kStateConfiguration ||
67 state == shill::kStatePortal || 70 state == shill::kStatePortal ||
68 state == shill::kStateReady) { 71 state == shill::kStateReady) {
69 active_service_list_out->push_back(service_path); 72 active_service_list_out->push_back(service_path);
70 } else { 73 } else {
71 inactive_service_list_out->push_back(service_path); 74 inactive_service_list_out->push_back(service_path);
72 } 75 }
73 } 76 }
74 } 77 }
75 78
79 void UpdatePortalledWifiState(const std::string& service_path) {
80 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface()
81 ->SetServiceProperty(service_path,
82 shill::kStateProperty,
83 base::StringValue(shill::kStatePortal));
84 }
85
76 } // namespace 86 } // namespace
77 87
78 FakeShillManagerClient::FakeShillManagerClient() 88 FakeShillManagerClient::FakeShillManagerClient()
79 : weak_ptr_factory_(this) { 89 : interactive_delay_(0),
90 weak_ptr_factory_(this) {
91 ParseCommandLineSwitch();
80 } 92 }
81 93
82 FakeShillManagerClient::~FakeShillManagerClient() {} 94 FakeShillManagerClient::~FakeShillManagerClient() {}
83 95
84 // ShillManagerClient overrides. 96 // ShillManagerClient overrides.
85 97
86 void FakeShillManagerClient::Init(dbus::Bus* bus) {} 98 void FakeShillManagerClient::Init(dbus::Bus* bus) {
99 // Note: This will occur *before* Init() is called on Service/Device/Profile
100 // clients.
101 SetupDefaultEnvironment();
pneubeck (no reviews) 2014/02/28 09:37:59 IIRC, the idea at some time was that this DefaultE
stevenjb 2014/02/28 17:43:06 Anything that calls InitializeWithStub is going to
102 }
87 103
88 void FakeShillManagerClient::AddPropertyChangedObserver( 104 void FakeShillManagerClient::AddPropertyChangedObserver(
89 ShillPropertyChangedObserver* observer) { 105 ShillPropertyChangedObserver* observer) {
90 observer_list_.AddObserver(observer); 106 observer_list_.AddObserver(observer);
91 } 107 }
92 108
93 void FakeShillManagerClient::RemovePropertyChangedObserver( 109 void FakeShillManagerClient::RemovePropertyChangedObserver(
94 ShillPropertyChangedObserver* observer) { 110 ShillPropertyChangedObserver* observer) {
95 observer_list_.RemoveObserver(observer); 111 observer_list_.RemoveObserver(observer);
96 } 112 }
(...skipping 14 matching lines...) Expand all
111 &FakeShillManagerClient::PassStubGeoNetworks, 127 &FakeShillManagerClient::PassStubGeoNetworks,
112 weak_ptr_factory_.GetWeakPtr(), 128 weak_ptr_factory_.GetWeakPtr(),
113 callback)); 129 callback));
114 } 130 }
115 131
116 void FakeShillManagerClient::SetProperty(const std::string& name, 132 void FakeShillManagerClient::SetProperty(const std::string& name,
117 const base::Value& value, 133 const base::Value& value,
118 const base::Closure& callback, 134 const base::Closure& callback,
119 const ErrorCallback& error_callback) { 135 const ErrorCallback& error_callback) {
120 stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); 136 stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy());
121 CallNotifyObserversPropertyChanged(name, 0); 137 CallNotifyObserversPropertyChanged(name);
122 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 138 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
123 } 139 }
124 140
125 void FakeShillManagerClient::RequestScan(const std::string& type, 141 void FakeShillManagerClient::RequestScan(const std::string& type,
126 const base::Closure& callback, 142 const base::Closure& callback,
127 const ErrorCallback& error_callback) { 143 const ErrorCallback& error_callback) {
128 // For Stub purposes, default to a Wifi scan. 144 // For Stub purposes, default to a Wifi scan.
129 std::string device_type = shill::kTypeWifi; 145 std::string device_type = shill::kTypeWifi;
130 if (!type.empty()) 146 if (!type.empty())
131 device_type = type; 147 device_type = type;
132 ShillDeviceClient::TestInterface* device_client = 148 ShillDeviceClient::TestInterface* device_client =
133 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); 149 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
134 std::string device_path = device_client->GetDevicePathForType(device_type); 150 std::string device_path = device_client->GetDevicePathForType(device_type);
135 if (!device_path.empty()) { 151 if (!device_path.empty()) {
136 device_client->SetDeviceProperty(device_path, 152 device_client->SetDeviceProperty(
137 shill::kScanningProperty, 153 device_path, shill::kScanningProperty, base::FundamentalValue(true));
138 base::FundamentalValue(true));
139 }
140 const int kScanDurationSeconds = 3;
141 int scan_duration_seconds = kScanDurationSeconds;
142 if (!CommandLine::ForCurrentProcess()->HasSwitch(
143 chromeos::switches::kEnableStubInteractive)) {
144 scan_duration_seconds = 0;
145 } 154 }
146 base::MessageLoop::current()->PostDelayedTask( 155 base::MessageLoop::current()->PostDelayedTask(
147 FROM_HERE, 156 FROM_HERE,
148 base::Bind(&FakeShillManagerClient::ScanCompleted, 157 base::Bind(&FakeShillManagerClient::ScanCompleted,
149 weak_ptr_factory_.GetWeakPtr(), device_path, callback), 158 weak_ptr_factory_.GetWeakPtr(),
150 base::TimeDelta::FromSeconds(scan_duration_seconds)); 159 device_path,
160 callback),
161 base::TimeDelta::FromSeconds(interactive_delay_));
151 } 162 }
152 163
153 void FakeShillManagerClient::EnableTechnology( 164 void FakeShillManagerClient::EnableTechnology(
154 const std::string& type, 165 const std::string& type,
155 const base::Closure& callback, 166 const base::Closure& callback,
156 const ErrorCallback& error_callback) { 167 const ErrorCallback& error_callback) {
157 base::ListValue* enabled_list = NULL; 168 base::ListValue* enabled_list = NULL;
158 if (!stub_properties_.GetListWithoutPathExpansion( 169 if (!stub_properties_.GetListWithoutPathExpansion(
159 shill::kEnabledTechnologiesProperty, &enabled_list)) { 170 shill::kEnabledTechnologiesProperty, &enabled_list)) {
160 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 171 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
161 base::MessageLoop::current()->PostTask( 172 base::MessageLoop::current()->PostTask(
162 FROM_HERE, 173 FROM_HERE,
163 base::Bind(error_callback, "StubError", "Property not found")); 174 base::Bind(error_callback, "StubError", "Property not found"));
164 return; 175 return;
165 } 176 }
166 if (CommandLine::ForCurrentProcess()->HasSwitch( 177 if (interactive_delay_) {
167 chromeos::switches::kEnableStubInteractive)) {
168 const int kEnableTechnologyDelaySeconds = 3;
169 base::MessageLoop::current()->PostDelayedTask( 178 base::MessageLoop::current()->PostDelayedTask(
170 FROM_HERE, 179 FROM_HERE,
171 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, 180 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled,
172 weak_ptr_factory_.GetWeakPtr(), type, callback, true), 181 weak_ptr_factory_.GetWeakPtr(),
173 base::TimeDelta::FromSeconds(kEnableTechnologyDelaySeconds)); 182 type,
183 callback,
184 true),
185 base::TimeDelta::FromSeconds(interactive_delay_));
174 } else { 186 } else {
175 SetTechnologyEnabled(type, callback, true); 187 SetTechnologyEnabled(type, callback, true);
176 } 188 }
177 } 189 }
178 190
179 void FakeShillManagerClient::DisableTechnology( 191 void FakeShillManagerClient::DisableTechnology(
180 const std::string& type, 192 const std::string& type,
181 const base::Closure& callback, 193 const base::Closure& callback,
182 const ErrorCallback& error_callback) { 194 const ErrorCallback& error_callback) {
183 base::ListValue* enabled_list = NULL; 195 base::ListValue* enabled_list = NULL;
184 if (!stub_properties_.GetListWithoutPathExpansion( 196 if (!stub_properties_.GetListWithoutPathExpansion(
185 shill::kEnabledTechnologiesProperty, &enabled_list)) { 197 shill::kEnabledTechnologiesProperty, &enabled_list)) {
186 base::MessageLoop::current()->PostTask( 198 base::MessageLoop::current()->PostTask(
187 FROM_HERE, 199 FROM_HERE,
188 base::Bind(error_callback, "StubError", "Property not found")); 200 base::Bind(error_callback, "StubError", "Property not found"));
189 return; 201 return;
190 } 202 }
191 if (CommandLine::ForCurrentProcess()->HasSwitch( 203 if (interactive_delay_) {
192 chromeos::switches::kEnableStubInteractive)) {
193 const int kDisableTechnologyDelaySeconds = 3;
194 base::MessageLoop::current()->PostDelayedTask( 204 base::MessageLoop::current()->PostDelayedTask(
195 FROM_HERE, 205 FROM_HERE,
196 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, 206 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled,
197 weak_ptr_factory_.GetWeakPtr(), type, callback, false), 207 weak_ptr_factory_.GetWeakPtr(),
198 base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); 208 type,
209 callback,
210 false),
211 base::TimeDelta::FromSeconds(interactive_delay_));
199 } else { 212 } else {
200 SetTechnologyEnabled(type, callback, false); 213 SetTechnologyEnabled(type, callback, false);
201 } 214 }
202 } 215 }
203 216
204 void FakeShillManagerClient::ConfigureService( 217 void FakeShillManagerClient::ConfigureService(
205 const base::DictionaryValue& properties, 218 const base::DictionaryValue& properties,
206 const ObjectPathCallback& callback, 219 const ObjectPathCallback& callback,
207 const ErrorCallback& error_callback) { 220 const ErrorCallback& error_callback) {
208 ShillServiceClient::TestInterface* service_client = 221 ShillServiceClient::TestInterface* service_client =
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 const ErrorCallback& error_callback) { 312 const ErrorCallback& error_callback) {
300 base::MessageLoop::current()->PostTask( 313 base::MessageLoop::current()->PostTask(
301 FROM_HERE, base::Bind(callback, "encrypted_credentials")); 314 FROM_HERE, base::Bind(callback, "encrypted_credentials"));
302 } 315 }
303 316
304 void FakeShillManagerClient::VerifyAndEncryptData( 317 void FakeShillManagerClient::VerifyAndEncryptData(
305 const VerificationProperties& properties, 318 const VerificationProperties& properties,
306 const std::string& data, 319 const std::string& data,
307 const StringCallback& callback, 320 const StringCallback& callback,
308 const ErrorCallback& error_callback) { 321 const ErrorCallback& error_callback) {
309 base::MessageLoop::current()->PostTask(FROM_HERE, 322 base::MessageLoop::current()->PostTask(
310 base::Bind(callback, "encrypted_data")); 323 FROM_HERE, base::Bind(callback, "encrypted_data"));
311 } 324 }
312 325
313 void FakeShillManagerClient::ConnectToBestServices( 326 void FakeShillManagerClient::ConnectToBestServices(
314 const base::Closure& callback, 327 const base::Closure& callback,
315 const ErrorCallback& error_callback) { 328 const ErrorCallback& error_callback) {
316 } 329 }
317 330
318 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { 331 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() {
319 return this; 332 return this;
320 } 333 }
321 334
322 // ShillManagerClient::TestInterface overrides. 335 // ShillManagerClient::TestInterface overrides.
323 336
324 void FakeShillManagerClient::AddDevice(const std::string& device_path) { 337 void FakeShillManagerClient::AddDevice(const std::string& device_path) {
325 if (GetListProperty(shill::kDevicesProperty)->AppendIfNotPresent( 338 if (GetListProperty(shill::kDevicesProperty)
326 base::Value::CreateStringValue(device_path))) { 339 ->AppendIfNotPresent(base::Value::CreateStringValue(device_path))) {
327 CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); 340 CallNotifyObserversPropertyChanged(shill::kDevicesProperty);
328 } 341 }
329 } 342 }
330 343
331 void FakeShillManagerClient::RemoveDevice(const std::string& device_path) { 344 void FakeShillManagerClient::RemoveDevice(const std::string& device_path) {
332 base::StringValue device_path_value(device_path); 345 base::StringValue device_path_value(device_path);
333 if (GetListProperty(shill::kDevicesProperty)->Remove( 346 if (GetListProperty(shill::kDevicesProperty)
334 device_path_value, NULL)) { 347 ->Remove(device_path_value, NULL)) {
335 CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); 348 CallNotifyObserversPropertyChanged(shill::kDevicesProperty);
336 } 349 }
337 } 350 }
338 351
339 void FakeShillManagerClient::ClearDevices() { 352 void FakeShillManagerClient::ClearDevices() {
340 GetListProperty(shill::kDevicesProperty)->Clear(); 353 GetListProperty(shill::kDevicesProperty)->Clear();
341 CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); 354 CallNotifyObserversPropertyChanged(shill::kDevicesProperty);
342 } 355 }
343 356
344 void FakeShillManagerClient::AddTechnology(const std::string& type, 357 void FakeShillManagerClient::AddTechnology(const std::string& type,
345 bool enabled) { 358 bool enabled) {
346 if (GetListProperty(shill::kAvailableTechnologiesProperty)-> 359 if (GetListProperty(shill::kAvailableTechnologiesProperty)
347 AppendIfNotPresent(base::Value::CreateStringValue(type))) { 360 ->AppendIfNotPresent(base::Value::CreateStringValue(type))) {
348 CallNotifyObserversPropertyChanged( 361 CallNotifyObserversPropertyChanged(shill::kAvailableTechnologiesProperty);
349 shill::kAvailableTechnologiesProperty, 0);
350 } 362 }
351 if (enabled && 363 if (enabled &&
352 GetListProperty(shill::kEnabledTechnologiesProperty)-> 364 GetListProperty(shill::kEnabledTechnologiesProperty)
353 AppendIfNotPresent(base::Value::CreateStringValue(type))) { 365 ->AppendIfNotPresent(base::Value::CreateStringValue(type))) {
354 CallNotifyObserversPropertyChanged( 366 CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty);
355 shill::kEnabledTechnologiesProperty, 0);
356 } 367 }
357 } 368 }
358 369
359 void FakeShillManagerClient::RemoveTechnology(const std::string& type) { 370 void FakeShillManagerClient::RemoveTechnology(const std::string& type) {
360 base::StringValue type_value(type); 371 base::StringValue type_value(type);
361 if (GetListProperty(shill::kAvailableTechnologiesProperty)->Remove( 372 if (GetListProperty(shill::kAvailableTechnologiesProperty)
362 type_value, NULL)) { 373 ->Remove(type_value, NULL)) {
363 CallNotifyObserversPropertyChanged( 374 CallNotifyObserversPropertyChanged(shill::kAvailableTechnologiesProperty);
364 shill::kAvailableTechnologiesProperty, 0);
365 } 375 }
366 if (GetListProperty(shill::kEnabledTechnologiesProperty)->Remove( 376 if (GetListProperty(shill::kEnabledTechnologiesProperty)
367 type_value, NULL)) { 377 ->Remove(type_value, NULL)) {
368 CallNotifyObserversPropertyChanged( 378 CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty);
369 shill::kEnabledTechnologiesProperty, 0);
370 } 379 }
371 } 380 }
372 381
373 void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type, 382 void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type,
374 bool initializing) { 383 bool initializing) {
375 if (initializing) { 384 if (initializing) {
376 if (GetListProperty(shill::kUninitializedTechnologiesProperty)-> 385 if (GetListProperty(shill::kUninitializedTechnologiesProperty)
377 AppendIfNotPresent(base::Value::CreateStringValue(type))) { 386 ->AppendIfNotPresent(base::Value::CreateStringValue(type))) {
378 CallNotifyObserversPropertyChanged( 387 CallNotifyObserversPropertyChanged(
379 shill::kUninitializedTechnologiesProperty, 0); 388 shill::kUninitializedTechnologiesProperty);
380 } 389 }
381 } else { 390 } else {
382 if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove( 391 if (GetListProperty(shill::kUninitializedTechnologiesProperty)
383 base::StringValue(type), NULL)) { 392 ->Remove(base::StringValue(type), NULL)) {
384 CallNotifyObserversPropertyChanged( 393 CallNotifyObserversPropertyChanged(
385 shill::kUninitializedTechnologiesProperty, 0); 394 shill::kUninitializedTechnologiesProperty);
386 } 395 }
387 } 396 }
388 } 397 }
389 398
399 void FakeShillManagerClient::AddGeoNetwork(
400 const std::string& technology,
401 const base::DictionaryValue& network) {
402 base::ListValue* list_value = NULL;
403 if (!stub_geo_networks_.GetListWithoutPathExpansion(technology,
404 &list_value)) {
405 list_value = new base::ListValue;
406 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value);
407 }
408 list_value->Append(network.DeepCopy());
409 }
410
411 void FakeShillManagerClient::AddProfile(const std::string& profile_path) {
412 const char* key = shill::kProfilesProperty;
413 if (GetListProperty(key)
414 ->AppendIfNotPresent(new base::StringValue(profile_path))) {
415 CallNotifyObserversPropertyChanged(key);
416 }
417 }
418
390 void FakeShillManagerClient::ClearProperties() { 419 void FakeShillManagerClient::ClearProperties() {
391 stub_properties_.Clear(); 420 stub_properties_.Clear();
392 } 421 }
393 422
394 void FakeShillManagerClient::AddManagerService(const std::string& service_path, 423 void FakeShillManagerClient::AddManagerService(const std::string& service_path,
395 bool add_to_visible_list, 424 bool add_to_visible_list,
396 bool add_to_watch_list) { 425 bool add_to_watch_list) {
397 // Always add to ServiceCompleteListProperty. 426 // Always add to ServiceCompleteListProperty.
398 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( 427 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent(
399 base::Value::CreateStringValue(service_path)); 428 base::Value::CreateStringValue(service_path));
400 // If visible, add to Services and notify if new. 429 // If visible, add to Services and notify if new.
401 if (add_to_visible_list && 430 if (add_to_visible_list &&
402 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( 431 GetListProperty(shill::kServicesProperty)
403 base::Value::CreateStringValue(service_path))) { 432 ->AppendIfNotPresent(base::Value::CreateStringValue(service_path))) {
404 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); 433 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
405 } 434 }
406 if (add_to_watch_list) 435 if (add_to_watch_list)
407 AddServiceToWatchList(service_path); 436 AddServiceToWatchList(service_path);
408 } 437 }
409 438
410 void FakeShillManagerClient::RemoveManagerService( 439 void FakeShillManagerClient::RemoveManagerService(
411 const std::string& service_path) { 440 const std::string& service_path) {
412 base::StringValue service_path_value(service_path); 441 base::StringValue service_path_value(service_path);
413 if (GetListProperty(shill::kServicesProperty)->Remove( 442 if (GetListProperty(shill::kServicesProperty)
414 service_path_value, NULL)) { 443 ->Remove(service_path_value, NULL)) {
415 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); 444 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
416 } 445 }
417 GetListProperty(shill::kServiceCompleteListProperty)->Remove( 446 GetListProperty(shill::kServiceCompleteListProperty)
418 service_path_value, NULL); 447 ->Remove(service_path_value, NULL);
419 if (GetListProperty(shill::kServiceWatchListProperty)->Remove( 448 if (GetListProperty(shill::kServiceWatchListProperty)
420 service_path_value, NULL)) { 449 ->Remove(service_path_value, NULL)) {
421 CallNotifyObserversPropertyChanged( 450 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
422 shill::kServiceWatchListProperty, 0);
423 } 451 }
424 } 452 }
425 453
426 void FakeShillManagerClient::ClearManagerServices() { 454 void FakeShillManagerClient::ClearManagerServices() {
427 GetListProperty(shill::kServicesProperty)->Clear(); 455 GetListProperty(shill::kServicesProperty)->Clear();
428 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); 456 GetListProperty(shill::kServiceCompleteListProperty)->Clear();
429 GetListProperty(shill::kServiceWatchListProperty)->Clear(); 457 GetListProperty(shill::kServiceWatchListProperty)->Clear();
430 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); 458 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
431 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); 459 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
432 } 460 }
433 461
434 void FakeShillManagerClient::SortManagerServices() { 462 void FakeShillManagerClient::SortManagerServices() {
435 static const char* ordered_types[] = { 463 static const char* ordered_types[] = {
436 shill::kTypeEthernet, 464 shill::kTypeEthernet,
437 shill::kTypeWifi, 465 shill::kTypeWifi,
438 shill::kTypeCellular, 466 shill::kTypeCellular,
439 shill::kTypeWimax, 467 shill::kTypeWimax,
440 shill::kTypeVPN 468 shill::kTypeVPN
441 }; 469 };
442 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); 470 base::ListValue* service_list = GetListProperty(shill::kServicesProperty);
443 if (!service_list || service_list->empty()) 471 if (!service_list || service_list->empty())
444 return; 472 return;
445 std::vector<std::string> active_services; 473 std::vector<std::string> active_services;
446 std::vector<std::string> inactive_services; 474 std::vector<std::string> inactive_services;
447 for (size_t i = 0; i < arraysize(ordered_types); ++i) { 475 for (size_t i = 0; i < arraysize(ordered_types); ++i) {
448 AppendServicesForType(service_list, ordered_types[i], 476 AppendServicesForType(service_list, ordered_types[i],
449 &active_services, &inactive_services); 477 &active_services, &inactive_services);
450 } 478 }
451 service_list->Clear(); 479 service_list->Clear();
452 for (size_t i = 0; i < active_services.size(); ++i) 480 for (size_t i = 0; i < active_services.size(); ++i)
453 service_list->AppendString(active_services[i]); 481 service_list->AppendString(active_services[i]);
454 for (size_t i = 0; i < inactive_services.size(); ++i) 482 for (size_t i = 0; i < inactive_services.size(); ++i)
455 service_list->AppendString(inactive_services[i]); 483 service_list->AppendString(inactive_services[i]);
456 484
457 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); 485 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
458 } 486 }
459 487
460 void FakeShillManagerClient::AddGeoNetwork( 488
461 const std::string& technology, 489 int FakeShillManagerClient::GetInteractiveDelay() const {
462 const base::DictionaryValue& network) { 490 return interactive_delay_;
463 base::ListValue* list_value = NULL;
464 if (!stub_geo_networks_.GetListWithoutPathExpansion(
465 technology, &list_value)) {
466 list_value = new base::ListValue;
467 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value);
468 }
469 list_value->Append(network.DeepCopy());
470 } 491 }
471 492
472 void FakeShillManagerClient::AddProfile(const std::string& profile_path) { 493 std::string FakeShillManagerClient::GetInitialState(
473 const char* key = shill::kProfilesProperty; 494 const std::string& type) const {
474 if (GetListProperty(key)->AppendIfNotPresent( 495 std::map<std::string, std::string>::const_iterator iter =
475 new base::StringValue(profile_path))) { 496 shill_initial_state_map_.find(type);
476 CallNotifyObserversPropertyChanged(key, 0); 497 if (iter == shill_initial_state_map_.end())
477 } 498 return shill::kStateOffline; // Not available
499 return iter->second;
478 } 500 }
479 501
502 // Private methods
503
480 void FakeShillManagerClient::AddServiceToWatchList( 504 void FakeShillManagerClient::AddServiceToWatchList(
481 const std::string& service_path) { 505 const std::string& service_path) {
482 // Remove and insert the service, moving it to the front of the watch list. 506 // Remove and insert the service, moving it to the front of the watch list.
483 GetListProperty(shill::kServiceWatchListProperty)->Remove( 507 GetListProperty(shill::kServiceWatchListProperty)
484 base::StringValue(service_path), NULL); 508 ->Remove(base::StringValue(service_path), NULL);
485 GetListProperty(shill::kServiceWatchListProperty)->Insert( 509 GetListProperty(shill::kServiceWatchListProperty)
486 0, base::Value::CreateStringValue(service_path)); 510 ->Insert(0, base::Value::CreateStringValue(service_path));
487 CallNotifyObserversPropertyChanged( 511 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
488 shill::kServiceWatchListProperty, 0);
489 } 512 }
490 513
491 void FakeShillManagerClient::PassStubProperties( 514 void FakeShillManagerClient::PassStubProperties(
492 const DictionaryValueCallback& callback) const { 515 const DictionaryValueCallback& callback) const {
493 scoped_ptr<base::DictionaryValue> stub_properties( 516 scoped_ptr<base::DictionaryValue> stub_properties(
494 stub_properties_.DeepCopy()); 517 stub_properties_.DeepCopy());
495 // Remove disabled services from the list. 518 // Remove disabled services from the list.
496 stub_properties->SetWithoutPathExpansion( 519 stub_properties->SetWithoutPathExpansion(
497 shill::kServicesProperty, 520 shill::kServicesProperty,
498 GetEnabledServiceList(shill::kServicesProperty)); 521 GetEnabledServiceList(shill::kServicesProperty));
499 stub_properties->SetWithoutPathExpansion( 522 stub_properties->SetWithoutPathExpansion(
500 shill::kServiceWatchListProperty, 523 shill::kServiceWatchListProperty,
501 GetEnabledServiceList(shill::kServiceWatchListProperty)); 524 GetEnabledServiceList(shill::kServiceWatchListProperty));
502 callback.Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties); 525 callback.Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties);
503 } 526 }
504 527
505 void FakeShillManagerClient::PassStubGeoNetworks( 528 void FakeShillManagerClient::PassStubGeoNetworks(
506 const DictionaryValueCallback& callback) const { 529 const DictionaryValueCallback& callback) const {
507 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); 530 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_);
508 } 531 }
509 532
510 void FakeShillManagerClient::CallNotifyObserversPropertyChanged( 533 void FakeShillManagerClient::CallNotifyObserversPropertyChanged(
511 const std::string& property, 534 const std::string& property) {
512 int delay_ms) {
513 // Avoid unnecessary delayed task if we have no observers (e.g. during 535 // Avoid unnecessary delayed task if we have no observers (e.g. during
514 // initial setup). 536 // initial setup).
515 if (!observer_list_.might_have_observers()) 537 if (!observer_list_.might_have_observers())
516 return; 538 return;
517 if (!CommandLine::ForCurrentProcess()->HasSwitch( 539 base::MessageLoop::current()->PostTask(
518 chromeos::switches::kEnableStubInteractive)) {
519 delay_ms = 0;
520 }
521 base::MessageLoop::current()->PostDelayedTask(
522 FROM_HERE, 540 FROM_HERE,
523 base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged, 541 base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged,
524 weak_ptr_factory_.GetWeakPtr(), 542 weak_ptr_factory_.GetWeakPtr(),
525 property), 543 property));
526 base::TimeDelta::FromMilliseconds(delay_ms));
527 } 544 }
528 545
529 void FakeShillManagerClient::NotifyObserversPropertyChanged( 546 void FakeShillManagerClient::NotifyObserversPropertyChanged(
530 const std::string& property) { 547 const std::string& property) {
531 if (property == shill::kServicesProperty || 548 if (property == shill::kServicesProperty ||
532 property == shill::kServiceWatchListProperty) { 549 property == shill::kServiceWatchListProperty) {
533 scoped_ptr<base::ListValue> services(GetEnabledServiceList(property)); 550 scoped_ptr<base::ListValue> services(GetEnabledServiceList(property));
534 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, 551 FOR_EACH_OBSERVER(ShillPropertyChangedObserver,
535 observer_list_, 552 observer_list_,
536 OnPropertyChanged(property, *(services.get()))); 553 OnPropertyChanged(property, *(services.get())));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 const base::Closure& callback, 603 const base::Closure& callback,
587 bool enabled) { 604 bool enabled) {
588 base::ListValue* enabled_list = NULL; 605 base::ListValue* enabled_list = NULL;
589 stub_properties_.GetListWithoutPathExpansion( 606 stub_properties_.GetListWithoutPathExpansion(
590 shill::kEnabledTechnologiesProperty, &enabled_list); 607 shill::kEnabledTechnologiesProperty, &enabled_list);
591 DCHECK(enabled_list); 608 DCHECK(enabled_list);
592 if (enabled) 609 if (enabled)
593 enabled_list->AppendIfNotPresent(new base::StringValue(type)); 610 enabled_list->AppendIfNotPresent(new base::StringValue(type));
594 else 611 else
595 enabled_list->Remove(base::StringValue(type), NULL); 612 enabled_list->Remove(base::StringValue(type), NULL);
596 CallNotifyObserversPropertyChanged( 613 CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty);
597 shill::kEnabledTechnologiesProperty, 0 /* already delayed */);
598 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 614 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
599 // May affect available services 615 // May affect available services
600 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); 616 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
601 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); 617 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
602 } 618 }
603 619
604 base::ListValue* FakeShillManagerClient::GetEnabledServiceList( 620 base::ListValue* FakeShillManagerClient::GetEnabledServiceList(
605 const std::string& property) const { 621 const std::string& property) const {
606 base::ListValue* new_service_list = new base::ListValue; 622 base::ListValue* new_service_list = new base::ListValue;
607 const base::ListValue* service_list; 623 const base::ListValue* service_list;
608 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { 624 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) {
609 ShillServiceClient::TestInterface* service_client = 625 ShillServiceClient::TestInterface* service_client =
610 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 626 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
611 for (base::ListValue::const_iterator iter = service_list->begin(); 627 for (base::ListValue::const_iterator iter = service_list->begin();
(...skipping 19 matching lines...) Expand all
631 } 647 }
632 648
633 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, 649 void FakeShillManagerClient::ScanCompleted(const std::string& device_path,
634 const base::Closure& callback) { 650 const base::Closure& callback) {
635 if (!device_path.empty()) { 651 if (!device_path.empty()) {
636 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> 652 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()->
637 SetDeviceProperty(device_path, 653 SetDeviceProperty(device_path,
638 shill::kScanningProperty, 654 shill::kScanningProperty,
639 base::FundamentalValue(false)); 655 base::FundamentalValue(false));
640 } 656 }
641 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); 657 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
642 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); 658 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
643 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 659 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
644 } 660 }
645 661
662 void FakeShillManagerClient::ParseCommandLineSwitch() {
663 if (dbus_command_line_helper::ParseOptions(
664 switches::kShillStub,
665 base::Bind(&FakeShillManagerClient::ParseOption,
666 base::Unretained(this))))
667 return;
668 // Default setup
669 SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline);
670 SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline);
671 SetInitialNetworkState(shill::kTypeCellular, shill::kStateIdle);
672 SetInitialNetworkState(shill::kTypeVPN, shill::kStateIdle);
673 }
674
675 bool FakeShillManagerClient::ParseOption(const std::string& arg0,
676 const std::string& arg1) {
677 if (arg0 == "interactive") {
678 int seconds = 3;
679 if (!arg1.empty())
680 base::StringToInt(arg1, &seconds);
681 interactive_delay_ = seconds;
682 return true;
683 }
684 return SetInitialNetworkState(arg0, arg1);
685 }
686
687 bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg,
688 std::string state_arg) {
689 std::string state;
690 state_arg = StringToLowerASCII(state_arg);
691 if (state_arg == "0" || state_arg == "off" || state_arg == "inactive" ||
692 state_arg == shill::kStateIdle)
693 state = shill::kStateIdle; // Enabled but not connected
694 else if (state_arg == "disabled" || state_arg == "disconnect")
695 state = shill::kStateDisconnect; // Diabled but available
696 else if (state_arg == "none" || state_arg == "offline")
697 state = shill::kStateOffline; // Not available
698 else if (state_arg == "portal")
699 state = shill::kStatePortal; // Connected to portal
700 else if (state_arg == "active" || state_arg == "activated")
701 state = shill::kActivationStateActivated; // Connected and activated
702 else
703 state = shill::kStateOnline; // Connected
704
705 std::string type;
706 type_arg = StringToLowerASCII(type_arg);
707 if (type_arg == "ethernet" || type_arg == "eth") {
708 if (state == shill::kStateIdle || state == shill::kStateDisconnect)
709 state = shill::kStateOffline; // No unconnected or disabled ethernet.
710 shill_initial_state_map_[shill::kTypeEthernet] = state;
711 } else if (type_arg == "wifi") {
712 shill_initial_state_map_[shill::kTypeWifi] = state;
713 } else if (type_arg == "cellular") {
714 shill_initial_state_map_[shill::kTypeCellular] = state;
715 } else if (type_arg == "wireless") {
716 shill_initial_state_map_[shill::kTypeWifi] = state;
717 shill_initial_state_map_[shill::kTypeCellular] = state;
718 } else if (type_arg == "wimax") {
719 shill_initial_state_map_[shill::kTypeWimax] = state;
720 } else if (type_arg == "vpn") {
721 shill_initial_state_map_[shill::kTypeVPN] = state;
722 } else {
723 LOG(WARNING) << "Unrecognized Shill network type: " << type_arg;
724 return false;
725 }
726 return true;
727 }
728
729 void FakeShillManagerClient::SetupDefaultEnvironment() {
730 DBusThreadManager* dbus_manager = DBusThreadManager::Get();
731 ShillServiceClient::TestInterface* services =
732 dbus_manager->GetShillServiceClient()->GetTestInterface();
733 ShillProfileClient::TestInterface* profiles =
734 dbus_manager->GetShillProfileClient()->GetTestInterface();
735 ShillDeviceClient::TestInterface* devices =
736 dbus_manager->GetShillDeviceClient()->GetTestInterface();
737 if (!services || !profiles || !devices)
738 return;
739
740 const std::string shared_profile = ShillProfileClient::GetSharedProfilePath();
741 profiles->AddProfile(shared_profile, std::string());
742
743 const bool add_to_visible = true;
744 const bool add_to_watchlist = true;
745
746 bool enabled, portaled;
747 std::string state;
748
749 // Ethernet. No service is not added unless connected.
750 state = ParseInitialState(shill::kTypeEthernet, &enabled, &portaled);
751 if (state == shill::kStateOnline) {
752 AddTechnology(shill::kTypeEthernet, enabled);
753 devices->AddDevice(
754 "/device/eth1", shill::kTypeEthernet, "stub_eth_device1");
755 services->AddService("eth1", "eth1",
756 shill::kTypeEthernet,
757 state,
758 add_to_visible, add_to_watchlist);
759 profiles->AddService(shared_profile, "eth1");
760 }
761
762 // Wifi
763 state = ParseInitialState(shill::kTypeWifi, &enabled, &portaled);
764 if (state != shill::kStateOffline) {
765 AddTechnology(shill::kTypeWifi, enabled);
766 devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1");
767
768 services->AddService("wifi1",
769 "wifi1",
770 shill::kTypeWifi,
771 state,
772 add_to_visible, add_to_watchlist);
773 services->SetServiceProperty("wifi1",
774 shill::kSecurityProperty,
775 base::StringValue(shill::kSecurityWep));
776 profiles->AddService(shared_profile, "wifi1");
777
778 services->AddService("wifi2",
779 "wifi2_PSK",
780 shill::kTypeWifi,
781 shill::kStateIdle,
782 add_to_visible, add_to_watchlist);
783 services->SetServiceProperty("wifi2",
784 shill::kSecurityProperty,
785 base::StringValue(shill::kSecurityPsk));
786
787 base::FundamentalValue strength_value(80);
788 services->SetServiceProperty(
789 "wifi2", shill::kSignalStrengthProperty, strength_value);
790 profiles->AddService(shared_profile, "wifi2");
791
792 if (portaled) {
793 services->AddService("portalled_wifi",
794 "Portalled Wifi",
795 shill::kTypeWifi,
796 shill::kStatePortal,
797 add_to_visible, add_to_watchlist);
798 services->SetServiceProperty("portalled_wifi",
799 shill::kSecurityProperty,
800 base::StringValue(shill::kSecurityNone));
801 services->SetConnectBehavior("portalled_wifi",
802 base::Bind(&UpdatePortalledWifiState,
803 "portalled_wifi"));
804 services->SetServiceProperty("portalled_wifi",
805 shill::kConnectableProperty,
806 base::FundamentalValue(true));
807 profiles->AddService(shared_profile, "portalled_wifi");
808 }
809 }
810
811 // Wimax
812 state = ParseInitialState(shill::kTypeWimax, &enabled, &portaled);
813 if (state != shill::kStateOffline) {
814 AddTechnology(shill::kTypeWimax, enabled);
815 devices->AddDevice(
816 "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1");
817
818 services->AddService("wimax1",
819 "wimax1",
820 shill::kTypeWimax,
821 state,
822 add_to_visible, add_to_watchlist);
823 services->SetServiceProperty(
824 "wimax1", shill::kConnectableProperty, base::FundamentalValue(true));
825 }
826
827 // Cellular
828 state = ParseInitialState(shill::kTypeCellular, &enabled, &portaled);
829 if (state != shill::kStateOffline) {
830 bool activated = false;
831 if (state == shill::kActivationStateActivated) {
832 activated = true;
833 state = shill::kStateIdle;
834 }
835 AddTechnology(shill::kTypeCellular, enabled);
836 devices->AddDevice(
837 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1");
838 devices->SetDeviceProperty("/device/cellular1",
839 shill::kCarrierProperty,
840 base::StringValue(shill::kCarrierSprint));
841
842 services->AddService("cellular1",
843 "cellular1",
844 shill::kTypeCellular,
845 state,
846 add_to_visible, add_to_watchlist);
847 base::StringValue technology_value(shill::kNetworkTechnologyGsm);
848 services->SetServiceProperty(
849 "cellular1", shill::kNetworkTechnologyProperty, technology_value);
850
851 if (activated) {
852 services->SetServiceProperty(
853 "cellular1",
854 shill::kActivationStateProperty,
855 base::StringValue(shill::kActivationStateActivated));
856 services->SetServiceProperty("cellular1",
857 shill::kConnectableProperty,
858 base::FundamentalValue(true));
859 } else {
860 services->SetServiceProperty(
861 "cellular1",
862 shill::kActivationStateProperty,
863 base::StringValue(shill::kActivationStateNotActivated));
864 }
865
866 services->SetServiceProperty("cellular1",
867 shill::kRoamingStateProperty,
868 base::StringValue(shill::kRoamingStateHome));
869 }
870
871 // VPN
872 state = ParseInitialState(shill::kTypeVPN, &enabled, &portaled);
873 if (state != shill::kStateOffline) {
874 // Set the "Provider" dictionary properties. Note: when setting these in
875 // Shill, "Provider.Type", etc keys are used, but when reading the values
876 // "Provider" . "Type", etc keys are used. Here we are setting the values
877 // that will be read (by the UI, tests, etc).
878 base::DictionaryValue provider_properties;
879 provider_properties.SetString(shill::kTypeProperty,
880 shill::kProviderOpenVpn);
881 provider_properties.SetString(shill::kHostProperty, "vpn_host");
882
883 services->AddService("vpn1",
884 "vpn1",
885 shill::kTypeVPN,
886 state,
887 add_to_visible, add_to_watchlist);
888 services->SetServiceProperty(
889 "vpn1", shill::kProviderProperty, provider_properties);
890 profiles->AddService(shared_profile, "vpn1");
891
892 services->AddService("vpn2",
893 "vpn2",
894 shill::kTypeVPN,
895 shill::kStateIdle,
896 add_to_visible, add_to_watchlist);
897 services->SetServiceProperty(
898 "vpn2", shill::kProviderProperty, provider_properties);
899 }
900
901 SortManagerServices();
902 }
903
904 std::string FakeShillManagerClient::ParseInitialState(const std::string& type,
905 bool* enabled,
906 bool* portaled) {
907 std::string state = GetInitialState(type);
908 if (state == shill::kStateDisconnect) {
909 *enabled = false;
910 *portaled = false;
911 return shill::kStateIdle;
912 }
913 if (state == shill::kStatePortal) {
914 if (type != shill::kTypeWifi)
915 LOG(WARNING) << "Invalid state: " << state << " for " << type;
916 *enabled = true;
917 *portaled = true;
918 return shill::kStateIdle;
919 }
920 if (state == shill::kActivationStateActivated &&
921 type != shill::kTypeCellular) {
922 LOG(WARNING) << "Invalid state: " << state << " for " << type;
923 state = shill::kStateIdle;
924 }
925 *enabled = true;
926 *portaled = false;
927 return state;
928 }
929
646 } // namespace chromeos 930 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698