[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / chromeos / network / managed_state.cc
blob556d200e44886b6b943ab7e66a0c203594a34d23
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 #include "chromeos/network/managed_state.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "chromeos/network/device_state.h"
10 #include "chromeos/network/network_state.h"
11 #include "third_party/cros_system_api/dbus/service_constants.h"
13 namespace chromeos {
15 ManagedState::ManagedState(ManagedType type, const std::string& path)
16 : managed_type_(type),
17 path_(path),
18 is_observed_(false) {
21 ManagedState::~ManagedState() {
24 ManagedState* ManagedState::Create(ManagedType type, const std::string& path) {
25 switch(type) {
26 case MANAGED_TYPE_NETWORK:
27 return new NetworkState(path);
28 case MANAGED_TYPE_DEVICE:
29 return new DeviceState(path);
31 return NULL;
34 NetworkState* ManagedState::AsNetworkState() {
35 if (managed_type() == MANAGED_TYPE_NETWORK)
36 return static_cast<NetworkState*>(this);
37 return NULL;
40 DeviceState* ManagedState::AsDeviceState() {
41 if (managed_type() == MANAGED_TYPE_DEVICE)
42 return static_cast<DeviceState*>(this);
43 return NULL;
46 bool ManagedState::ManagedStatePropertyChanged(const std::string& key,
47 const base::Value& value) {
48 if (key == flimflam::kNameProperty) {
49 return GetStringValue(key, value, &name_);
50 } else if (key == flimflam::kTypeProperty) {
51 return GetStringValue(key, value, &type_);
53 return false;
56 bool ManagedState::GetBooleanValue(const std::string& key,
57 const base::Value& value,
58 bool* out_value) {
59 bool res = value.GetAsBoolean(out_value);
60 if (!res)
61 LOG(WARNING) << "Failed to parse boolean value for:" << key;
62 return res;
65 bool ManagedState::GetIntegerValue(const std::string& key,
66 const base::Value& value,
67 int* out_value) {
68 bool res = value.GetAsInteger(out_value);
69 if (!res)
70 LOG(WARNING) << "Failed to parse integer value for:" << key;
71 return res;
74 bool ManagedState::GetStringValue(const std::string& key,
75 const base::Value& value,
76 std::string* out_value) {
77 bool res = value.GetAsString(out_value);
78 if (!res)
79 LOG(WARNING) << "Failed to parse string value for:" << key;
80 return res;
83 } // namespace chromeos