Stop linking tcmalloc into shared library components.
[chromium-blink-merge.git] / chromeos / network / managed_state.h
blob5dcaff2818a76cf50b38c2240e1dfa72cd3c8fe4
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;
18 namespace chromeos {
20 class DeviceState;
21 class NetworkState;
23 // Base class for states managed by NetworkStateManger which are associated
24 // with a Shill path (e.g. service path or device path).
25 class ManagedState {
26 public:
27 enum ManagedType {
28 MANAGED_TYPE_NETWORK,
29 MANAGED_TYPE_DEVICE
32 virtual ~ManagedState();
34 // This will construct and return a new instance of the appropriate class
35 // based on |type|.
36 static ManagedState* Create(ManagedType type, const std::string& path);
38 // Returns the specific class pointer if this is the correct type, or
39 // NULL if it is not.
40 NetworkState* AsNetworkState();
41 DeviceState* AsDeviceState();
43 // Called by NetworkStateHandler when a property changes. Returns false if
44 // the property was not recognized, was not parsed successfully, or is
45 // unchanged (complex properties may be assumed to have changed).
46 virtual bool PropertyChanged(const std::string& key,
47 const base::Value& value) = 0;
49 // Called by NetworkStateHandler after all calls to PropertyChanged for the
50 // initial set of properties. Used to update state requiring multiple
51 // parsed properties, e.g. name from hex_ssid in NetworkState.
52 virtual void InitialPropertiesReceived();
54 const ManagedType managed_type() const { return managed_type_; }
55 const std::string& path() const { return path_; }
56 const std::string& name() const { return name_; }
57 const std::string& type() const { return type_; }
58 bool is_observed() const { return is_observed_; }
59 void set_is_observed(bool is_observed) { is_observed_ = is_observed; }
61 protected:
62 ManagedState(ManagedType type, const std::string& path);
64 // Parses common property keys (name, type).
65 bool ManagedStatePropertyChanged(const std::string& key,
66 const base::Value& value);
68 // Helper methods that log warnings and return true if parsing succeeded and
69 // the new value does not match the existing output value.
70 bool GetBooleanValue(const std::string& key,
71 const base::Value& value,
72 bool* out_value);
73 bool GetIntegerValue(const std::string& key,
74 const base::Value& value,
75 int* out_value);
76 bool GetStringValue(const std::string& key,
77 const base::Value& value,
78 std::string* out_value);
80 void set_name(const std::string& name) { name_ = name; }
82 private:
83 friend class NetworkChangeNotifierChromeosUpdateTest;
85 ManagedType managed_type_;
87 // The path (e.g. service path or device path) of the managed state object.
88 std::string path_;
90 // Common properties shared by all managed state objects.
91 std::string name_; // flimflam::kNameProperty
92 std::string type_; // flimflam::kTypeProperty
94 // Tracks when the state is being observed.
95 bool is_observed_;
97 DISALLOW_COPY_AND_ASSIGN(ManagedState);
100 } // namespace chromeos
102 #endif // CHROMEOS_NETWORK_MANAGED_STATE_H_