| 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->SetBoolean(shill::kSIMLockEnabledProperty, require); |
| 156 // TODO(stevenjb): Investigate why non-empty value breaks UI. |
| 157 std::string lock_type = ""; // shill::kSIMLockPin |
| 158 simlock_dict->SetString(shill::kSIMLockTypeProperty, lock_type); |
| 159 simlock_dict->SetInteger(shill::kSIMLockRetriesLeftProperty, 5); |
| 160 |
| 161 NotifyObserversPropertyChanged(device_path, shill::kSIMLockStatusProperty); |
| 136 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 162 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 137 } | 163 } |
| 138 | 164 |
| 139 void FakeShillDeviceClient::EnterPin(const dbus::ObjectPath& device_path, | 165 void FakeShillDeviceClient::EnterPin(const dbus::ObjectPath& device_path, |
| 140 const std::string& pin, | 166 const std::string& pin, |
| 141 const base::Closure& callback, | 167 const base::Closure& callback, |
| 142 const ErrorCallback& error_callback) { | 168 const ErrorCallback& error_callback) { |
| 169 VLOG(1) << "EnterPin: " << device_path.value(); |
| 170 if (pin != kSimPin) { |
| 171 base::MessageLoop::current()->PostTask( |
| 172 FROM_HERE, |
| 173 base::Bind(error_callback, shill::kErrorResultIncorrectPin, "")); |
| 174 return; |
| 175 } |
| 143 if (!stub_devices_.HasKey(device_path.value())) { | 176 if (!stub_devices_.HasKey(device_path.value())) { |
| 144 PostDeviceNotFoundError(error_callback); | 177 PostDeviceNotFoundError(error_callback); |
| 145 return; | 178 return; |
| 146 } | 179 } |
| 147 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 180 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 148 } | 181 } |
| 149 | 182 |
| 150 void FakeShillDeviceClient::UnblockPin(const dbus::ObjectPath& device_path, | 183 void FakeShillDeviceClient::UnblockPin(const dbus::ObjectPath& device_path, |
| 151 const std::string& puk, | 184 const std::string& puk, |
| 152 const std::string& pin, | 185 const std::string& pin, |
| 153 const base::Closure& callback, | 186 const base::Closure& callback, |
| 154 const ErrorCallback& error_callback) { | 187 const ErrorCallback& error_callback) { |
| 188 VLOG(1) << "UnblockPin: " << device_path.value(); |
| 155 if (!stub_devices_.HasKey(device_path.value())) { | 189 if (!stub_devices_.HasKey(device_path.value())) { |
| 156 PostDeviceNotFoundError(error_callback); | 190 PostDeviceNotFoundError(error_callback); |
| 157 return; | 191 return; |
| 158 } | 192 } |
| 159 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 193 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 160 } | 194 } |
| 161 | 195 |
| 162 void FakeShillDeviceClient::ChangePin(const dbus::ObjectPath& device_path, | 196 void FakeShillDeviceClient::ChangePin(const dbus::ObjectPath& device_path, |
| 163 const std::string& old_pin, | 197 const std::string& old_pin, |
| 164 const std::string& new_pin, | 198 const std::string& new_pin, |
| 165 const base::Closure& callback, | 199 const base::Closure& callback, |
| 166 const ErrorCallback& error_callback) { | 200 const ErrorCallback& error_callback) { |
| 201 VLOG(1) << "ChangePin: " << device_path.value(); |
| 167 if (!stub_devices_.HasKey(device_path.value())) { | 202 if (!stub_devices_.HasKey(device_path.value())) { |
| 168 PostDeviceNotFoundError(error_callback); | 203 PostDeviceNotFoundError(error_callback); |
| 169 return; | 204 return; |
| 170 } | 205 } |
| 171 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 206 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 172 } | 207 } |
| 173 | 208 |
| 174 void FakeShillDeviceClient::Register(const dbus::ObjectPath& device_path, | 209 void FakeShillDeviceClient::Register(const dbus::ObjectPath& device_path, |
| 175 const std::string& network_id, | 210 const std::string& network_id, |
| 176 const base::Closure& callback, | 211 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 = | 387 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
| 353 observer_list_.find(device_path); | 388 observer_list_.find(device_path); |
| 354 if (iter != observer_list_.end()) | 389 if (iter != observer_list_.end()) |
| 355 return *(iter->second); | 390 return *(iter->second); |
| 356 PropertyObserverList* observer_list = new PropertyObserverList(); | 391 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 357 observer_list_[device_path] = observer_list; | 392 observer_list_[device_path] = observer_list; |
| 358 return *observer_list; | 393 return *observer_list; |
| 359 } | 394 } |
| 360 | 395 |
| 361 } // namespace chromeos | 396 } // namespace chromeos |
| OLD | NEW |