| 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 #ifndef CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_STUB_H_ | 5 #ifndef CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_STUB_H_ |
| 6 #define CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_STUB_H_ | 6 #define CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_STUB_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/dbus/shill_service_client.h" | 15 #include "chromeos/dbus/shill_service_client.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 // A stub implementation of ShillServiceClient. This works in close coordination | 19 // A stub implementation of ShillServiceClient. This works in close coordination |
| 20 // with ShillManagerClientStub and is not intended to be used independently. | 20 // with ShillManagerClientStub and is not intended to be used independently. |
| 21 class ShillServiceClientStub : public ShillServiceClient, | 21 class ShillServiceClientStub : public ShillServiceClient, |
| 22 public ShillServiceClient::TestInterface { | 22 public ShillServiceClient::TestInterface { |
| 23 public: | 23 public: |
| 24 ShillServiceClientStub(); | 24 ShillServiceClientStub(); |
| 25 virtual ~ShillServiceClientStub(); | 25 virtual ~ShillServiceClientStub(); |
| 26 | 26 |
| 27 // Returns true when stub portalled wifi is enabled and it's service | |
| 28 // path equals to |path|. | |
| 29 CHROMEOS_EXPORT static bool IsStubPortalledWifiEnabled( | |
| 30 const std::string& path); | |
| 31 | |
| 32 // ShillServiceClient overrides | 27 // ShillServiceClient overrides |
| 33 virtual void Init(dbus::Bus* bus) OVERRIDE; | 28 virtual void Init(dbus::Bus* bus) OVERRIDE; |
| 34 virtual void AddPropertyChangedObserver( | 29 virtual void AddPropertyChangedObserver( |
| 35 const dbus::ObjectPath& service_path, | 30 const dbus::ObjectPath& service_path, |
| 36 ShillPropertyChangedObserver* observer) OVERRIDE; | 31 ShillPropertyChangedObserver* observer) OVERRIDE; |
| 37 virtual void RemovePropertyChangedObserver( | 32 virtual void RemovePropertyChangedObserver( |
| 38 const dbus::ObjectPath& service_path, | 33 const dbus::ObjectPath& service_path, |
| 39 ShillPropertyChangedObserver* observer) OVERRIDE; | 34 ShillPropertyChangedObserver* observer) OVERRIDE; |
| 40 virtual void GetProperties(const dbus::ObjectPath& service_path, | 35 virtual void GetProperties(const dbus::ObjectPath& service_path, |
| 41 const DictionaryValueCallback& callback) OVERRIDE; | 36 const DictionaryValueCallback& callback) OVERRIDE; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 virtual void CompleteCellularActivation( | 68 virtual void CompleteCellularActivation( |
| 74 const dbus::ObjectPath& service_path, | 69 const dbus::ObjectPath& service_path, |
| 75 const base::Closure& callback, | 70 const base::Closure& callback, |
| 76 const ErrorCallback& error_callback) OVERRIDE; | 71 const ErrorCallback& error_callback) OVERRIDE; |
| 77 virtual void GetLoadableProfileEntries( | 72 virtual void GetLoadableProfileEntries( |
| 78 const dbus::ObjectPath& service_path, | 73 const dbus::ObjectPath& service_path, |
| 79 const DictionaryValueCallback& callback) OVERRIDE; | 74 const DictionaryValueCallback& callback) OVERRIDE; |
| 80 virtual ShillServiceClient::TestInterface* GetTestInterface() OVERRIDE; | 75 virtual ShillServiceClient::TestInterface* GetTestInterface() OVERRIDE; |
| 81 | 76 |
| 82 // ShillServiceClient::TestInterface overrides. | 77 // ShillServiceClient::TestInterface overrides. |
| 83 virtual void AddDefaultServices() OVERRIDE; | |
| 84 virtual void AddService(const std::string& service_path, | 78 virtual void AddService(const std::string& service_path, |
| 85 const std::string& name, | 79 const std::string& name, |
| 86 const std::string& type, | 80 const std::string& type, |
| 87 const std::string& state, | 81 const std::string& state, |
| 88 bool add_to_visible_list, | 82 bool add_to_visible_list, |
| 89 bool add_to_watch_list) OVERRIDE; | 83 bool add_to_watch_list) OVERRIDE; |
| 90 virtual void AddServiceWithIPConfig(const std::string& service_path, | 84 virtual void AddServiceWithIPConfig(const std::string& service_path, |
| 91 const std::string& name, | 85 const std::string& name, |
| 92 const std::string& type, | 86 const std::string& type, |
| 93 const std::string& state, | 87 const std::string& state, |
| 94 const std::string& ipconfig_path, | 88 const std::string& ipconfig_path, |
| 95 bool add_to_visible_list, | 89 bool add_to_visible_list, |
| 96 bool add_to_watch_list) OVERRIDE; | 90 bool add_to_watch_list) OVERRIDE; |
| 97 virtual void RemoveService(const std::string& service_path) OVERRIDE; | 91 virtual void RemoveService(const std::string& service_path) OVERRIDE; |
| 98 virtual bool SetServiceProperty(const std::string& service_path, | 92 virtual bool SetServiceProperty(const std::string& service_path, |
| 99 const std::string& property, | 93 const std::string& property, |
| 100 const base::Value& value) OVERRIDE; | 94 const base::Value& value) OVERRIDE; |
| 101 virtual const base::DictionaryValue* GetServiceProperties( | 95 virtual const base::DictionaryValue* GetServiceProperties( |
| 102 const std::string& service_path) const OVERRIDE; | 96 const std::string& service_path) const OVERRIDE; |
| 103 virtual void ClearServices() OVERRIDE; | 97 virtual void ClearServices() OVERRIDE; |
| 98 virtual void SetConnectBehavior(const std::string& service_path, |
| 99 const base::Closure& behavior) OVERRIDE; |
| 104 | 100 |
| 105 private: | 101 private: |
| 106 typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList; | 102 typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList; |
| 107 | 103 |
| 108 void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path, | 104 void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path, |
| 109 const std::string& property); | 105 const std::string& property); |
| 110 base::DictionaryValue* GetModifiableServiceProperties( | 106 base::DictionaryValue* GetModifiableServiceProperties( |
| 111 const std::string& service_path); | 107 const std::string& service_path, |
| 108 bool create_if_missing); |
| 112 PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path); | 109 PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path); |
| 113 void SetOtherServicesOffline(const std::string& service_path); | 110 void SetOtherServicesOffline(const std::string& service_path); |
| 114 void SetCellularActivated(const dbus::ObjectPath& service_path, | 111 void SetCellularActivated(const dbus::ObjectPath& service_path, |
| 115 const ErrorCallback& error_callback); | 112 const ErrorCallback& error_callback); |
| 113 void ContinueConnect(const std::string& service_path); |
| 116 | 114 |
| 117 base::DictionaryValue stub_services_; | 115 base::DictionaryValue stub_services_; |
| 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 |
| 118 // Observer list for each service. | 122 // Observer list for each service. |
| 119 std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_; | 123 std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_; |
| 120 | 124 |
| 121 // Note: This should remain the last member so it'll be destroyed and | 125 // Note: This should remain the last member so it'll be destroyed and |
| 122 // invalidate its weak pointers before any other members are destroyed. | 126 // invalidate its weak pointers before any other members are destroyed. |
| 123 base::WeakPtrFactory<ShillServiceClientStub> weak_ptr_factory_; | 127 base::WeakPtrFactory<ShillServiceClientStub> weak_ptr_factory_; |
| 124 | 128 |
| 125 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStub); | 129 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStub); |
| 126 }; | 130 }; |
| 127 | 131 |
| 128 } // namespace chromeos | 132 } // namespace chromeos |
| 129 | 133 |
| 130 #endif // CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_STUB_H_ | 134 #endif // CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_STUB_H_ |
| OLD | NEW |