| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/shill_service_client_stub.h" | 5 #include "chromeos/dbus/shill_service_client_stub.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 result_properties.reset(nested_dict->DeepCopy()); | 79 result_properties.reset(nested_dict->DeepCopy()); |
| 80 // Remove credentials that Shill wouldn't send. | 80 // Remove credentials that Shill wouldn't send. |
| 81 result_properties->RemoveWithoutPathExpansion(flimflam::kPassphraseProperty, | 81 result_properties->RemoveWithoutPathExpansion(flimflam::kPassphraseProperty, |
| 82 NULL); | 82 NULL); |
| 83 call_status = DBUS_METHOD_CALL_SUCCESS; | 83 call_status = DBUS_METHOD_CALL_SUCCESS; |
| 84 } else { | 84 } else { |
| 85 result_properties.reset(new base::DictionaryValue); | 85 result_properties.reset(new base::DictionaryValue); |
| 86 call_status = DBUS_METHOD_CALL_FAILURE; | 86 call_status = DBUS_METHOD_CALL_FAILURE; |
| 87 } | 87 } |
| 88 | 88 |
| 89 MessageLoop::current()->PostTask( | 89 base::MessageLoop::current()->PostTask( |
| 90 FROM_HERE, | 90 FROM_HERE, |
| 91 base::Bind(&PassStubServiceProperties, | 91 base::Bind(&PassStubServiceProperties, |
| 92 callback, | 92 callback, |
| 93 call_status, | 93 call_status, |
| 94 base::Owned(result_properties.release()))); | 94 base::Owned(result_properties.release()))); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path, | 97 void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path, |
| 98 const std::string& name, | 98 const std::string& name, |
| 99 const base::Value& value, | 99 const base::Value& value, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 113 std::string state; | 113 std::string state; |
| 114 if (value.GetAsString(&state) && (state == flimflam::kStateOnline || | 114 if (value.GetAsString(&state) && (state == flimflam::kStateOnline || |
| 115 state == flimflam::kStatePortal)) { | 115 state == flimflam::kStatePortal)) { |
| 116 ShillManagerClient* manager_client = | 116 ShillManagerClient* manager_client = |
| 117 DBusThreadManager::Get()->GetShillManagerClient(); | 117 DBusThreadManager::Get()->GetShillManagerClient(); |
| 118 manager_client->GetTestInterface()->MoveServiceToIndex( | 118 manager_client->GetTestInterface()->MoveServiceToIndex( |
| 119 service_path.value(), 0, true); | 119 service_path.value(), 0, true); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 dict->SetWithoutPathExpansion(name, value.DeepCopy()); | 122 dict->SetWithoutPathExpansion(name, value.DeepCopy()); |
| 123 MessageLoop::current()->PostTask( | 123 base::MessageLoop::current()->PostTask( |
| 124 FROM_HERE, | 124 FROM_HERE, |
| 125 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, | 125 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, |
| 126 weak_ptr_factory_.GetWeakPtr(), service_path, name)); | 126 weak_ptr_factory_.GetWeakPtr(), service_path, name)); |
| 127 if (callback.is_null()) | 127 if (callback.is_null()) |
| 128 return; | 128 return; |
| 129 MessageLoop::current()->PostTask(FROM_HERE, callback); | 129 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void ShillServiceClientStub::ClearProperty( | 132 void ShillServiceClientStub::ClearProperty( |
| 133 const dbus::ObjectPath& service_path, | 133 const dbus::ObjectPath& service_path, |
| 134 const std::string& name, | 134 const std::string& name, |
| 135 const base::Closure& callback, | 135 const base::Closure& callback, |
| 136 const ErrorCallback& error_callback) { | 136 const ErrorCallback& error_callback) { |
| 137 base::DictionaryValue* dict = NULL; | 137 base::DictionaryValue* dict = NULL; |
| 138 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 138 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| 139 service_path.value(), &dict)) { | 139 service_path.value(), &dict)) { |
| 140 error_callback.Run("Error.InvalidService", "Invalid Service"); | 140 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 141 return; | 141 return; |
| 142 } | 142 } |
| 143 dict->Remove(name, NULL); | 143 dict->Remove(name, NULL); |
| 144 MessageLoop::current()->PostTask( | 144 base::MessageLoop::current()->PostTask( |
| 145 FROM_HERE, | 145 FROM_HERE, |
| 146 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, | 146 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, |
| 147 weak_ptr_factory_.GetWeakPtr(), service_path, name)); | 147 weak_ptr_factory_.GetWeakPtr(), service_path, name)); |
| 148 if (callback.is_null()) | 148 if (callback.is_null()) |
| 149 return; | 149 return; |
| 150 MessageLoop::current()->PostTask(FROM_HERE, callback); | 150 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void ShillServiceClientStub::ClearProperties( | 153 void ShillServiceClientStub::ClearProperties( |
| 154 const dbus::ObjectPath& service_path, | 154 const dbus::ObjectPath& service_path, |
| 155 const std::vector<std::string>& names, | 155 const std::vector<std::string>& names, |
| 156 const ListValueCallback& callback, | 156 const ListValueCallback& callback, |
| 157 const ErrorCallback& error_callback) { | 157 const ErrorCallback& error_callback) { |
| 158 base::DictionaryValue* dict = NULL; | 158 base::DictionaryValue* dict = NULL; |
| 159 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 159 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| 160 service_path.value(), &dict)) { | 160 service_path.value(), &dict)) { |
| 161 error_callback.Run("Error.InvalidService", "Invalid Service"); | 161 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 scoped_ptr<base::ListValue> results(new base::ListValue); | 164 scoped_ptr<base::ListValue> results(new base::ListValue); |
| 165 for (std::vector<std::string>::const_iterator iter = names.begin(); | 165 for (std::vector<std::string>::const_iterator iter = names.begin(); |
| 166 iter != names.end(); ++iter) { | 166 iter != names.end(); ++iter) { |
| 167 dict->Remove(*iter, NULL); | 167 dict->Remove(*iter, NULL); |
| 168 results->AppendBoolean(true); | 168 results->AppendBoolean(true); |
| 169 } | 169 } |
| 170 for (std::vector<std::string>::const_iterator iter = names.begin(); | 170 for (std::vector<std::string>::const_iterator iter = names.begin(); |
| 171 iter != names.end(); ++iter) { | 171 iter != names.end(); ++iter) { |
| 172 MessageLoop::current()->PostTask( | 172 base::MessageLoop::current()->PostTask( |
| 173 FROM_HERE, | 173 FROM_HERE, |
| 174 base::Bind( | 174 base::Bind( |
| 175 &ShillServiceClientStub::NotifyObserversPropertyChanged, | 175 &ShillServiceClientStub::NotifyObserversPropertyChanged, |
| 176 weak_ptr_factory_.GetWeakPtr(), service_path, *iter)); | 176 weak_ptr_factory_.GetWeakPtr(), service_path, *iter)); |
| 177 } | 177 } |
| 178 if (callback.is_null()) | 178 if (callback.is_null()) |
| 179 return; | 179 return; |
| 180 MessageLoop::current()->PostTask( | 180 base::MessageLoop::current()->PostTask( |
| 181 FROM_HERE, | 181 FROM_HERE, |
| 182 base::Bind(&PassStubListValue, | 182 base::Bind(&PassStubListValue, |
| 183 callback, base::Owned(results.release()))); | 183 callback, base::Owned(results.release()))); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, | 186 void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, |
| 187 const base::Closure& callback, | 187 const base::Closure& callback, |
| 188 const ErrorCallback& error_callback) { | 188 const ErrorCallback& error_callback) { |
| 189 base::Value* service; | 189 base::Value* service; |
| 190 if (!stub_services_.Get(service_path.value(), &service)) { | 190 if (!stub_services_.Get(service_path.value(), &service)) { |
| 191 error_callback.Run("Error.InvalidService", "Invalid Service"); | 191 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 192 return; | 192 return; |
| 193 } | 193 } |
| 194 base::TimeDelta delay; | 194 base::TimeDelta delay; |
| 195 if (CommandLine::ForCurrentProcess()->HasSwitch( | 195 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 196 chromeos::switches::kEnableStubInteractive)) { | 196 chromeos::switches::kEnableStubInteractive)) { |
| 197 // Set Associating | 197 // Set Associating |
| 198 base::StringValue associating_value(flimflam::kStateAssociation); | 198 base::StringValue associating_value(flimflam::kStateAssociation); |
| 199 SetServiceProperty(service_path.value(), | 199 SetServiceProperty(service_path.value(), |
| 200 flimflam::kStateProperty, | 200 flimflam::kStateProperty, |
| 201 associating_value); | 201 associating_value); |
| 202 const int kConnectDelaySeconds = 5; | 202 const int kConnectDelaySeconds = 5; |
| 203 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | 203 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); |
| 204 } | 204 } |
| 205 // Set Online after a delay | 205 // Set Online after a delay |
| 206 base::StringValue online_value(flimflam::kStateOnline); | 206 base::StringValue online_value(flimflam::kStateOnline); |
| 207 MessageLoop::current()->PostDelayedTask( | 207 base::MessageLoop::current()->PostDelayedTask( |
| 208 FROM_HERE, | 208 FROM_HERE, |
| 209 base::Bind(&ShillServiceClientStub::SetProperty, | 209 base::Bind(&ShillServiceClientStub::SetProperty, |
| 210 weak_ptr_factory_.GetWeakPtr(), | 210 weak_ptr_factory_.GetWeakPtr(), |
| 211 service_path, | 211 service_path, |
| 212 flimflam::kStateProperty, | 212 flimflam::kStateProperty, |
| 213 online_value, | 213 online_value, |
| 214 base::Bind(&base::DoNothing), | 214 base::Bind(&base::DoNothing), |
| 215 error_callback), | 215 error_callback), |
| 216 delay); | 216 delay); |
| 217 callback.Run(); | 217 callback.Run(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, | 220 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, |
| 221 const base::Closure& callback, | 221 const base::Closure& callback, |
| 222 const ErrorCallback& error_callback) { | 222 const ErrorCallback& error_callback) { |
| 223 base::Value* service; | 223 base::Value* service; |
| 224 if (!stub_services_.Get(service_path.value(), &service)) { | 224 if (!stub_services_.Get(service_path.value(), &service)) { |
| 225 error_callback.Run("Error.InvalidService", "Invalid Service"); | 225 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 226 return; | 226 return; |
| 227 } | 227 } |
| 228 base::TimeDelta delay; | 228 base::TimeDelta delay; |
| 229 if (CommandLine::ForCurrentProcess()->HasSwitch( | 229 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 230 chromeos::switches::kEnableStubInteractive)) { | 230 chromeos::switches::kEnableStubInteractive)) { |
| 231 const int kConnectDelaySeconds = 2; | 231 const int kConnectDelaySeconds = 2; |
| 232 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | 232 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); |
| 233 } | 233 } |
| 234 // Set Idle after a delay | 234 // Set Idle after a delay |
| 235 base::StringValue idle_value(flimflam::kStateIdle); | 235 base::StringValue idle_value(flimflam::kStateIdle); |
| 236 MessageLoop::current()->PostDelayedTask( | 236 base::MessageLoop::current()->PostDelayedTask( |
| 237 FROM_HERE, | 237 FROM_HERE, |
| 238 base::Bind(&ShillServiceClientStub::SetProperty, | 238 base::Bind(&ShillServiceClientStub::SetProperty, |
| 239 weak_ptr_factory_.GetWeakPtr(), | 239 weak_ptr_factory_.GetWeakPtr(), |
| 240 service_path, | 240 service_path, |
| 241 flimflam::kStateProperty, | 241 flimflam::kStateProperty, |
| 242 idle_value, | 242 idle_value, |
| 243 base::Bind(&base::DoNothing), | 243 base::Bind(&base::DoNothing), |
| 244 error_callback), | 244 error_callback), |
| 245 delay); | 245 delay); |
| 246 callback.Run(); | 246 callback.Run(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void ShillServiceClientStub::Remove(const dbus::ObjectPath& service_path, | 249 void ShillServiceClientStub::Remove(const dbus::ObjectPath& service_path, |
| 250 const base::Closure& callback, | 250 const base::Closure& callback, |
| 251 const ErrorCallback& error_callback) { | 251 const ErrorCallback& error_callback) { |
| 252 if (callback.is_null()) | 252 if (callback.is_null()) |
| 253 return; | 253 return; |
| 254 MessageLoop::current()->PostTask(FROM_HERE, callback); | 254 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void ShillServiceClientStub::ActivateCellularModem( | 257 void ShillServiceClientStub::ActivateCellularModem( |
| 258 const dbus::ObjectPath& service_path, | 258 const dbus::ObjectPath& service_path, |
| 259 const std::string& carrier, | 259 const std::string& carrier, |
| 260 const base::Closure& callback, | 260 const base::Closure& callback, |
| 261 const ErrorCallback& error_callback) { | 261 const ErrorCallback& error_callback) { |
| 262 if (callback.is_null()) | 262 if (callback.is_null()) |
| 263 return; | 263 return; |
| 264 MessageLoop::current()->PostTask(FROM_HERE, callback); | 264 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void ShillServiceClientStub::CompleteCellularActivation( | 267 void ShillServiceClientStub::CompleteCellularActivation( |
| 268 const dbus::ObjectPath& service_path, | 268 const dbus::ObjectPath& service_path, |
| 269 const base::Closure& callback, | 269 const base::Closure& callback, |
| 270 const ErrorCallback& error_callback) { | 270 const ErrorCallback& error_callback) { |
| 271 if (callback.is_null()) | 271 if (callback.is_null()) |
| 272 return; | 272 return; |
| 273 MessageLoop::current()->PostTask(FROM_HERE, callback); | 273 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 274 } | 274 } |
| 275 | 275 |
| 276 bool ShillServiceClientStub::CallActivateCellularModemAndBlock( | 276 bool ShillServiceClientStub::CallActivateCellularModemAndBlock( |
| 277 const dbus::ObjectPath& service_path, | 277 const dbus::ObjectPath& service_path, |
| 278 const std::string& carrier) { | 278 const std::string& carrier) { |
| 279 return true; | 279 return true; |
| 280 } | 280 } |
| 281 | 281 |
| 282 ShillServiceClient::TestInterface* ShillServiceClientStub::GetTestInterface() { | 282 ShillServiceClient::TestInterface* ShillServiceClientStub::GetTestInterface() { |
| 283 return this; | 283 return this; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 446 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
| 447 observer_list_.find(device_path); | 447 observer_list_.find(device_path); |
| 448 if (iter != observer_list_.end()) | 448 if (iter != observer_list_.end()) |
| 449 return *(iter->second); | 449 return *(iter->second); |
| 450 PropertyObserverList* observer_list = new PropertyObserverList(); | 450 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 451 observer_list_[device_path] = observer_list; | 451 observer_list_[device_path] = observer_list; |
| 452 return *observer_list; | 452 return *observer_list; |
| 453 } | 453 } |
| 454 | 454 |
| 455 } // namespace chromeos | 455 } // namespace chromeos |
| OLD | NEW |