Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "chromeos/dbus/shill_manager_client.h" | 12 #include "chromeos/dbus/shill_manager_client.h" |
| 13 #include "chromeos/dbus/shill_property_changed_observer.h" | 13 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 14 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
| 15 #include "dbus/message.h" | 15 #include "dbus/message.h" |
| 16 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
| 17 #include "dbus/object_proxy.h" | 17 #include "dbus/object_proxy.h" |
| 18 #include "dbus/values_util.h" | 18 #include "dbus/values_util.h" |
| 19 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 20 | 20 |
| 21 namespace chromeos { | 21 namespace chromeos { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 std::string kSimPin = "1111"; | |
| 26 | |
| 25 void ErrorFunction(const std::string& device_path, | 27 void ErrorFunction(const std::string& device_path, |
| 26 const std::string& error_name, | 28 const std::string& error_name, |
| 27 const std::string& error_message) { | 29 const std::string& error_message) { |
| 28 LOG(ERROR) << "Shill Error for: " << device_path | 30 LOG(ERROR) << "Shill Error for: " << device_path |
| 29 << ": " << error_name << " : " << error_message; | 31 << ": " << error_name << " : " << error_message; |
| 30 } | 32 } |
| 31 | 33 |
| 32 void PostDeviceNotFoundError( | 34 void PostDeviceNotFoundError( |
| 33 const ShillDeviceClient::ErrorCallback& error_callback) { | 35 const ShillDeviceClient::ErrorCallback& error_callback) { |
| 34 std::string error_message("Failed"); | 36 std::string error_message("Failed"); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 base::Bind(callback, | 124 base::Bind(callback, |
| 123 DBUS_METHOD_CALL_SUCCESS, | 125 DBUS_METHOD_CALL_SUCCESS, |
| 124 dbus::ObjectPath())); | 126 dbus::ObjectPath())); |
| 125 } | 127 } |
| 126 | 128 |
| 127 void FakeShillDeviceClient::RequirePin(const dbus::ObjectPath& device_path, | 129 void FakeShillDeviceClient::RequirePin(const dbus::ObjectPath& device_path, |
| 128 const std::string& pin, | 130 const std::string& pin, |
| 129 bool require, | 131 bool require, |
| 130 const base::Closure& callback, | 132 const base::Closure& callback, |
| 131 const ErrorCallback& error_callback) { | 133 const ErrorCallback& error_callback) { |
| 132 if (!stub_devices_.HasKey(device_path.value())) { | 134 VLOG(1) << "RequirePin: " << device_path.value(); |
| 135 if (pin != kSimPin) { | |
| 136 base::MessageLoop::current()->PostTask( | |
| 137 FROM_HERE, | |
| 138 base::Bind(error_callback, shill::kErrorResultIncorrectPin, "")); | |
| 139 return; | |
| 140 } | |
| 141 base::DictionaryValue* device_properties = NULL; | |
| 142 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), | |
| 143 &device_properties)) { | |
| 133 PostDeviceNotFoundError(error_callback); | 144 PostDeviceNotFoundError(error_callback); |
| 134 return; | 145 return; |
| 135 } | 146 } |
| 147 base::DictionaryValue* simlock_dict = NULL; | |
| 148 if (!device_properties->GetDictionaryWithoutPathExpansion( | |
| 149 shill::kSIMLockStatusProperty, &simlock_dict)) { | |
| 150 simlock_dict = new base::DictionaryValue; | |
| 151 device_properties->SetWithoutPathExpansion( | |
| 152 shill::kSIMLockStatusProperty, simlock_dict); | |
| 153 } | |
| 154 simlock_dict->Clear(); | |
| 155 simlock_dict->Set(shill::kSIMLockEnabledProperty, | |
| 156 new base::FundamentalValue(require)); | |
|
armansito
2014/07/18 03:34:58
nit: SetBoolean?
stevenjb
2014/07/18 17:39:23
Done.
| |
| 157 // TODO(stevenjb): Investigate why non-empty value breaks UI. | |
| 158 std::string lock_type = ""; // shill::kSIMLockPin | |
| 159 simlock_dict->SetString(shill::kSIMLockTypeProperty, lock_type); | |
| 160 simlock_dict->SetInteger(shill::kSIMLockRetriesLeftProperty, 5); | |
| 161 | |
| 162 NotifyObserversPropertyChanged(device_path, shill::kSIMLockStatusProperty); | |
| 136 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 163 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 137 } | 164 } |
| 138 | 165 |
| 139 void FakeShillDeviceClient::EnterPin(const dbus::ObjectPath& device_path, | 166 void FakeShillDeviceClient::EnterPin(const dbus::ObjectPath& device_path, |
| 140 const std::string& pin, | 167 const std::string& pin, |
| 141 const base::Closure& callback, | 168 const base::Closure& callback, |
| 142 const ErrorCallback& error_callback) { | 169 const ErrorCallback& error_callback) { |
| 170 VLOG(1) << "EnterPin: " << device_path.value(); | |
| 171 if (pin != kSimPin) { | |
| 172 base::MessageLoop::current()->PostTask( | |
| 173 FROM_HERE, | |
| 174 base::Bind(error_callback, shill::kErrorResultIncorrectPin, "")); | |
| 175 return; | |
| 176 } | |
| 143 if (!stub_devices_.HasKey(device_path.value())) { | 177 if (!stub_devices_.HasKey(device_path.value())) { |
| 144 PostDeviceNotFoundError(error_callback); | 178 PostDeviceNotFoundError(error_callback); |
| 145 return; | 179 return; |
| 146 } | 180 } |
| 147 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 181 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 148 } | 182 } |
| 149 | 183 |
| 150 void FakeShillDeviceClient::UnblockPin(const dbus::ObjectPath& device_path, | 184 void FakeShillDeviceClient::UnblockPin(const dbus::ObjectPath& device_path, |
| 151 const std::string& puk, | 185 const std::string& puk, |
| 152 const std::string& pin, | 186 const std::string& pin, |
| 153 const base::Closure& callback, | 187 const base::Closure& callback, |
| 154 const ErrorCallback& error_callback) { | 188 const ErrorCallback& error_callback) { |
| 189 VLOG(1) << "UnblockPin: " << device_path.value(); | |
| 155 if (!stub_devices_.HasKey(device_path.value())) { | 190 if (!stub_devices_.HasKey(device_path.value())) { |
| 156 PostDeviceNotFoundError(error_callback); | 191 PostDeviceNotFoundError(error_callback); |
| 157 return; | 192 return; |
| 158 } | 193 } |
| 159 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 194 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 160 } | 195 } |
| 161 | 196 |
| 162 void FakeShillDeviceClient::ChangePin(const dbus::ObjectPath& device_path, | 197 void FakeShillDeviceClient::ChangePin(const dbus::ObjectPath& device_path, |
| 163 const std::string& old_pin, | 198 const std::string& old_pin, |
| 164 const std::string& new_pin, | 199 const std::string& new_pin, |
| 165 const base::Closure& callback, | 200 const base::Closure& callback, |
| 166 const ErrorCallback& error_callback) { | 201 const ErrorCallback& error_callback) { |
| 202 VLOG(1) << "ChangePin: " << device_path.value(); | |
| 167 if (!stub_devices_.HasKey(device_path.value())) { | 203 if (!stub_devices_.HasKey(device_path.value())) { |
| 168 PostDeviceNotFoundError(error_callback); | 204 PostDeviceNotFoundError(error_callback); |
| 169 return; | 205 return; |
| 170 } | 206 } |
| 171 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 207 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 172 } | 208 } |
| 173 | 209 |
| 174 void FakeShillDeviceClient::Register(const dbus::ObjectPath& device_path, | 210 void FakeShillDeviceClient::Register(const dbus::ObjectPath& device_path, |
| 175 const std::string& network_id, | 211 const std::string& network_id, |
| 176 const base::Closure& callback, | 212 const base::Closure& callback, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 388 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
| 353 observer_list_.find(device_path); | 389 observer_list_.find(device_path); |
| 354 if (iter != observer_list_.end()) | 390 if (iter != observer_list_.end()) |
| 355 return *(iter->second); | 391 return *(iter->second); |
| 356 PropertyObserverList* observer_list = new PropertyObserverList(); | 392 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 357 observer_list_[device_path] = observer_list; | 393 observer_list_[device_path] = observer_list; |
| 358 return *observer_list; | 394 return *observer_list; |
| 359 } | 395 } |
| 360 | 396 |
| 361 } // namespace chromeos | 397 } // namespace chromeos |
| OLD | NEW |