[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_STUB_H_ |
| 6 | #define CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_STUB_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/basictypes.h" |
| 12 | #include "base/callback.h" |
| 13 | #include "base/memory/weak_ptr.h" |
[email protected] | 6b3328b | 2013-08-12 22:30:24 | [diff] [blame] | 14 | #include "chromeos/chromeos_export.h" |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 15 | #include "chromeos/dbus/shill_service_client.h" |
| 16 | |
| 17 | namespace chromeos { |
| 18 | |
[email protected] | 5341905 | 2013-05-14 04:37:56 | [diff] [blame] | 19 | // A stub implementation of ShillServiceClient. This works in close coordination |
| 20 | // with ShillManagerClientStub and is not intended to be used independently. |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 21 | class ShillServiceClientStub : public ShillServiceClient, |
| 22 | public ShillServiceClient::TestInterface { |
| 23 | public: |
| 24 | ShillServiceClientStub(); |
| 25 | virtual ~ShillServiceClientStub(); |
| 26 | |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 27 | // ShillServiceClient overrides |
| 28 | virtual void Init(dbus::Bus* bus) OVERRIDE; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 29 | virtual void AddPropertyChangedObserver( |
| 30 | const dbus::ObjectPath& service_path, |
| 31 | ShillPropertyChangedObserver* observer) OVERRIDE; |
| 32 | virtual void RemovePropertyChangedObserver( |
| 33 | const dbus::ObjectPath& service_path, |
| 34 | ShillPropertyChangedObserver* observer) OVERRIDE; |
| 35 | virtual void GetProperties(const dbus::ObjectPath& service_path, |
| 36 | const DictionaryValueCallback& callback) OVERRIDE; |
| 37 | virtual void SetProperty(const dbus::ObjectPath& service_path, |
| 38 | const std::string& name, |
| 39 | const base::Value& value, |
| 40 | const base::Closure& callback, |
| 41 | const ErrorCallback& error_callback) OVERRIDE; |
[email protected] | e499e67 | 2013-07-10 18:51:24 | [diff] [blame] | 42 | virtual void SetProperties(const dbus::ObjectPath& service_path, |
| 43 | const base::DictionaryValue& properties, |
| 44 | const base::Closure& callback, |
| 45 | const ErrorCallback& error_callback) OVERRIDE; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 46 | virtual void ClearProperty(const dbus::ObjectPath& service_path, |
| 47 | const std::string& name, |
| 48 | const base::Closure& callback, |
| 49 | const ErrorCallback& error_callback) OVERRIDE; |
| 50 | virtual void ClearProperties(const dbus::ObjectPath& service_path, |
| 51 | const std::vector<std::string>& names, |
| 52 | const ListValueCallback& callback, |
| 53 | const ErrorCallback& error_callback) OVERRIDE; |
| 54 | virtual void Connect(const dbus::ObjectPath& service_path, |
| 55 | const base::Closure& callback, |
| 56 | const ErrorCallback& error_callback) OVERRIDE; |
| 57 | virtual void Disconnect(const dbus::ObjectPath& service_path, |
| 58 | const base::Closure& callback, |
| 59 | const ErrorCallback& error_callback) OVERRIDE; |
| 60 | virtual void Remove(const dbus::ObjectPath& service_path, |
| 61 | const base::Closure& callback, |
| 62 | const ErrorCallback& error_callback) OVERRIDE; |
| 63 | virtual void ActivateCellularModem( |
| 64 | const dbus::ObjectPath& service_path, |
| 65 | const std::string& carrier, |
| 66 | const base::Closure& callback, |
| 67 | const ErrorCallback& error_callback) OVERRIDE; |
[email protected] | 4cd3819 | 2013-02-16 07:54:18 | [diff] [blame] | 68 | virtual void CompleteCellularActivation( |
| 69 | const dbus::ObjectPath& service_path, |
| 70 | const base::Closure& callback, |
| 71 | const ErrorCallback& error_callback) OVERRIDE; |
[email protected] | 7c8fd564 | 2013-07-02 22:24:30 | [diff] [blame] | 72 | virtual void GetLoadableProfileEntries( |
| 73 | const dbus::ObjectPath& service_path, |
| 74 | const DictionaryValueCallback& callback) OVERRIDE; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 75 | virtual ShillServiceClient::TestInterface* GetTestInterface() OVERRIDE; |
| 76 | |
| 77 | // ShillServiceClient::TestInterface overrides. |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 78 | virtual void AddService(const std::string& service_path, |
| 79 | const std::string& name, |
| 80 | const std::string& type, |
[email protected] | fde8b32 | 2013-02-28 17:44:24 | [diff] [blame] | 81 | const std::string& state, |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 82 | bool add_to_visible_list, |
[email protected] | fde8b32 | 2013-02-28 17:44:24 | [diff] [blame] | 83 | bool add_to_watch_list) OVERRIDE; |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 84 | virtual void AddServiceWithIPConfig(const std::string& service_path, |
| 85 | const std::string& name, |
| 86 | const std::string& type, |
| 87 | const std::string& state, |
| 88 | const std::string& ipconfig_path, |
[email protected] | ce21fc6 | 2013-07-03 10:45:58 | [diff] [blame] | 89 | bool add_to_visible_list, |
[email protected] | 362fb22 | 2013-04-02 23:24:28 | [diff] [blame] | 90 | bool add_to_watch_list) OVERRIDE; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 91 | virtual void RemoveService(const std::string& service_path) OVERRIDE; |
[email protected] | e499e67 | 2013-07-10 18:51:24 | [diff] [blame] | 92 | virtual bool SetServiceProperty(const std::string& service_path, |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 93 | const std::string& property, |
| 94 | const base::Value& value) OVERRIDE; |
[email protected] | fde8b32 | 2013-02-28 17:44:24 | [diff] [blame] | 95 | virtual const base::DictionaryValue* GetServiceProperties( |
| 96 | const std::string& service_path) const OVERRIDE; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 97 | virtual void ClearServices() OVERRIDE; |
[email protected] | 54287ec | 2013-09-23 18:40:02 | [diff] [blame^] | 98 | virtual void SetConnectBehavior(const std::string& service_path, |
| 99 | const base::Closure& behavior) OVERRIDE; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 100 | |
| 101 | private: |
| 102 | typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList; |
| 103 | |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 104 | void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path, |
| 105 | const std::string& property); |
[email protected] | fde8b32 | 2013-02-28 17:44:24 | [diff] [blame] | 106 | base::DictionaryValue* GetModifiableServiceProperties( |
[email protected] | 54287ec | 2013-09-23 18:40:02 | [diff] [blame^] | 107 | const std::string& service_path, |
| 108 | bool create_if_missing); |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 109 | PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path); |
[email protected] | 783aa24d | 2013-08-06 23:54:38 | [diff] [blame] | 110 | void SetOtherServicesOffline(const std::string& service_path); |
[email protected] | 5fd84cc9 | 2013-08-14 02:35:50 | [diff] [blame] | 111 | void SetCellularActivated(const dbus::ObjectPath& service_path, |
| 112 | const ErrorCallback& error_callback); |
[email protected] | 54287ec | 2013-09-23 18:40:02 | [diff] [blame^] | 113 | void ContinueConnect(const std::string& service_path); |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 114 | |
| 115 | base::DictionaryValue stub_services_; |
[email protected] | 54287ec | 2013-09-23 18:40:02 | [diff] [blame^] | 116 | |
| 117 | // Per network service, stores a closure that is executed on each connection |
| 118 | // attempt. The callback can for example modify the services properties in |
| 119 | // order to simulate a connection failure. |
| 120 | std::map<std::string, base::Closure> connect_behavior_; |
| 121 | |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 122 | // Observer list for each service. |
| 123 | std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_; |
| 124 | |
| 125 | // Note: This should remain the last member so it'll be destroyed and |
| 126 | // invalidate its weak pointers before any other members are destroyed. |
| 127 | base::WeakPtrFactory<ShillServiceClientStub> weak_ptr_factory_; |
| 128 | |
| 129 | DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStub); |
| 130 | }; |
| 131 | |
| 132 | } // namespace chromeos |
| 133 | |
| 134 | #endif // CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_STUB_H_ |