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_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "chromeos/chromeos_export.h"
16 class DictionaryValue
;
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
{
32 MANAGED_TYPE_FAVORITE
,
36 virtual ~ManagedState();
38 // This will construct and return a new instance of the appropriate class
40 static ManagedState
* Create(ManagedType type
, const std::string
& path
);
42 // Returns the specific class pointer if this is the correct type, or
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
);
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
,
98 bool GetIntegerValue(const std::string
& key
,
99 const base::Value
& 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
,
108 void set_name(const std::string
& name
) { name_
= name
; }
111 friend class NetworkChangeNotifierChromeosUpdateTest
;
113 ManagedType managed_type_
;
115 // The path (e.g. service path or device path) of the managed state object.
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_