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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/network/managed_state.h ('k') | chromeos/network/network_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/managed_state.cc
diff --git a/chromeos/network/managed_state.cc b/chromeos/network/managed_state.cc
new file mode 100644
index 0000000000000000000000000000000000000000..556d200e44886b6b943ab7e66a0c203594a34d23
--- /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
« 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