Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ | |
| 6 #define CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <map> | |
| 10 #include <set> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 15 #include "chromeos/dbus/shill_property_changed_observer.h" | |
| 16 #include "chromeos/network/managed_state.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class DictionaryValue; | |
| 20 class ListValue; | |
| 21 class Value; | |
| 22 } | |
| 23 | |
| 24 namespace chromeos { | |
| 25 | |
| 26 class ShillManagerClient; | |
| 27 | |
| 28 namespace internal { | |
| 29 | |
| 30 class ShillServiceObserver; | |
| 31 | |
| 32 // This class handles Shill calls and observers to reflect the state of the | |
| 33 // Shill Manager and its services and devices. It observes Shill.Manager and | |
| 34 // requests properties for new devices/networks.It takes a Listener in its | |
|
gauravsh
2012/11/06 22:51:41
NIT: space before It
stevenjb
2012/11/07 01:38:13
Done.
| |
| 35 // constructor (e.g. NetworkStateHandler) that it calls when properties change | |
| 36 // (including once to set their initial state after Init() gets called). | |
| 37 // It also observes Shill.Service for all services in Manager.ServiceWatchList. | |
| 38 // This class must not outlive the ShillManagerClient instance. | |
| 39 class CHROMEOS_EXPORT ShillPropertyHandler | |
| 40 : public ShillPropertyChangedObserver { | |
| 41 public: | |
| 42 typedef std::map<std::string, ShillServiceObserver*> ShillServiceObserverMap; | |
| 43 | |
| 44 class CHROMEOS_EXPORT Listener { | |
| 45 public: | |
| 46 // Called when the entries in a managed list have changed. | |
| 47 virtual void UpdateManagedList(ManagedState::ManagedType type, | |
| 48 const base::ListValue& entries) = 0; | |
| 49 | |
| 50 // Called when the available technologies are set or have changed. | |
| 51 virtual void UpdateAvailableTechnologies( | |
| 52 const base::ListValue& technologies) = 0; | |
| 53 | |
| 54 // Called when the enabled technologies are set or have changed. | |
| 55 virtual void UpdateEnabledTechnologies( | |
| 56 const base::ListValue& technologies) = 0; | |
| 57 | |
| 58 // Called when the properties for a managed state have changed. | |
| 59 virtual void UpdateManagedStateProperties( | |
| 60 ManagedState::ManagedType type, | |
| 61 const std::string& path, | |
| 62 const base::DictionaryValue& properties) = 0; | |
| 63 | |
| 64 // Called when a property for a watched network service has changed. | |
| 65 virtual void UpdateNetworkServiceProperty( | |
| 66 const std::string& service_path, | |
| 67 const std::string& key, | |
| 68 const base::Value& value) = 0; | |
| 69 | |
| 70 // Called when one or more manager properties (e.g. a technology list) | |
| 71 // changes. | |
| 72 virtual void ManagerPropertyChanged() = 0; | |
| 73 | |
| 74 // Called whent the IP address of a service has been updated. Occurs after | |
| 75 // UpdateManagedStateProperties is called for the service. | |
| 76 virtual void UpdateNetworkServiceIPAddress( | |
| 77 const std::string& service_path, | |
| 78 const std::string& ip_address) = 0; | |
| 79 | |
| 80 // Called when a managed state list has changed, after properties for any | |
| 81 // new entries in the list have been received and | |
| 82 // UpdateManagedStateProperties has been called for each new entry. | |
| 83 virtual void ManagedStateListChanged(ManagedState::ManagedType type) = 0; | |
| 84 | |
| 85 protected: | |
| 86 virtual ~Listener() {} | |
| 87 }; | |
| 88 | |
| 89 explicit ShillPropertyHandler(Listener* listener); | |
| 90 virtual ~ShillPropertyHandler(); | |
| 91 | |
| 92 // Sends an initial property request and sets up the observer. | |
| 93 void Init(); | |
| 94 | |
| 95 // Asynchronously sets the enabled state for |technology|. | |
| 96 // Note: Modifes Manager state. TODO(stevenjb): Add a completion callback. | |
| 97 void SetTechnologyEnabled(const std::string& technology, bool enabled); | |
| 98 | |
| 99 // Requests an immediate network scan. | |
| 100 void RequestScan() const; | |
| 101 | |
| 102 // Requests all properties for the service or device (called for new items). | |
| 103 void RequestProperties(ManagedState::ManagedType type, | |
| 104 const std::string& path); | |
| 105 | |
| 106 // Requests the IP config specified by |ip_config_path| for |service_path|. | |
| 107 void RequestIPConfig(const std::string& service_path, | |
| 108 const std::string& ip_config_path); | |
| 109 | |
| 110 bool IsObservingNetwork(const std::string& service_path) { | |
| 111 return observed_networks_.count(service_path) != 0; | |
| 112 } | |
| 113 | |
| 114 // ShillPropertyChangedObserver overrides | |
| 115 virtual void OnPropertyChanged(const std::string& key, | |
| 116 const base::Value& value) OVERRIDE; | |
| 117 | |
| 118 private: | |
| 119 // Callback for dbus method fetching properties. | |
| 120 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, | |
| 121 const base::DictionaryValue& properties); | |
| 122 // Called form OnPropertyChanged() and ManagerPropertiesCallback(). | |
| 123 // Returns true if observers should be notified. | |
| 124 bool ManagerPropertyChanged(const std::string& key, const base::Value& value); | |
| 125 | |
| 126 // Calls listener_->UpdateManagedList and triggers ManagedStateListChanged if | |
| 127 // no new property requests have been made. | |
| 128 void UpdateManagedList(ManagedState::ManagedType type, | |
| 129 const base::ListValue& entries); | |
| 130 | |
| 131 // Updates the Shill service property observers to observe any entries | |
| 132 // in the service watch list. | |
| 133 void UpdateObservedNetworkServices(const base::ListValue& entries); | |
| 134 | |
| 135 // Called when Shill returns the properties for a service or device. | |
| 136 void GetPropertiesCallback(ManagedState::ManagedType type, | |
| 137 const std::string& path, | |
| 138 DBusMethodCallStatus call_status, | |
| 139 const base::DictionaryValue& properties); | |
| 140 | |
| 141 // Callback invoked when a watched service property changes. Calls | |
| 142 // network->PropertyChanged(key, value) and signals observers. | |
| 143 void NetworkServicePropertyChangedCallback(const std::string& path, | |
| 144 const std::string& key, | |
| 145 const base::Value& value); | |
| 146 | |
| 147 // Callback for getting the IPConfig property of a Network. Handled here | |
| 148 // instead of in NetworkState so that all asynchronous requests are done | |
| 149 // in a single place (also simplifies NetworkState considerably). | |
| 150 void GetIPConfigCallback(const std::string& service_path, | |
| 151 DBusMethodCallStatus call_status, | |
| 152 const base::DictionaryValue& properties); | |
| 153 | |
| 154 // Pointer to containing class (owns this) | |
| 155 Listener* listener_; | |
| 156 | |
| 157 // Convenience pointer for ShillManagerClient | |
| 158 ShillManagerClient* shill_manager_; | |
| 159 | |
| 160 // Pending update count for each managed state type | |
| 161 std::map<ManagedState::ManagedType, int> pending_updates_; | |
| 162 | |
| 163 // List of network services with Shill property changed observers | |
| 164 ShillServiceObserverMap observed_networks_; | |
| 165 | |
| 166 // For Shill client callbacks | |
| 167 base::WeakPtrFactory<ShillPropertyHandler> weak_ptr_factory_; | |
| 168 | |
| 169 DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandler); | |
| 170 }; | |
| 171 | |
| 172 } // namespace internal | |
| 173 } // namespace chromeos | |
| 174 | |
| 175 #endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ | |
| OLD | NEW |