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
;
23 class NetworkTypePattern
;
25 // Base class for states managed by NetworkStateManger which are associated
26 // with a Shill path (e.g. service path or device path).
27 class CHROMEOS_EXPORT ManagedState
{
34 virtual ~ManagedState();
36 // This will construct and return a new instance of the appropriate class
38 static ManagedState
* Create(ManagedType type
, const std::string
& path
);
40 // Returns the specific class pointer if this is the correct type, or
42 NetworkState
* AsNetworkState();
43 DeviceState
* AsDeviceState();
45 // Called by NetworkStateHandler when a property was received. The return
46 // value indicates if the state changed and is used to reduce the number of
47 // notifications. The only guarantee however is: If the return value is false
48 // then the state wasn't modified. This might happen because of
49 // * |key| was not recognized.
50 // * |value| was not parsed successfully.
51 // * |value| is equal to the cached property value.
52 // If the return value is true, the state might or might not be modified.
53 virtual bool PropertyChanged(const std::string
& key
,
54 const base::Value
& value
) = 0;
56 // Called by NetworkStateHandler after all calls to PropertyChanged for the
57 // initial set of properties. Used to update state requiring multiple
58 // properties, e.g. name from hex_ssid in NetworkState.
59 // |properties| contains the complete set of initial properties.
60 // Returns true if any additional properties are updated.
61 virtual bool InitialPropertiesReceived(
62 const base::DictionaryValue
& properties
);
64 // Fills |dictionary| with a minimal set of state properties for the network
65 // type. See implementations for which properties are included.
66 virtual void GetStateProperties(base::DictionaryValue
* dictionary
) const;
68 ManagedType
managed_type() const { return managed_type_
; }
69 const std::string
& path() const { return path_
; }
70 const std::string
& name() const { return name_
; }
71 const std::string
& type() const { return type_
; }
72 bool update_received() const { return update_received_
; }
73 void set_update_received() { update_received_
= true; }
74 bool update_requested() const { return update_requested_
; }
75 void set_update_requested(bool update_requested
) {
76 update_requested_
= update_requested
;
79 // Returns true if |type_| matches |pattern|.
80 bool Matches(const NetworkTypePattern
& pattern
) const;
82 static std::string
TypeToString(ManagedType type
);
85 ManagedState(ManagedType type
, const std::string
& path
);
87 // Parses common property keys (name, type).
88 bool ManagedStatePropertyChanged(const std::string
& key
,
89 const base::Value
& value
);
91 // Helper methods that log warnings and return true if parsing succeeded and
92 // the new value does not match the existing output value.
93 bool GetBooleanValue(const std::string
& key
,
94 const base::Value
& value
,
96 bool GetIntegerValue(const std::string
& key
,
97 const base::Value
& value
,
99 bool GetStringValue(const std::string
& key
,
100 const base::Value
& value
,
101 std::string
* out_value
);
102 bool GetUInt32Value(const std::string
& key
,
103 const base::Value
& value
,
106 void set_name(const std::string
& name
) { name_
= name
; }
109 friend class NetworkChangeNotifierChromeosUpdateTest
;
111 ManagedType managed_type_
;
113 // The path (e.g. service path or device path) of the managed state object.
116 // Common properties shared by all managed state objects.
117 std::string name_
; // shill::kNameProperty
118 std::string type_
; // shill::kTypeProperty
120 // Set to true when the an update has been received.
121 bool update_received_
;
123 // Tracks when an update has been requested.
124 bool update_requested_
;
126 DISALLOW_COPY_AND_ASSIGN(ManagedState
);
129 } // namespace chromeos
131 #endif // CHROMEOS_NETWORK_MANAGED_STATE_H_