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_service_client.h" | 5 #include "chromeos/dbus/fake_shill_service_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 if (!ipconfig_path.empty()) { | 337 if (!ipconfig_path.empty()) { |
338 properties->SetWithoutPathExpansion( | 338 properties->SetWithoutPathExpansion( |
339 shill::kIPConfigProperty, | 339 shill::kIPConfigProperty, |
340 new base::StringValue(ipconfig_path)); | 340 new base::StringValue(ipconfig_path)); |
341 } | 341 } |
342 | 342 |
343 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 343 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
344 AddManagerService(service_path, true); | 344 AddManagerService(service_path, true); |
345 } | 345 } |
346 | 346 |
347 | |
348 base::DictionaryValue* FakeShillServiceClient::SetServiceProperties( | 347 base::DictionaryValue* FakeShillServiceClient::SetServiceProperties( |
349 const std::string& service_path, | 348 const std::string& service_path, |
350 const std::string& guid, | 349 const std::string& guid, |
351 const std::string& name, | 350 const std::string& name, |
352 const std::string& type, | 351 const std::string& type, |
353 const std::string& state, | 352 const std::string& state, |
354 bool visible) { | 353 bool visible) { |
355 base::DictionaryValue* properties = | 354 base::DictionaryValue* properties = |
356 GetModifiableServiceProperties(service_path, true); | 355 GetModifiableServiceProperties(service_path, true); |
357 connect_behavior_.erase(service_path); | 356 connect_behavior_.erase(service_path); |
358 | 357 |
359 std::string profile_path; | 358 std::string profile_path; |
360 base::DictionaryValue profile_properties; | 359 base::DictionaryValue profile_properties; |
361 if (DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> | 360 if (DBusThreadManager::Get() |
362 GetService(service_path, &profile_path, &profile_properties)) { | 361 ->GetShillProfileClient() |
363 properties->SetWithoutPathExpansion( | 362 ->GetTestInterface() |
364 shill::kProfileProperty, | 363 ->GetService(service_path, &profile_path, &profile_properties)) { |
365 new base::StringValue(profile_path)); | 364 properties->SetStringWithoutPathExpansion(shill::kProfileProperty, |
| 365 profile_path); |
366 } | 366 } |
367 | 367 |
368 // If |guid| is provided, set Service.GUID to that. Otherwise if a GUID is | 368 // If |guid| is provided, set Service.GUID to that. Otherwise if a GUID is |
369 // stored in a profile entry, use that. Otherwise leave it blank. Shill does | 369 // stored in a profile entry, use that. Otherwise leave it blank. Shill does |
370 // not enforce a valid guid, we do that at the NetworkStateHandler layer. | 370 // not enforce a valid guid, we do that at the NetworkStateHandler layer. |
371 std::string guid_to_set = guid; | 371 std::string guid_to_set = guid; |
372 if (guid_to_set.empty()) { | 372 if (guid_to_set.empty()) { |
373 profile_properties.GetStringWithoutPathExpansion( | 373 profile_properties.GetStringWithoutPathExpansion(shill::kGuidProperty, |
374 shill::kGuidProperty, &guid_to_set); | 374 &guid_to_set); |
375 } | 375 } |
376 if (!guid_to_set.empty()) { | 376 if (!guid_to_set.empty()) { |
377 properties->SetWithoutPathExpansion(shill::kGuidProperty, | 377 properties->SetStringWithoutPathExpansion(shill::kGuidProperty, |
378 new base::StringValue(guid_to_set)); | 378 guid_to_set); |
379 } | 379 } |
380 shill_property_util::SetSSID(name, properties); | 380 properties->SetStringWithoutPathExpansion(shill::kSSIDProperty, name); |
381 properties->SetWithoutPathExpansion( | 381 shill_property_util::SetSSID(name, properties); // Sets kWifiHexSsid |
382 shill::kNameProperty, | 382 properties->SetStringWithoutPathExpansion(shill::kNameProperty, name); |
383 new base::StringValue(name)); | 383 std::string device_path = DBusThreadManager::Get() |
384 std::string device_path = | 384 ->GetShillDeviceClient() |
385 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> | 385 ->GetTestInterface() |
386 GetDevicePathForType(type); | 386 ->GetDevicePathForType(type); |
387 properties->SetWithoutPathExpansion( | 387 properties->SetStringWithoutPathExpansion(shill::kDeviceProperty, |
388 shill::kDeviceProperty, | 388 device_path); |
389 new base::StringValue(device_path)); | 389 properties->SetStringWithoutPathExpansion(shill::kTypeProperty, type); |
390 properties->SetWithoutPathExpansion( | 390 properties->SetStringWithoutPathExpansion(shill::kStateProperty, state); |
391 shill::kTypeProperty, | 391 properties->SetBooleanWithoutPathExpansion(shill::kVisibleProperty, visible); |
392 new base::StringValue(type)); | |
393 properties->SetWithoutPathExpansion( | |
394 shill::kStateProperty, | |
395 new base::StringValue(state)); | |
396 properties->SetWithoutPathExpansion( | |
397 shill::kVisibleProperty, | |
398 new base::FundamentalValue(visible)); | |
399 if (type == shill::kTypeWifi) { | 392 if (type == shill::kTypeWifi) { |
400 properties->SetWithoutPathExpansion( | 393 properties->SetStringWithoutPathExpansion(shill::kSecurityProperty, |
401 shill::kSecurityProperty, | 394 shill::kSecurityNone); |
402 new base::StringValue(shill::kSecurityNone)); | 395 properties->SetStringWithoutPathExpansion(shill::kModeProperty, |
403 properties->SetWithoutPathExpansion( | 396 shill::kModeManaged); |
404 shill::kModeProperty, | |
405 new base::StringValue(shill::kModeManaged)); | |
406 } | 397 } |
407 return properties; | 398 return properties; |
408 } | 399 } |
409 | 400 |
410 void FakeShillServiceClient::RemoveService(const std::string& service_path) { | 401 void FakeShillServiceClient::RemoveService(const std::string& service_path) { |
411 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); | 402 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
412 connect_behavior_.erase(service_path); | 403 connect_behavior_.erase(service_path); |
413 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 404 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
414 RemoveManagerService(service_path); | 405 RemoveManagerService(service_path); |
415 } | 406 } |
416 | 407 |
417 bool FakeShillServiceClient::SetServiceProperty(const std::string& service_path, | 408 bool FakeShillServiceClient::SetServiceProperty(const std::string& service_path, |
418 const std::string& property, | 409 const std::string& property, |
419 const base::Value& value) { | 410 const base::Value& value) { |
420 base::DictionaryValue* dict = NULL; | 411 base::DictionaryValue* dict = NULL; |
421 if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, &dict)) | 412 if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, &dict)) |
422 return false; | 413 return false; |
423 | 414 |
424 VLOG(1) << "Service.SetProperty: " << property << " = " << value | 415 VLOG(1) << "Service.SetProperty: " << property << " = " << value |
425 << " For: " << service_path; | 416 << " For: " << service_path; |
426 | 417 |
427 base::DictionaryValue new_properties; | 418 base::DictionaryValue new_properties; |
428 std::string changed_property; | 419 std::string changed_property; |
429 bool case_sensitive = true; | 420 bool case_sensitive = true; |
430 if (StartsWithASCII(property, "Provider.", case_sensitive) || | 421 if (StartsWithASCII(property, "Provider.", case_sensitive) || |
431 StartsWithASCII(property, "OpenVPN.", case_sensitive) || | 422 StartsWithASCII(property, "OpenVPN.", case_sensitive) || |
432 StartsWithASCII(property, "L2TPIPsec.", case_sensitive)) { | 423 StartsWithASCII(property, "L2TPIPsec.", case_sensitive)) { |
433 // These properties are only nested within the Provider dictionary if read | 424 // These properties are only nested within the Provider dictionary if read |
434 // from Shill. | 425 // from Shill. Properties that start with "Provider" need to have that |
| 426 // stripped off, other properties are nested in the "Provider" dictionary |
| 427 // as-is. |
| 428 std::string key = property; |
| 429 if (StartsWithASCII(property, "Provider.", case_sensitive)) |
| 430 key = property.substr(strlen("Provider.")); |
435 base::DictionaryValue* provider = new base::DictionaryValue; | 431 base::DictionaryValue* provider = new base::DictionaryValue; |
436 provider->SetWithoutPathExpansion(property, value.DeepCopy()); | 432 provider->SetWithoutPathExpansion(key, value.DeepCopy()); |
437 new_properties.SetWithoutPathExpansion(shill::kProviderProperty, provider); | 433 new_properties.SetWithoutPathExpansion(shill::kProviderProperty, provider); |
438 changed_property = shill::kProviderProperty; | 434 changed_property = shill::kProviderProperty; |
439 } else { | 435 } else { |
440 new_properties.SetWithoutPathExpansion(property, value.DeepCopy()); | 436 new_properties.SetWithoutPathExpansion(property, value.DeepCopy()); |
441 changed_property = property; | 437 changed_property = property; |
442 } | 438 } |
443 | 439 |
444 dict->MergeDictionary(&new_properties); | 440 dict->MergeDictionary(&new_properties); |
445 | 441 |
446 // Add or update the profile entry. | 442 // Add or update the profile entry. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 } else { | 628 } else { |
633 // Set Online. | 629 // Set Online. |
634 VLOG(1) << "Setting state to Online " << service_path; | 630 VLOG(1) << "Setting state to Online " << service_path; |
635 SetServiceProperty(service_path, | 631 SetServiceProperty(service_path, |
636 shill::kStateProperty, | 632 shill::kStateProperty, |
637 base::StringValue(shill::kStateOnline)); | 633 base::StringValue(shill::kStateOnline)); |
638 } | 634 } |
639 } | 635 } |
640 | 636 |
641 } // namespace chromeos | 637 } // namespace chromeos |
OLD | NEW |