Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: chromeos/network/managed_state.cc

Issue 11192024: Add chromeos::NetworkStateManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Separate out NetworkStateHandlerImpl, address feedback Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chromeos/network/managed_state.h"
6
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"
12
13 namespace chromeos {
14
15 ManagedState::ManagedState(ManagedType type, const std::string& path)
16 : managed_type_(type),
17 path_(path) {
18 }
19
20 ManagedState::~ManagedState() {
21 }
22
23 ManagedState* ManagedState::Create(ManagedType type, const std::string& path) {
24 switch(type) {
25 case MANAGED_TYPE_NETWORK:
26 return new NetworkState(path);
27 case MANAGED_TYPE_DEVICE:
28 return new DeviceState(path);
29 }
30 return NULL;
31 }
32
33 NetworkState* ManagedState::AsNetworkState() {
34 if (managed_type() == MANAGED_TYPE_NETWORK)
35 return static_cast<NetworkState*>(this);
36 return NULL;
37 }
38
39 DeviceState* ManagedState::AsDeviceState() {
40 if (managed_type() == MANAGED_TYPE_DEVICE)
41 return static_cast<DeviceState*>(this);
42 return NULL;
43 }
44
45 bool ManagedState::ManagedStatePropertyChanged(const std::string& key,
46 const base::Value& value) {
47 if (key == flimflam::kNameProperty) {
48 return GetStringValue(key, value, &name_);
49 } else if (key == flimflam::kTypeProperty) {
50 return GetStringValue(key, value, &type_);
51 }
52 return false;
53 }
54
55 bool ManagedState::GetBooleanValue(const std::string& key,
56 const base::Value& value,
57 bool* out_value) {
58 bool res = value.GetAsBoolean(out_value);
59 if (!res)
60 LOG(WARNING) << "Failed to parse boolean value for:" << key;
61 return res;
62 }
63
64 bool ManagedState::GetIntegerValue(const std::string& key,
65 const base::Value& value,
66 int* out_value) {
67 bool res = value.GetAsInteger(out_value);
68 if (!res)
69 LOG(WARNING) << "Failed to parse integer value for:" << key;
70 return res;
71 }
72
73 bool ManagedState::GetStringValue(const std::string& key,
74 const base::Value& value,
75 std::string* out_value) {
76 bool res = value.GetAsString(out_value);
77 if (!res)
78 LOG(WARNING) << "Failed to parse string value for:" << key;
79 return res;
80 }
81
82 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698