network_state.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/network_state.h"
6
7#include "base/values.h"
8#include "third_party/cros_system_api/dbus/service_constants.h"
9
10namespace chromeos {
11
12NetworkState::NetworkState(const std::string& path)
13    : ManagedState(MANAGED_TYPE_NETWORK, path),
14      signal_strength_(0) {
15}
16
17NetworkState::~NetworkState() {
18}
19
20bool NetworkState::PropertyChanged(const std::string& key,
21                                   const base::Value& value) {
22  if (ManagedStatePropertyChanged(key, value))
23    return true;
24  if (key == flimflam::kSignalStrengthProperty) {
25    return GetIntegerValue(key, value, &signal_strength_);
26  } else if (key == flimflam::kStateProperty) {
27    return GetStringValue(key, value, &state_);
28  } else if (key == flimflam::kErrorProperty) {
29    return GetStringValue(key, value, &error_);
30  } else if (key == flimflam::kActivationStateProperty) {
31    return GetStringValue(key, value, &activation_state_);
32  } else if (key == flimflam::kRoamingStateProperty) {
33    return GetStringValue(key, value, &roaming_);
34  } else if (key == flimflam::kSecurityProperty) {
35    return GetStringValue(key, value, &security_);
36  } else if (key == flimflam::kNetworkTechnologyProperty) {
37    return GetStringValue(key, value, &technology_);
38  } else if (key == flimflam::kDeviceProperty) {
39    return GetStringValue(key, value, &device_path_);
40  }
41  return false;
42}
43
44bool NetworkState::IsConnectedState() const {
45  return StateIsConnected(state_);
46}
47
48bool NetworkState::IsConnectingState() const {
49  return StateIsConnecting(state_);
50}
51
52// static
53bool NetworkState::StateIsConnected(const std::string& state) {
54  return (state == flimflam::kStateReady ||
55          state == flimflam::kStateOnline ||
56          state == flimflam::kStatePortal);
57}
58
59// static
60bool NetworkState::StateIsConnecting(const std::string& state) {
61  return (state == flimflam::kStateAssociation ||
62          state == flimflam::kStateConfiguration ||
63          state == flimflam::kStateCarrier);
64}
65
66}  // namespace chromeos
67