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