summaryrefslogtreecommitdiffstats
path: root/chromeos/network/network_state.cc
blob: c87bdcb4763c9fdef56f09f60e16360a7e83b9d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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/values.h"
#include "third_party/cros_system_api/dbus/service_constants.h"

namespace chromeos {

NetworkState::NetworkState(const std::string& path)
    : ManagedState(MANAGED_TYPE_NETWORK, path),
      signal_strength_(0) {
}

NetworkState::~NetworkState() {
}

bool NetworkState::PropertyChanged(const std::string& key,
                                   const base::Value& value) {
  if (ManagedStatePropertyChanged(key, value))
    return true;
  if (key == flimflam::kSignalStrengthProperty) {
    return GetIntegerValue(key, value, &signal_strength_);
  } else if (key == flimflam::kStateProperty) {
    return GetStringValue(key, value, &state_);
  } else if (key == flimflam::kErrorProperty) {
    return GetStringValue(key, value, &error_);
  } else if (key == flimflam::kActivationStateProperty) {
    return GetStringValue(key, value, &activation_state_);
  } else if (key == flimflam::kRoamingStateProperty) {
    return GetStringValue(key, value, &roaming_);
  } else if (key == flimflam::kSecurityProperty) {
    return GetStringValue(key, value, &security_);
  } else if (key == flimflam::kNetworkTechnologyProperty) {
    return GetStringValue(key, value, &technology_);
  } else if (key == flimflam::kDeviceProperty) {
    return GetStringValue(key, value, &device_path_);
  }
  return false;
}

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