| 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_device_client.h" | 5 #include "chromeos/dbus/fake_shill_device_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 const std::string& name, | 114 const std::string& name, |
| 115 const base::Value& value, | 115 const base::Value& value, |
| 116 const base::Closure& callback, | 116 const base::Closure& callback, |
| 117 const ErrorCallback& error_callback) { | 117 const ErrorCallback& error_callback) { |
| 118 base::DictionaryValue* device_properties = NULL; | 118 base::DictionaryValue* device_properties = NULL; |
| 119 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), | 119 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), |
| 120 &device_properties)) { | 120 &device_properties)) { |
| 121 PostNotFoundError(error_callback); | 121 PostNotFoundError(error_callback); |
| 122 return; | 122 return; |
| 123 } | 123 } |
| 124 device_properties->SetWithoutPathExpansion(name, value.DeepCopy()); | 124 device_properties->SetWithoutPathExpansion(name, value.CreateDeepCopy()); |
| 125 base::ThreadTaskRunnerHandle::Get()->PostTask( | 125 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 126 FROM_HERE, | 126 FROM_HERE, |
| 127 base::Bind(&FakeShillDeviceClient::NotifyObserversPropertyChanged, | 127 base::Bind(&FakeShillDeviceClient::NotifyObserversPropertyChanged, |
| 128 weak_ptr_factory_.GetWeakPtr(), device_path, name)); | 128 weak_ptr_factory_.GetWeakPtr(), device_path, name)); |
| 129 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 129 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void FakeShillDeviceClient::ClearProperty( | 132 void FakeShillDeviceClient::ClearProperty( |
| 133 const dbus::ObjectPath& device_path, | 133 const dbus::ObjectPath& device_path, |
| 134 const std::string& name, | 134 const std::string& name, |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 base::DictionaryValue* device_properties = NULL; | 488 base::DictionaryValue* device_properties = NULL; |
| 489 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path, | 489 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path, |
| 490 &device_properties)) { | 490 &device_properties)) { |
| 491 NOTREACHED() << "Device not found: " << device_path; | 491 NOTREACHED() << "Device not found: " << device_path; |
| 492 return; | 492 return; |
| 493 } | 493 } |
| 494 | 494 |
| 495 base::DictionaryValue* simlock_dict = nullptr; | 495 base::DictionaryValue* simlock_dict = nullptr; |
| 496 if (!device_properties->GetDictionaryWithoutPathExpansion( | 496 if (!device_properties->GetDictionaryWithoutPathExpansion( |
| 497 shill::kSIMLockStatusProperty, &simlock_dict)) { | 497 shill::kSIMLockStatusProperty, &simlock_dict)) { |
| 498 simlock_dict = new base::DictionaryValue; | 498 device_properties->SetWithoutPathExpansion( |
| 499 device_properties->SetWithoutPathExpansion(shill::kSIMLockStatusProperty, | 499 shill::kSIMLockStatusProperty, |
| 500 simlock_dict); | 500 base::MakeUnique<base::DictionaryValue>()); |
| 501 device_properties->GetDictionaryWithoutPathExpansion( |
| 502 shill::kSIMLockStatusProperty, &simlock_dict); |
| 501 } | 503 } |
| 502 simlock_dict->Clear(); | 504 simlock_dict->Clear(); |
| 503 simlock_dict->SetStringWithoutPathExpansion(shill::kSIMLockTypeProperty, | 505 simlock_dict->SetStringWithoutPathExpansion(shill::kSIMLockTypeProperty, |
| 504 status.type); | 506 status.type); |
| 505 simlock_dict->SetIntegerWithoutPathExpansion( | 507 simlock_dict->SetIntegerWithoutPathExpansion( |
| 506 shill::kSIMLockRetriesLeftProperty, status.retries_left); | 508 shill::kSIMLockRetriesLeftProperty, status.retries_left); |
| 507 simlock_dict->SetBooleanWithoutPathExpansion(shill::kSIMLockEnabledProperty, | 509 simlock_dict->SetBooleanWithoutPathExpansion(shill::kSIMLockEnabledProperty, |
| 508 status.lock_enabled); | 510 status.lock_enabled); |
| 509 NotifyObserversPropertyChanged(dbus::ObjectPath(device_path), | 511 NotifyObserversPropertyChanged(dbus::ObjectPath(device_path), |
| 510 shill::kSIMLockStatusProperty); | 512 shill::kSIMLockStatusProperty); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 } | 608 } |
| 607 for (auto& observer : GetObserverList(device_path)) | 609 for (auto& observer : GetObserverList(device_path)) |
| 608 observer.OnPropertyChanged(property, *value); | 610 observer.OnPropertyChanged(property, *value); |
| 609 } | 611 } |
| 610 | 612 |
| 611 base::DictionaryValue* FakeShillDeviceClient::GetDeviceProperties( | 613 base::DictionaryValue* FakeShillDeviceClient::GetDeviceProperties( |
| 612 const std::string& device_path) { | 614 const std::string& device_path) { |
| 613 base::DictionaryValue* properties = NULL; | 615 base::DictionaryValue* properties = NULL; |
| 614 if (!stub_devices_.GetDictionaryWithoutPathExpansion( | 616 if (!stub_devices_.GetDictionaryWithoutPathExpansion( |
| 615 device_path, &properties)) { | 617 device_path, &properties)) { |
| 616 properties = new base::DictionaryValue; | 618 stub_devices_.SetWithoutPathExpansion( |
| 617 stub_devices_.SetWithoutPathExpansion(device_path, properties); | 619 device_path, base::MakeUnique<base::DictionaryValue>()); |
| 620 stub_devices_.GetDictionaryWithoutPathExpansion(device_path, &properties); |
| 618 } | 621 } |
| 619 return properties; | 622 return properties; |
| 620 } | 623 } |
| 621 | 624 |
| 622 FakeShillDeviceClient::PropertyObserverList& | 625 FakeShillDeviceClient::PropertyObserverList& |
| 623 FakeShillDeviceClient::GetObserverList(const dbus::ObjectPath& device_path) { | 626 FakeShillDeviceClient::GetObserverList(const dbus::ObjectPath& device_path) { |
| 624 auto iter = observer_list_.find(device_path); | 627 auto iter = observer_list_.find(device_path); |
| 625 if (iter != observer_list_.end()) | 628 if (iter != observer_list_.end()) |
| 626 return *(iter->second); | 629 return *(iter->second); |
| 627 PropertyObserverList* observer_list = new PropertyObserverList(); | 630 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 628 observer_list_[device_path] = base::WrapUnique(observer_list); | 631 observer_list_[device_path] = base::WrapUnique(observer_list); |
| 629 return *observer_list; | 632 return *observer_list; |
| 630 } | 633 } |
| 631 | 634 |
| 632 } // namespace chromeos | 635 } // namespace chromeos |
| OLD | NEW |