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"
15 ManagedState::ManagedState(ManagedType type
, const std::string
& path
)
16 : managed_type_(type
),
21 ManagedState::~ManagedState() {
24 ManagedState
* ManagedState::Create(ManagedType type
, const std::string
& path
) {
26 case MANAGED_TYPE_NETWORK
:
27 return new NetworkState(path
);
28 case MANAGED_TYPE_DEVICE
:
29 return new DeviceState(path
);
34 NetworkState
* ManagedState::AsNetworkState() {
35 if (managed_type() == MANAGED_TYPE_NETWORK
)
36 return static_cast<NetworkState
*>(this);
40 DeviceState
* ManagedState::AsDeviceState() {
41 if (managed_type() == MANAGED_TYPE_DEVICE
)
42 return static_cast<DeviceState
*>(this);
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_
);
56 bool ManagedState::GetBooleanValue(const std::string
& key
,
57 const base::Value
& value
,
59 bool res
= value
.GetAsBoolean(out_value
);
61 LOG(WARNING
) << "Failed to parse boolean value for:" << key
;
65 bool ManagedState::GetIntegerValue(const std::string
& key
,
66 const base::Value
& value
,
68 bool res
= value
.GetAsInteger(out_value
);
70 LOG(WARNING
) << "Failed to parse integer value for:" << key
;
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
);
79 LOG(WARNING
) << "Failed to parse string value for:" << key
;
83 } // namespace chromeos