Add default implementations for AppWindowRegistry::Observer notifications.
[chromium-blink-merge.git] / chromeos / network / managed_state.h
blob8b563943ffc13040235af3b673a15e8b057ca954
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.
5 #ifndef CHROMEOS_NETWORK_MANAGED_STATE_H_
6 #define CHROMEOS_NETWORK_MANAGED_STATE_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "chromeos/chromeos_export.h"
14 namespace base {
15 class Value;
16 class DictionaryValue;
19 namespace chromeos {
21 class DeviceState;
22 class FavoriteState;
23 class NetworkState;
24 class NetworkTypePattern;
26 // Base class for states managed by NetworkStateManger which are associated
27 // with a Shill path (e.g. service path or device path).
28 class CHROMEOS_EXPORT ManagedState {
29 public:
30 enum ManagedType {
31 MANAGED_TYPE_NETWORK,
32 MANAGED_TYPE_FAVORITE,
33 MANAGED_TYPE_DEVICE
36 virtual ~ManagedState();
38 // This will construct and return a new instance of the appropriate class
39 // based on |type|.
40 static ManagedState* Create(ManagedType type, const std::string& path);
42 // Returns the specific class pointer if this is the correct type, or
43 // NULL if it is not.
44 NetworkState* AsNetworkState();
45 DeviceState* AsDeviceState();
46 FavoriteState* AsFavoriteState();
48 // Called by NetworkStateHandler when a property was received. The return
49 // value indicates if the state changed and is used to reduce the number of
50 // notifications. The only guarantee however is: If the return value is false
51 // then the state wasn't modified. This might happen because of
52 // * |key| was not recognized.
53 // * |value| was not parsed successfully.
54 // * |value| is equal to the cached property value.
55 // If the return value is true, the state might or might not be modified.
56 virtual bool PropertyChanged(const std::string& key,
57 const base::Value& value) = 0;
59 // Called by NetworkStateHandler after all calls to PropertyChanged for the
60 // initial set of properties. Used to update state requiring multiple
61 // properties, e.g. name from hex_ssid in NetworkState.
62 // |properties| contains the complete set of initial properties.
63 // Returns true if any additional properties are updated.
64 virtual bool InitialPropertiesReceived(
65 const base::DictionaryValue& properties);
67 // Fills |dictionary| with a minimal set of state properties for the network
68 // type. See implementations for which properties are included.
69 virtual void GetStateProperties(base::DictionaryValue* dictionary) const;
71 const ManagedType managed_type() const { return managed_type_; }
72 const std::string& path() const { return path_; }
73 const std::string& name() const { return name_; }
74 const std::string& type() const { return type_; }
75 bool update_received() const { return update_received_; }
76 void set_update_received() { update_received_ = true; }
77 bool update_requested() const { return update_requested_; }
78 void set_update_requested(bool update_requested) {
79 update_requested_ = update_requested;
82 bool Matches(const NetworkTypePattern& pattern) const;
84 static std::string TypeToString(ManagedType type);
86 protected:
87 ManagedState(ManagedType type, const std::string& path);
89 // Parses common property keys (name, type).
90 bool ManagedStatePropertyChanged(const std::string& key,
91 const base::Value& value);
93 // Helper methods that log warnings and return true if parsing succeeded and
94 // the new value does not match the existing output value.
95 bool GetBooleanValue(const std::string& key,
96 const base::Value& value,
97 bool* out_value);
98 bool GetIntegerValue(const std::string& key,
99 const base::Value& value,
100 int* out_value);
101 bool GetStringValue(const std::string& key,
102 const base::Value& value,
103 std::string* out_value);
104 bool GetUInt32Value(const std::string& key,
105 const base::Value& value,
106 uint32* out_value);
108 void set_name(const std::string& name) { name_ = name; }
110 private:
111 friend class NetworkChangeNotifierChromeosUpdateTest;
113 ManagedType managed_type_;
115 // The path (e.g. service path or device path) of the managed state object.
116 std::string path_;
118 // Common properties shared by all managed state objects.
119 std::string name_; // shill::kNameProperty
120 std::string type_; // shill::kTypeProperty
122 // Set to true when the an update has been received.
123 bool update_received_;
125 // Tracks when an update has been requested.
126 bool update_requested_;
128 DISALLOW_COPY_AND_ASSIGN(ManagedState);
131 } // namespace chromeos
133 #endif // CHROMEOS_NETWORK_MANAGED_STATE_H_