Index: chromeos/network/network_state.cc |
diff --git a/chromeos/network/network_state.cc b/chromeos/network/network_state.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..28e3a8b08681b7c989c5050317d4d06888272afb |
--- /dev/null |
+++ b/chromeos/network/network_state.cc |
@@ -0,0 +1,65 @@ |
+// 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/network_state.h" |
+ |
+#include "base/logging.h" |
+#include "base/values.h" |
+ |
+namespace chromeos { |
+ |
+NetworkState::NetworkState(const std::string& path) |
+ : ManagedState(MANAGED_TYPE_NETWORK, path), |
+ strength_(0) { |
+} |
+ |
+bool NetworkState::PropertyChanged(const std::string& key, |
+ const base::Value& value) { |
+ if (key == flimflam::kSignalStrengthProperty) { |
+ return value.GetAsInteger(&strength_); |
+ } else if (key == flimflam::kStateProperty) { |
+ return value.GetAsString(&state_); |
+ } else if (key == flimflam::kErrorProperty) { |
+ return value.GetAsString(&error_); |
+ } else if (key == flimflam::kActivationStateProperty) { |
+ return value.GetAsString(&activation_); |
+ } else if (key == flimflam::kRoamingStateProperty) { |
+ return value.GetAsString(&roaming_); |
+ } else if (key == flimflam::kNameProperty) { |
+ return value.GetAsString(&name_); |
+ } else if (key == flimflam::kTypeProperty) { |
+ return value.GetAsString(&type_); |
+ } else if (key == flimflam::kSecurityProperty) { |
+ return value.GetAsString(&security_); |
+ } else if (key == flimflam::kNetworkTechnologyProperty) { |
+ return value.GetAsString(&technology_); |
+ } else if (key == flimflam::kDeviceProperty) { |
+ return value.GetAsString(&device_path_); |
+ } |
+ return true; |
+} |
+ |
+bool NetworkState::IsConnectedState() const { |
+ return StateIsConnected(state_); |
+} |
+ |
+bool NetworkState::IsConnectingState() const { |
+ return StateIsConnecting(state_); |
+} |
+ |
+// static |
+bool NetworkState::StateIsConnected(const std::string& state) { |
+ return (state == flimflam::kStateReady || |
+ state == flimflam::kStateOnline || |
+ state == flimflam::kStatePortal); |
+} |
+ |
+// static |
+bool NetworkState::StateIsConnecting(const std::string& state) { |
+ return (state == flimflam::kStateAssociation || |
+ state == flimflam::kStateConfiguration || |
+ state == flimflam::kStateCarrier); |
+} |
+ |
+} // namespace chromeos |