summaryrefslogtreecommitdiffstats
path: root/chromeos/network/managed_state.cc
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-07 10:14:59 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-07 10:14:59 +0000
commit3c8bd113b0da75a274072e543c314a8c19288429 (patch)
tree70993526ffd965ea57989435fafe33fbc50788f3 /chromeos/network/managed_state.cc
parent51ed599857bf45c7ea54761dfce58691fe9c657e (diff)
downloadchromium_src-3c8bd113b0da75a274072e543c314a8c19288429.zip
chromium_src-3c8bd113b0da75a274072e543c314a8c19288429.tar.gz
chromium_src-3c8bd113b0da75a274072e543c314a8c19288429.tar.bz2
Add chromeos::NetworkStateManager to src/chromeos/network.
The intention for this class is to provide up-to-date state information about the network for the majority of the network related UI. It should also serve as a foundation for classes monitoring the state of the active network. This code is not designed to provide detailed information about specific network service or device properties, not should it provide the ability to set (configure) those properties. BUG=154072 Review URL: https://chromiumcodereview.appspot.com/11192024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166375 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/network/managed_state.cc')
-rw-r--r--chromeos/network/managed_state.cc83
1 files changed, 83 insertions, 0 deletions
diff --git a/chromeos/network/managed_state.cc b/chromeos/network/managed_state.cc
new file mode 100644
index 0000000..556d200
--- /dev/null
+++ b/chromeos/network/managed_state.cc
@@ -0,0 +1,83 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/network/managed_state.h"
+
+#include "base/logging.h"
+#include "base/values.h"
+#include "chromeos/network/device_state.h"
+#include "chromeos/network/network_state.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
+
+namespace chromeos {
+
+ManagedState::ManagedState(ManagedType type, const std::string& path)
+ : managed_type_(type),
+ path_(path),
+ is_observed_(false) {
+}
+
+ManagedState::~ManagedState() {
+}
+
+ManagedState* ManagedState::Create(ManagedType type, const std::string& path) {
+ switch(type) {
+ case MANAGED_TYPE_NETWORK:
+ return new NetworkState(path);
+ case MANAGED_TYPE_DEVICE:
+ return new DeviceState(path);
+ }
+ return NULL;
+}
+
+NetworkState* ManagedState::AsNetworkState() {
+ if (managed_type() == MANAGED_TYPE_NETWORK)
+ return static_cast<NetworkState*>(this);
+ return NULL;
+}
+
+DeviceState* ManagedState::AsDeviceState() {
+ if (managed_type() == MANAGED_TYPE_DEVICE)
+ return static_cast<DeviceState*>(this);
+ return NULL;
+}
+
+bool ManagedState::ManagedStatePropertyChanged(const std::string& key,
+ const base::Value& value) {
+ if (key == flimflam::kNameProperty) {
+ return GetStringValue(key, value, &name_);
+ } else if (key == flimflam::kTypeProperty) {
+ return GetStringValue(key, value, &type_);
+ }
+ return false;
+}
+
+bool ManagedState::GetBooleanValue(const std::string& key,
+ const base::Value& value,
+ bool* out_value) {
+ bool res = value.GetAsBoolean(out_value);
+ if (!res)
+ LOG(WARNING) << "Failed to parse boolean value for:" << key;
+ return res;
+}
+
+bool ManagedState::GetIntegerValue(const std::string& key,
+ const base::Value& value,
+ int* out_value) {
+ bool res = value.GetAsInteger(out_value);
+ if (!res)
+ LOG(WARNING) << "Failed to parse integer value for:" << key;
+ return res;
+}
+
+bool ManagedState::GetStringValue(const std::string& key,
+ const base::Value& value,
+ std::string* out_value) {
+ bool res = value.GetAsString(out_value);
+ if (!res)
+ LOG(WARNING) << "Failed to parse string value for:" << key;
+ return res;
+}
+
+} // namespace chromeos