Index: chromeos/network/network_state_handler_impl.h |
diff --git a/chromeos/network/network_state_handler_impl.h b/chromeos/network/network_state_handler_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..25be2d00859801cd8ccda4bb91e9cde9f763db9b |
--- /dev/null |
+++ b/chromeos/network/network_state_handler_impl.h |
@@ -0,0 +1,120 @@ |
+// 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 NetworkStateHandler; |
+class ShillServiceObserver; |
+class ShillManagerClient; |
+ |
+namespace internal { |
+ |
+// Implementation class for NetworkStateHandler. This class handles all Shill |
+// calls and observers. This class must not outlive the ShillManagerClient |
+// instance. |
+class NetworkStateHandlerImpl : public ShillPropertyChangedObserver { |
gauravsh
2012/10/27 00:26:33
Please think of a better name for this class. It's
stevenjb
2012/10/29 18:34:07
Fair enough. How about ShillPropertyHandler?
gauravsh
2012/10/29 18:37:05
SGTM
|
+ public: |
+ typedef std::map<std::string, ShillServiceObserver*> ShillServiceObserverMap; |
+ |
+ explicit NetworkStateHandlerImpl(NetworkStateHandler* base); |
+ ~NetworkStateHandlerImpl(); |
+ |
+ // Initialize NetworkStateHandler. Sends an initial property request. |
+ 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); |
+ |
+ // ShillPropertyChangedObserver overrides |
+ virtual void OnPropertyChanged(const std::string& key, |
+ const base::Value& value) OVERRIDE; |
+ |
+ const ShillServiceObserverMap& observed_networks() { |
+ return observed_networks_; |
+ } |
+ |
+ 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); |
+ |
+ // 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) |
+ NetworkStateHandler* base_; |
+ |
+ // 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<NetworkStateHandlerImpl> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NetworkStateHandlerImpl); |
+}; |
+ |
+} // namespace internal |
+} // namespace chromeos |
+ |
+#endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ |