OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_NETWORK_MANAGED_STATE_H_ | 5 #ifndef CHROMEOS_NETWORK_MANAGED_STATE_H_ |
6 #define CHROMEOS_NETWORK_MANAGED_STATE_H_ | 6 #define CHROMEOS_NETWORK_MANAGED_STATE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // This will construct and return a new instance of the approprate class | 34 // This will construct and return a new instance of the approprate class |
35 // based on |type|. | 35 // based on |type|. |
36 static ManagedState* Create(ManagedType type, const std::string& path); | 36 static ManagedState* Create(ManagedType type, const std::string& path); |
37 | 37 |
38 // Returns the specific class pointer if this is the correct type, or | 38 // Returns the specific class pointer if this is the correct type, or |
39 // NULL if it is not. | 39 // NULL if it is not. |
40 NetworkState* AsNetworkState(); | 40 NetworkState* AsNetworkState(); |
41 DeviceState* AsDeviceState(); | 41 DeviceState* AsDeviceState(); |
42 | 42 |
43 // Called by NetworkStateHandler when a property changes. Returns true if | 43 // Called by NetworkStateHandler when a property changes. Returns true if |
44 // the property was recognized and parsed successfully. | 44 // the property was recognized, parsed successfully, and different from |
| 45 // the previous value. |
45 virtual bool PropertyChanged(const std::string& key, | 46 virtual bool PropertyChanged(const std::string& key, |
46 const base::Value& value) = 0; | 47 const base::Value& value) = 0; |
47 | 48 |
48 // Called by NetworkStateHandler after all calls to PropertyChanged for the | 49 // Called by NetworkStateHandler after all calls to PropertyChanged for the |
49 // initial set of properties. Used to update state requiring multiple | 50 // initial set of properties. Used to update state requiring multiple |
50 // parsed properties, e.g. name from hex_ssid in NetworkState. | 51 // parsed properties, e.g. name from hex_ssid in NetworkState. |
51 virtual void InitialPropertiesReceived(); | 52 virtual void InitialPropertiesReceived(); |
52 | 53 |
53 const ManagedType managed_type() const { return managed_type_; } | 54 const ManagedType managed_type() const { return managed_type_; } |
54 const std::string& path() const { return path_; } | 55 const std::string& path() const { return path_; } |
55 const std::string& name() const { return name_; } | 56 const std::string& name() const { return name_; } |
56 const std::string& type() const { return type_; } | 57 const std::string& type() const { return type_; } |
57 bool is_observed() const { return is_observed_; } | 58 bool is_observed() const { return is_observed_; } |
58 void set_is_observed(bool is_observed) { is_observed_ = is_observed; } | 59 void set_is_observed(bool is_observed) { is_observed_ = is_observed; } |
59 | 60 |
60 protected: | 61 protected: |
61 ManagedState(ManagedType type, const std::string& path); | 62 ManagedState(ManagedType type, const std::string& path); |
62 | 63 |
63 // Parses common property keys (name, type). | 64 // Parses common property keys (name, type). |
64 bool ManagedStatePropertyChanged(const std::string& key, | 65 bool ManagedStatePropertyChanged(const std::string& key, |
65 const base::Value& value); | 66 const base::Value& value); |
66 | 67 |
67 // Helper methods that log warnings and return false if parsing failed. | 68 // Helper methods that log warnings and return true if parsing succeeded and |
| 69 // the new value does not match the existing output value. |
68 bool GetBooleanValue(const std::string& key, | 70 bool GetBooleanValue(const std::string& key, |
69 const base::Value& value, | 71 const base::Value& value, |
70 bool* out_value); | 72 bool* out_value); |
71 bool GetIntegerValue(const std::string& key, | 73 bool GetIntegerValue(const std::string& key, |
72 const base::Value& value, | 74 const base::Value& value, |
73 int* out_value); | 75 int* out_value); |
74 bool GetStringValue(const std::string& key, | 76 bool GetStringValue(const std::string& key, |
75 const base::Value& value, | 77 const base::Value& value, |
76 std::string* out_value); | 78 std::string* out_value); |
77 | 79 |
(...skipping 13 matching lines...) Expand all Loading... |
91 | 93 |
92 // Tracks when the state is being observed. | 94 // Tracks when the state is being observed. |
93 bool is_observed_; | 95 bool is_observed_; |
94 | 96 |
95 DISALLOW_COPY_AND_ASSIGN(ManagedState); | 97 DISALLOW_COPY_AND_ASSIGN(ManagedState); |
96 }; | 98 }; |
97 | 99 |
98 } // namespace chromeos | 100 } // namespace chromeos |
99 | 101 |
100 #endif // CHROMEOS_NETWORK_MANAGED_STATE_H_ | 102 #endif // CHROMEOS_NETWORK_MANAGED_STATE_H_ |
OLD | NEW |