network_state.h revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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#ifndef CHROMEOS_NETWORK_NETWORK_STATE_H_ 6#define CHROMEOS_NETWORK_NETWORK_STATE_H_ 7 8#include <string> 9#include <vector> 10 11#include "chromeos/network/managed_state.h" 12 13namespace base { 14class DictionaryValue; 15} 16 17namespace chromeos { 18 19// Simple class to provide network state information about a network service. 20// This class should always be passed as a const* and should never be held 21// on to. Store network_state->path() (defined in ManagedState) instead and 22// call NetworkStateHandler::GetNetworkState(path) to retrieve the state for 23// the network. 24class CHROMEOS_EXPORT NetworkState : public ManagedState { 25 public: 26 explicit NetworkState(const std::string& path); 27 virtual ~NetworkState(); 28 29 // ManagedState overrides 30 // If you change this method, update GetProperties too. 31 virtual bool PropertyChanged(const std::string& key, 32 const base::Value& value) OVERRIDE; 33 virtual void InitialPropertiesReceived() OVERRIDE; 34 35 // Fills |dictionary| with the state properties. All the properties that are 36 // accepted by PropertyChanged are stored in |dictionary|, no other values are 37 // stored. 38 void GetProperties(base::DictionaryValue* dictionary) const; 39 40 // Accessors 41 const std::string& security() const { return security_; } 42 const std::string& ip_address() const { return ip_address_; } 43 const std::vector<std::string>& dns_servers() const { return dns_servers_; } 44 const std::string& device_path() const { return device_path_; } 45 const std::string& guid() const { return guid_; } 46 const std::string& connection_state() const { return connection_state_; } 47 const std::string& profile_path() const { return profile_path_; } 48 const std::string& error() const { return error_; } 49 bool auto_connect() const { return auto_connect_; } 50 bool favorite() const { return favorite_; } 51 int priority() const { return priority_; } 52 // Wireless property accessors 53 int signal_strength() const { return signal_strength_; } 54 bool connectable() const { return connectable_; } 55 // Wifi property accessors 56 bool passphrase_required() const { return passphrase_required_; } 57 // Cellular property accessors 58 const std::string& technology() const { return technology_; } 59 const std::string& activation_state() const { return activation_state_; } 60 const std::string& roaming() const { return roaming_; } 61 bool activate_over_non_cellular_networks() const { 62 return activate_over_non_cellular_networks_; 63 } 64 bool cellular_out_of_credits() const { return cellular_out_of_credits_; } 65 66 bool IsConnectedState() const; 67 bool IsConnectingState() const; 68 69 // Helpers (used e.g. when a state is cached) 70 static bool StateIsConnected(const std::string& connection_state); 71 static bool StateIsConnecting(const std::string& connection_state); 72 73 // Helper to return a full prefixed version of an IPConfig property 74 // key. 75 static std::string IPConfigProperty(const char* key); 76 77 private: 78 friend class NetworkStateHandler; 79 friend class NetworkChangeNotifierChromeosUpdateTest; 80 81 // Updates the name from hex_ssid_ if provided, and validates name_. 82 void UpdateName(); 83 84 // Called by NetworkStateHandler when the ip config changes. 85 void set_ip_address(const std::string& ip_address) { 86 ip_address_ = ip_address; 87 } 88 void set_dns_servers(const std::vector<std::string>& dns_servers) { 89 dns_servers_ = dns_servers; 90 } 91 92 // Common Network Service properties 93 std::string security_; 94 std::string device_path_; 95 std::string guid_; 96 std::string connection_state_; 97 std::string profile_path_; 98 std::string error_; 99 bool auto_connect_; 100 bool favorite_; 101 int priority_; 102 // IPConfig properties. 103 // Note: These do not correspond to actual Shill.Service properties 104 // but are derived from the service's corresponding IPConfig object. 105 std::string ip_address_; 106 std::vector<std::string> dns_servers_; 107 // Wireless properties 108 int signal_strength_; 109 bool connectable_; 110 // Wifi properties 111 std::string hex_ssid_; 112 std::string country_code_; 113 bool passphrase_required_; 114 // Cellular properties 115 std::string technology_; 116 std::string activation_state_; 117 std::string roaming_; 118 bool activate_over_non_cellular_networks_; 119 bool cellular_out_of_credits_; 120 121 DISALLOW_COPY_AND_ASSIGN(NetworkState); 122}; 123 124} // namespace chromeos 125 126#endif // CHROMEOS_NETWORK_NETWORK_STATE_H_ 127