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

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: Fix comment 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
« no previous file with comments | « chromeos/network/managed_state.h ('k') | chromeos/network/network_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 is_observed_(false) {
19 }
20
21 ManagedState::~ManagedState() {
22 }
23
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);
30 }
31 return NULL;
32 }
33
34 NetworkState* ManagedState::AsNetworkState() {
35 if (managed_type() == MANAGED_TYPE_NETWORK)
36 return static_cast<NetworkState*>(this);
37 return NULL;
38 }
39
40 DeviceState* ManagedState::AsDeviceState() {
41 if (managed_type() == MANAGED_TYPE_DEVICE)
42 return static_cast<DeviceState*>(this);
43 return NULL;
44 }
45
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_);
52 }
53 return false;
54 }
55
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;
63 }
64
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;
72 }
73
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;
81 }
82
83 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/managed_state.h ('k') | chromeos/network/network_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698