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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 callback.Run(*value); | 32 callback.Run(*value); |
33 } | 33 } |
34 | 34 |
35 void PassStubServiceProperties( | 35 void PassStubServiceProperties( |
36 const ShillServiceClient::DictionaryValueCallback& callback, | 36 const ShillServiceClient::DictionaryValueCallback& callback, |
37 DBusMethodCallStatus call_status, | 37 DBusMethodCallStatus call_status, |
38 const base::DictionaryValue* properties) { | 38 const base::DictionaryValue* properties) { |
39 callback.Run(call_status, *properties); | 39 callback.Run(call_status, *properties); |
40 } | 40 } |
41 | 41 |
| 42 void CallSortManagerServices() { |
| 43 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 44 SortManagerServices(); |
| 45 } |
| 46 |
42 } // namespace | 47 } // namespace |
43 | 48 |
44 FakeShillServiceClient::FakeShillServiceClient() : weak_ptr_factory_(this) { | 49 FakeShillServiceClient::FakeShillServiceClient() : weak_ptr_factory_(this) { |
45 } | 50 } |
46 | 51 |
47 FakeShillServiceClient::~FakeShillServiceClient() { | 52 FakeShillServiceClient::~FakeShillServiceClient() { |
48 STLDeleteContainerPairSecondPointers( | 53 STLDeleteContainerPairSecondPointers( |
49 observer_list_.begin(), observer_list_.end()); | 54 observer_list_.begin(), observer_list_.end()); |
50 } | 55 } |
51 | 56 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 base::Value::CreateStringValue(name)); | 356 base::Value::CreateStringValue(name)); |
352 properties->SetWithoutPathExpansion( | 357 properties->SetWithoutPathExpansion( |
353 shill::kDeviceProperty, | 358 shill::kDeviceProperty, |
354 base::Value::CreateStringValue(device_path)); | 359 base::Value::CreateStringValue(device_path)); |
355 properties->SetWithoutPathExpansion( | 360 properties->SetWithoutPathExpansion( |
356 shill::kTypeProperty, | 361 shill::kTypeProperty, |
357 base::Value::CreateStringValue(type)); | 362 base::Value::CreateStringValue(type)); |
358 properties->SetWithoutPathExpansion( | 363 properties->SetWithoutPathExpansion( |
359 shill::kStateProperty, | 364 shill::kStateProperty, |
360 base::Value::CreateStringValue(state)); | 365 base::Value::CreateStringValue(state)); |
361 if (!ipconfig_path.empty()) | 366 if (!ipconfig_path.empty()) { |
362 properties->SetWithoutPathExpansion( | 367 properties->SetWithoutPathExpansion( |
363 shill::kIPConfigProperty, | 368 shill::kIPConfigProperty, |
364 base::Value::CreateStringValue(ipconfig_path)); | 369 base::Value::CreateStringValue(ipconfig_path)); |
| 370 } |
| 371 |
| 372 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 373 SortManagerServices(); |
365 } | 374 } |
366 | 375 |
367 void FakeShillServiceClient::RemoveService(const std::string& service_path) { | 376 void FakeShillServiceClient::RemoveService(const std::string& service_path) { |
368 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 377 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
369 RemoveManagerService(service_path); | 378 RemoveManagerService(service_path); |
370 | 379 |
371 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); | 380 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
372 connect_behavior_.erase(service_path); | 381 connect_behavior_.erase(service_path); |
373 } | 382 } |
374 | 383 |
(...skipping 19 matching lines...) Expand all Loading... |
394 provider->SetWithoutPathExpansion(property, value.DeepCopy()); | 403 provider->SetWithoutPathExpansion(property, value.DeepCopy()); |
395 new_properties.SetWithoutPathExpansion(shill::kProviderProperty, provider); | 404 new_properties.SetWithoutPathExpansion(shill::kProviderProperty, provider); |
396 changed_property = shill::kProviderProperty; | 405 changed_property = shill::kProviderProperty; |
397 } else { | 406 } else { |
398 new_properties.SetWithoutPathExpansion(property, value.DeepCopy()); | 407 new_properties.SetWithoutPathExpansion(property, value.DeepCopy()); |
399 changed_property = property; | 408 changed_property = property; |
400 } | 409 } |
401 | 410 |
402 dict->MergeDictionary(&new_properties); | 411 dict->MergeDictionary(&new_properties); |
403 | 412 |
| 413 // Notify the Manager if the state changed (affects DefaultService). |
404 if (property == shill::kStateProperty) { | 414 if (property == shill::kStateProperty) { |
405 // When State changes the sort order of Services may change. | 415 std::string state; |
| 416 value.GetAsString(&state); |
406 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 417 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
407 SortManagerServices(); | 418 ServiceStateChanged(service_path, state); |
408 } | 419 } |
409 | 420 |
| 421 // If the State changes, the sort order of Services may change and the |
| 422 // DefaultService property may change. |
| 423 if (property == shill::kStateProperty) { |
| 424 base::MessageLoop::current()->PostTask( |
| 425 FROM_HERE, base::Bind(&CallSortManagerServices)); |
| 426 } |
| 427 |
| 428 // Notifiy Chrome of the property change. |
410 base::MessageLoop::current()->PostTask( | 429 base::MessageLoop::current()->PostTask( |
411 FROM_HERE, | 430 FROM_HERE, |
412 base::Bind(&FakeShillServiceClient::NotifyObserversPropertyChanged, | 431 base::Bind(&FakeShillServiceClient::NotifyObserversPropertyChanged, |
413 weak_ptr_factory_.GetWeakPtr(), | 432 weak_ptr_factory_.GetWeakPtr(), |
414 dbus::ObjectPath(service_path), changed_property)); | 433 dbus::ObjectPath(service_path), changed_property)); |
415 return true; | 434 return true; |
416 } | 435 } |
417 | 436 |
418 const base::DictionaryValue* FakeShillServiceClient::GetServiceProperties( | 437 const base::DictionaryValue* FakeShillServiceClient::GetServiceProperties( |
419 const std::string& service_path) const { | 438 const std::string& service_path) const { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 base::StringValue(shill::kErrorBadPassphrase))); | 577 base::StringValue(shill::kErrorBadPassphrase))); |
559 } else { | 578 } else { |
560 // Set Online. | 579 // Set Online. |
561 SetServiceProperty(service_path, | 580 SetServiceProperty(service_path, |
562 shill::kStateProperty, | 581 shill::kStateProperty, |
563 base::StringValue(shill::kStateOnline)); | 582 base::StringValue(shill::kStateOnline)); |
564 } | 583 } |
565 } | 584 } |
566 | 585 |
567 } // namespace chromeos | 586 } // namespace chromeos |
OLD | NEW |