Chromium Code Reviews| Index: chromeos/network/shill_property_handler.h |
| diff --git a/chromeos/network/shill_property_handler.h b/chromeos/network/shill_property_handler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..81aec853531cd6d28345437eafe05845764025a6 |
| --- /dev/null |
| +++ b/chromeos/network/shill_property_handler.h |
| @@ -0,0 +1,172 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ |
| +#define CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ |
| + |
| +#include <list> |
| +#include <map> |
| +#include <set> |
| +#include <string> |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "chromeos/dbus/dbus_method_call_status.h" |
| +#include "chromeos/dbus/shill_property_changed_observer.h" |
| +#include "chromeos/network/managed_state.h" |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +class ListValue; |
| +class Value; |
| +} |
| + |
| +namespace chromeos { |
| + |
| +class ShillServiceObserver; |
| +class ShillManagerClient; |
| + |
| +namespace internal { |
| + |
| +// This class handles all Shill calls and observers for a Delegate (e.g. |
| +// NetworkStateHandler). It observes Shill.Manager and requests properties |
| +// for new devices/networks, calling Delegate methods to track them. It also |
| +// observes Shill.Service for all services in Shill.Manager.ServiceWatchList |
| +// and calls Delegate methods with updates. |
| +// This class must not outlive the ShillManagerClient instance. |
| +class CHROMEOS_EXPORT ShillPropertyHandler |
| + : public ShillPropertyChangedObserver { |
| + public: |
| + typedef std::map<std::string, ShillServiceObserver*> ShillServiceObserverMap; |
| + |
| + class CHROMEOS_EXPORT Delegate { |
|
gauravsh
2012/11/06 01:56:59
I agree with Steven that ChangeListener/Listener w
stevenjb
2012/11/06 03:17:03
Done.
|
| + public: |
| + // Called when the entries in a managed list have changed. |
| + virtual void UpdateManagedList(ManagedState::ManagedType type, |
| + const base::ListValue& entries) = 0; |
| + |
| + // Called when the available technologies are set or have changed. |
| + virtual void UpdateAvailableTechnologies( |
| + const base::ListValue& technologies) = 0; |
| + |
| + // Called when the enabled technologies are set or have changed. |
| + virtual void UpdateEnabledTechnologies( |
| + const base::ListValue& technologies) = 0; |
| + |
| + // Called when the properties for a managed state have changed. |
| + virtual void UpdateManagedStateProperties( |
| + ManagedState::ManagedType type, |
| + const std::string& path, |
| + const base::DictionaryValue& properties) = 0; |
| + |
| + // Called when a property for a watched network service has changed. |
| + virtual void UpdateNetworkServiceProperty( |
| + const std::string& service_path, |
| + const std::string& key, |
| + const base::Value& value) = 0; |
| + |
| + // Called after updating a technology list. |
| + virtual void ManagerPropertyChanged() = 0; |
|
gauravsh
2012/11/06 01:56:59
If the intention is to only have this be called wh
stevenjb
2012/11/06 03:17:03
Changed the comment; at the moment this gets calle
|
| + |
| + // Called whent the IP address of a service has been updated. Occurs after |
| + // UpdateManagedStateProperties is called for the service. |
| + virtual void UpdateNetworkServiceIPAddress( |
| + const std::string& service_path, |
| + const std::string& ip_address) = 0; |
| + |
| + // Called when a managed state list has changed, after properties for any |
| + // new entries in the list have been received and |
| + // UpdateManagedStateProperties has been called for each new entry. |
| + virtual void ManagedStateListChanged(ManagedState::ManagedType type) = 0; |
| + |
| + protected: |
| + virtual ~Delegate() {} |
| + }; |
| + |
| + explicit ShillPropertyHandler(Delegate* delegate); |
| + virtual ~ShillPropertyHandler(); |
| + |
| + // Sends an initial property request and sets up the observer. |
| + void Init(); |
| + |
| + // Asynchronously sets the enabled state for |technology|. |
| + // Note: Modifes Manager state. TODO(stevenjb): Add a completion callback. |
| + void SetTechnologyEnabled(const std::string& technology, bool enabled); |
| + |
| + // Requests an immediate network scan. |
| + void RequestScan() const; |
| + |
| + // Requests all properties for the service or device (called for new items). |
| + void RequestProperties(ManagedState::ManagedType type, |
| + const std::string& path); |
| + |
| + // Requests the IP config specified by |ip_config_path| for |service_path|. |
| + void RequestIPConfig(const std::string& service_path, |
| + const std::string& ip_config_path); |
| + |
| + bool IsObservingNetwork(const std::string& service_path) { |
| + return observed_networks_.count(service_path) != 0; |
| + } |
| + |
| + // ShillPropertyChangedObserver overrides |
| + virtual void OnPropertyChanged(const std::string& key, |
| + const base::Value& value) OVERRIDE; |
| + |
| + private: |
| + // Callback for dbus method fetching properties. |
| + void ManagerPropertiesCallback(DBusMethodCallStatus call_status, |
| + const base::DictionaryValue& properties); |
| + // Called form OnPropertyChanged() and ManagerPropertiesCallback(). |
| + // Returns true if observers should be notified. |
| + bool ManagerPropertyChanged(const std::string& key, const base::Value& value); |
| + |
| + // Calls delegate_->UpdateManagedList and triggers ManagedStateListChanged if |
| + // no new property requests have been made. |
| + void UpdateManagedList(ManagedState::ManagedType type, |
| + const base::ListValue& entries); |
| + |
| + // Updates the Shill service property observers to observe any entries |
| + // in the service watch list. |
| + void UpdateObservedNetworkServices(const base::ListValue& entries); |
| + |
| + // Called when Shill returns the properties for a service or device. |
| + void GetPropertiesCallback(ManagedState::ManagedType type, |
| + const std::string& path, |
| + DBusMethodCallStatus call_status, |
| + const base::DictionaryValue& properties); |
| + |
| + // Callback invoked when a watched service property changes. Calls |
| + // network->PropertyChanged(key, value) and signals observers. |
| + void NetworkServicePropertyChangedCallback(const std::string& path, |
| + const std::string& key, |
| + const base::Value& value); |
| + |
| + // Callback for getting the IPConfig property of a Network. Handled here |
| + // instead of in NetworkState so that all asynchronous requests are done |
| + // in a single place (also simplifies NetworkState considerably). |
| + void GetIPConfigCallback(const std::string& service_path, |
| + DBusMethodCallStatus call_status, |
| + const base::DictionaryValue& properties); |
| + |
| + // Pointer to containing class (owns this) |
| + Delegate* delegate_; |
| + |
| + // Convenience pointer for ShillManagerClient |
| + ShillManagerClient* shill_manager_; |
| + |
| + // Pending update count for each managed state type |
| + std::map<ManagedState::ManagedType, int> pending_updates_; |
| + |
| + // List of network services with Shill property changed observers |
| + ShillServiceObserverMap observed_networks_; |
| + |
| + // For Shill client callbacks |
| + base::WeakPtrFactory<ShillPropertyHandler> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ShillPropertyHandler); |
| +}; |
| + |
| +} // namespace internal |
| +} // namespace chromeos |
| + |
| +#endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ |