| 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 14 matching lines...) Expand all Loading... |
| 25 void ErrorFunction(const std::string& error_name, | 25 void ErrorFunction(const std::string& error_name, |
| 26 const std::string& error_message) { | 26 const std::string& error_message) { |
| 27 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; | 27 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; |
| 28 } | 28 } |
| 29 | 29 |
| 30 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback, | 30 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback, |
| 31 base::ListValue* value) { | 31 base::ListValue* value) { |
| 32 callback.Run(*value); | 32 callback.Run(*value); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void PassStubServiceProperties( |
| 36 const ShillServiceClient::DictionaryValueCallback& callback, |
| 37 DBusMethodCallStatus call_status, |
| 38 const base::DictionaryValue* properties) { |
| 39 callback.Run(call_status, *properties); |
| 40 } |
| 41 |
| 35 } // namespace | 42 } // namespace |
| 36 | 43 |
| 37 ShillServiceClientStub::ShillServiceClientStub() : weak_ptr_factory_(this) { | 44 ShillServiceClientStub::ShillServiceClientStub() : weak_ptr_factory_(this) { |
| 38 SetDefaultProperties(); | 45 SetDefaultProperties(); |
| 39 } | 46 } |
| 40 | 47 |
| 41 ShillServiceClientStub::~ShillServiceClientStub() { | 48 ShillServiceClientStub::~ShillServiceClientStub() { |
| 42 STLDeleteContainerPairSecondPointers( | 49 STLDeleteContainerPairSecondPointers( |
| 43 observer_list_.begin(), observer_list_.end()); | 50 observer_list_.begin(), observer_list_.end()); |
| 44 } | 51 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 const dbus::ObjectPath& service_path, | 62 const dbus::ObjectPath& service_path, |
| 56 ShillPropertyChangedObserver* observer) { | 63 ShillPropertyChangedObserver* observer) { |
| 57 GetObserverList(service_path).RemoveObserver(observer); | 64 GetObserverList(service_path).RemoveObserver(observer); |
| 58 } | 65 } |
| 59 | 66 |
| 60 void ShillServiceClientStub::GetProperties( | 67 void ShillServiceClientStub::GetProperties( |
| 61 const dbus::ObjectPath& service_path, | 68 const dbus::ObjectPath& service_path, |
| 62 const DictionaryValueCallback& callback) { | 69 const DictionaryValueCallback& callback) { |
| 63 if (callback.is_null()) | 70 if (callback.is_null()) |
| 64 return; | 71 return; |
| 72 |
| 73 base::DictionaryValue* nested_dict = NULL; |
| 74 scoped_ptr<base::DictionaryValue> result_properties; |
| 75 DBusMethodCallStatus call_status; |
| 76 stub_services_.GetDictionaryWithoutPathExpansion(service_path.value(), |
| 77 &nested_dict); |
| 78 if (nested_dict) { |
| 79 result_properties.reset(nested_dict->DeepCopy()); |
| 80 // Remove credentials that Shill wouldn't send. |
| 81 result_properties->RemoveWithoutPathExpansion(flimflam::kPassphraseProperty, |
| 82 NULL); |
| 83 call_status = DBUS_METHOD_CALL_SUCCESS; |
| 84 } else { |
| 85 result_properties.reset(new base::DictionaryValue); |
| 86 call_status = DBUS_METHOD_CALL_FAILURE; |
| 87 } |
| 88 |
| 65 MessageLoop::current()->PostTask( | 89 MessageLoop::current()->PostTask( |
| 66 FROM_HERE, | 90 FROM_HERE, |
| 67 base::Bind(&ShillServiceClientStub::PassStubServiceProperties, | 91 base::Bind(&PassStubServiceProperties, |
| 68 weak_ptr_factory_.GetWeakPtr(), | 92 callback, |
| 69 service_path, | 93 call_status, |
| 70 callback)); | 94 base::Owned(result_properties.release()))); |
| 71 } | 95 } |
| 72 | 96 |
| 73 void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path, | 97 void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path, |
| 74 const std::string& name, | 98 const std::string& name, |
| 75 const base::Value& value, | 99 const base::Value& value, |
| 76 const base::Closure& callback, | 100 const base::Closure& callback, |
| 77 const ErrorCallback& error_callback) { | 101 const ErrorCallback& error_callback) { |
| 78 base::DictionaryValue* dict = NULL; | 102 base::DictionaryValue* dict = NULL; |
| 79 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 103 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| 80 service_path.value(), &dict)) { | 104 service_path.value(), &dict)) { |
| 81 error_callback.Run("Error.InvalidService", "Invalid Service"); | 105 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 82 return; | 106 return; |
| 83 } | 107 } |
| 84 if (name == flimflam::kStateProperty) { | 108 if (name == flimflam::kStateProperty) { |
| 85 // If we connect to a service, then we move it to the top of the list in | 109 // If we connect to a service, then we move it to the top of the list in |
| 86 // the manager client. | 110 // the manager client. |
| 87 std::string state; | 111 std::string state; |
| 88 if (value.GetAsString(&state) && state == flimflam::kStateOnline) { | 112 if (value.GetAsString(&state) && state == flimflam::kStateOnline) { |
| 89 ShillManagerClient* manager_client = | 113 ShillManagerClient* manager_client = |
| 90 DBusThreadManager::Get()->GetShillManagerClient(); | 114 DBusThreadManager::Get()->GetShillManagerClient(); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 flimflam::kTypeVPN, | 391 flimflam::kTypeVPN, |
| 368 flimflam::kStateOnline, | 392 flimflam::kStateOnline, |
| 369 add_to_watchlist); | 393 add_to_watchlist); |
| 370 | 394 |
| 371 AddService("stub_vpn2", "vpn2", | 395 AddService("stub_vpn2", "vpn2", |
| 372 flimflam::kTypeVPN, | 396 flimflam::kTypeVPN, |
| 373 flimflam::kStateOffline, | 397 flimflam::kStateOffline, |
| 374 add_to_watchlist); | 398 add_to_watchlist); |
| 375 } | 399 } |
| 376 | 400 |
| 377 void ShillServiceClientStub::PassStubServiceProperties( | |
| 378 const dbus::ObjectPath& service_path, | |
| 379 const DictionaryValueCallback& callback) { | |
| 380 base::DictionaryValue* dict = NULL; | |
| 381 if (!stub_services_.GetDictionaryWithoutPathExpansion( | |
| 382 service_path.value(), &dict)) { | |
| 383 base::DictionaryValue empty_dictionary; | |
| 384 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); | |
| 385 return; | |
| 386 } | |
| 387 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dict); | |
| 388 } | |
| 389 | |
| 390 void ShillServiceClientStub::NotifyObserversPropertyChanged( | 401 void ShillServiceClientStub::NotifyObserversPropertyChanged( |
| 391 const dbus::ObjectPath& service_path, | 402 const dbus::ObjectPath& service_path, |
| 392 const std::string& property) { | 403 const std::string& property) { |
| 393 base::DictionaryValue* dict = NULL; | 404 base::DictionaryValue* dict = NULL; |
| 394 std::string path = service_path.value(); | 405 std::string path = service_path.value(); |
| 395 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &dict)) { | 406 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &dict)) { |
| 396 LOG(ERROR) << "Notify for unknown service: " << path; | 407 LOG(ERROR) << "Notify for unknown service: " << path; |
| 397 return; | 408 return; |
| 398 } | 409 } |
| 399 base::Value* value = NULL; | 410 base::Value* value = NULL; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 423 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 434 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
| 424 observer_list_.find(device_path); | 435 observer_list_.find(device_path); |
| 425 if (iter != observer_list_.end()) | 436 if (iter != observer_list_.end()) |
| 426 return *(iter->second); | 437 return *(iter->second); |
| 427 PropertyObserverList* observer_list = new PropertyObserverList(); | 438 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 428 observer_list_[device_path] = observer_list; | 439 observer_list_[device_path] = observer_list; |
| 429 return *observer_list; | 440 return *observer_list; |
| 430 } | 441 } |
| 431 | 442 |
| 432 } // namespace chromeos | 443 } // namespace chromeos |
| OLD | NEW |