[email protected] | 9b85bb82 | 2013-10-21 10:00:17 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 9b85bb82 | 2013-10-21 10:00:17 | [diff] [blame] | 5 | #ifndef CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_ |
| 6 | #define CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_ |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 7 | |
| 8 | #include <map> |
Hidehiko Abe | 5a138a2 | 2017-10-05 16:22:21 | [diff] [blame] | 9 | #include <memory> |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 10 | #include <string> |
Hidehiko Abe | 5a138a2 | 2017-10-05 16:22:21 | [diff] [blame] | 11 | #include <vector> |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 12 | |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 13 | #include "base/callback.h" |
Steven Bennetts | ab7b68e | 2019-01-07 19:14:43 | [diff] [blame] | 14 | #include "base/component_export.h" |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 15 | #include "base/macros.h" |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 17 | #include "chromeos/dbus/shill_service_client.h" |
| 18 | |
| 19 | namespace chromeos { |
| 20 | |
[email protected] | 9b85bb82 | 2013-10-21 10:00:17 | [diff] [blame] | 21 | // A fake implementation of ShillServiceClient. This works in close coordination |
| 22 | // with FakeShillManagerClient and is not intended to be used independently. |
Steven Bennetts | ab7b68e | 2019-01-07 19:14:43 | [diff] [blame] | 23 | class COMPONENT_EXPORT(CHROMEOS_DBUS) FakeShillServiceClient |
[email protected] | 4d201ec | 2014-03-05 19:54:40 | [diff] [blame] | 24 | : public ShillServiceClient, |
[email protected] | 9b85bb82 | 2013-10-21 10:00:17 | [diff] [blame] | 25 | public ShillServiceClient::TestInterface { |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 26 | public: |
[email protected] | 9b85bb82 | 2013-10-21 10:00:17 | [diff] [blame] | 27 | FakeShillServiceClient(); |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 28 | ~FakeShillServiceClient() override; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 29 | |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 30 | // ShillServiceClient overrides |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 31 | void Init(dbus::Bus* bus) override; |
| 32 | void AddPropertyChangedObserver( |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 33 | const dbus::ObjectPath& service_path, |
mostynb | 4f4cf14 | 2014-10-06 13:57:52 | [diff] [blame] | 34 | ShillPropertyChangedObserver* observer) override; |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 35 | void RemovePropertyChangedObserver( |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 36 | const dbus::ObjectPath& service_path, |
mostynb | 4f4cf14 | 2014-10-06 13:57:52 | [diff] [blame] | 37 | ShillPropertyChangedObserver* observer) override; |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 38 | void GetProperties(const dbus::ObjectPath& service_path, |
| 39 | const DictionaryValueCallback& callback) override; |
| 40 | void SetProperty(const dbus::ObjectPath& service_path, |
| 41 | const std::string& name, |
| 42 | const base::Value& value, |
| 43 | const base::Closure& callback, |
| 44 | const ErrorCallback& error_callback) override; |
| 45 | void SetProperties(const dbus::ObjectPath& service_path, |
| 46 | const base::DictionaryValue& properties, |
| 47 | const base::Closure& callback, |
| 48 | const ErrorCallback& error_callback) override; |
| 49 | void ClearProperty(const dbus::ObjectPath& service_path, |
| 50 | const std::string& name, |
| 51 | const base::Closure& callback, |
| 52 | const ErrorCallback& error_callback) override; |
| 53 | void ClearProperties(const dbus::ObjectPath& service_path, |
| 54 | const std::vector<std::string>& names, |
| 55 | const ListValueCallback& callback, |
mostynb | 4f4cf14 | 2014-10-06 13:57:52 | [diff] [blame] | 56 | const ErrorCallback& error_callback) override; |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 57 | void Connect(const dbus::ObjectPath& service_path, |
| 58 | const base::Closure& callback, |
| 59 | const ErrorCallback& error_callback) override; |
| 60 | void Disconnect(const dbus::ObjectPath& service_path, |
| 61 | const base::Closure& callback, |
| 62 | const ErrorCallback& error_callback) override; |
| 63 | void Remove(const dbus::ObjectPath& service_path, |
| 64 | const base::Closure& callback, |
| 65 | const ErrorCallback& error_callback) override; |
| 66 | void ActivateCellularModem(const dbus::ObjectPath& service_path, |
| 67 | const std::string& carrier, |
| 68 | const base::Closure& callback, |
| 69 | const ErrorCallback& error_callback) override; |
| 70 | void CompleteCellularActivation(const dbus::ObjectPath& service_path, |
| 71 | const base::Closure& callback, |
| 72 | const ErrorCallback& error_callback) override; |
| 73 | void GetLoadableProfileEntries( |
[email protected] | 7c8fd564 | 2013-07-02 22:24:30 | [diff] [blame] | 74 | const dbus::ObjectPath& service_path, |
mostynb | 4f4cf14 | 2014-10-06 13:57:52 | [diff] [blame] | 75 | const DictionaryValueCallback& callback) override; |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 76 | ShillServiceClient::TestInterface* GetTestInterface() override; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 77 | |
| 78 | // ShillServiceClient::TestInterface overrides. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 79 | void AddService(const std::string& service_path, |
| 80 | const std::string& guid, |
| 81 | const std::string& name, |
| 82 | const std::string& type, |
| 83 | const std::string& state, |
| 84 | bool visible) override; |
| 85 | void AddServiceWithIPConfig(const std::string& service_path, |
| 86 | const std::string& guid, |
| 87 | const std::string& name, |
| 88 | const std::string& type, |
| 89 | const std::string& state, |
| 90 | const std::string& ipconfig_path, |
| 91 | bool visible) override; |
| 92 | base::DictionaryValue* SetServiceProperties(const std::string& service_path, |
| 93 | const std::string& guid, |
| 94 | const std::string& name, |
| 95 | const std::string& type, |
| 96 | const std::string& state, |
| 97 | bool visible) override; |
| 98 | void RemoveService(const std::string& service_path) override; |
| 99 | bool SetServiceProperty(const std::string& service_path, |
| 100 | const std::string& property, |
| 101 | const base::Value& value) override; |
| 102 | const base::DictionaryValue* GetServiceProperties( |
mostynb | 4f4cf14 | 2014-10-06 13:57:52 | [diff] [blame] | 103 | const std::string& service_path) const override; |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 104 | void ClearServices() override; |
| 105 | void SetConnectBehavior(const std::string& service_path, |
| 106 | const base::Closure& behavior) override; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 107 | |
| 108 | private: |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 109 | typedef base::ObserverList<ShillPropertyChangedObserver>::Unchecked |
| 110 | PropertyObserverList; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 111 | |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 112 | void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path, |
| 113 | const std::string& property); |
[email protected] | fde8b32 | 2013-02-28 17:44:24 | [diff] [blame] | 114 | base::DictionaryValue* GetModifiableServiceProperties( |
[email protected] | 54287ec | 2013-09-23 18:40:02 | [diff] [blame] | 115 | const std::string& service_path, |
| 116 | bool create_if_missing); |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 117 | PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path); |
[email protected] | 783aa24d | 2013-08-06 23:54:38 | [diff] [blame] | 118 | void SetOtherServicesOffline(const std::string& service_path); |
[email protected] | 5fd84cc9 | 2013-08-14 02:35:50 | [diff] [blame] | 119 | void SetCellularActivated(const dbus::ObjectPath& service_path, |
| 120 | const ErrorCallback& error_callback); |
[email protected] | 54287ec | 2013-09-23 18:40:02 | [diff] [blame] | 121 | void ContinueConnect(const std::string& service_path); |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 122 | |
| 123 | base::DictionaryValue stub_services_; |
[email protected] | 54287ec | 2013-09-23 18:40:02 | [diff] [blame] | 124 | |
| 125 | // Per network service, stores a closure that is executed on each connection |
| 126 | // attempt. The callback can for example modify the services properties in |
| 127 | // order to simulate a connection failure. |
| 128 | std::map<std::string, base::Closure> connect_behavior_; |
| 129 | |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 130 | // Observer list for each service. |
avi | 8194ad6 | 2016-09-20 16:58:36 | [diff] [blame] | 131 | std::map<dbus::ObjectPath, std::unique_ptr<PropertyObserverList>> |
| 132 | observer_list_; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 133 | |
| 134 | // Note: This should remain the last member so it'll be destroyed and |
| 135 | // invalidate its weak pointers before any other members are destroyed. |
[email protected] | 9b85bb82 | 2013-10-21 10:00:17 | [diff] [blame] | 136 | base::WeakPtrFactory<FakeShillServiceClient> weak_ptr_factory_; |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 137 | |
[email protected] | 9b85bb82 | 2013-10-21 10:00:17 | [diff] [blame] | 138 | DISALLOW_COPY_AND_ASSIGN(FakeShillServiceClient); |
[email protected] | 4a5ddd205 | 2013-02-14 23:54:00 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | } // namespace chromeos |
| 142 | |
[email protected] | 9b85bb82 | 2013-10-21 10:00:17 | [diff] [blame] | 143 | #endif // CHROMEOS_DBUS_FAKE_SHILL_SERVICE_CLIENT_H_ |