network_state.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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 "base/values.h" 12#include "chromeos/network/managed_state.h" 13#include "chromeos/network/onc/onc_constants.h" 14 15namespace chromeos { 16 17// Simple class to provide network state information about a network service. 18// This class should always be passed as a const* and should never be held 19// on to. Store network_state->path() (defined in ManagedState) instead and 20// call NetworkStateHandler::GetNetworkState(path) to retrieve the state for 21// the network. 22class CHROMEOS_EXPORT NetworkState : public ManagedState { 23public: 24 typedef std::vector<int> FrequencyList; 25 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 // Fills |dictionary| with the state properties required to configure a 41 // network. 42 void GetConfigProperties(base::DictionaryValue* dictionary) const; 43 44 // Accessors 45 const std::string& security() const { return security_; } 46 const std::string& ip_address() const { return ip_address_; } 47 const std::vector<std::string>& dns_servers() const { return dns_servers_; } 48 const std::string& device_path() const { return device_path_; } 49 const std::string& guid() const { return guid_; } 50 const std::string& connection_state() const { return connection_state_; } 51 const std::string& profile_path() const { return profile_path_; } 52 const std::string& error() const { return error_; } 53 const std::string& error_details() const { return error_details_; } 54 bool auto_connect() const { return auto_connect_; } 55 bool favorite() const { return favorite_; } 56 int priority() const { return priority_; } 57 const base::DictionaryValue& proxy_config() const { return proxy_config_; } 58 onc::ONCSource onc_source() const { return onc_source_; } 59 // Wireless property accessors 60 int signal_strength() const { return signal_strength_; } 61 bool connectable() const { return connectable_; } 62 // Wifi property accessors 63 bool passphrase_required() const { return passphrase_required_; } 64 const FrequencyList& wifi_frequencies() const { return wifi_frequencies_; } 65 // Cellular property accessors 66 const std::string& technology() const { return technology_; } 67 const std::string& activation_state() const { return activation_state_; } 68 const std::string& roaming() const { return roaming_; } 69 bool activate_over_non_cellular_networks() const { 70 return activate_over_non_cellular_networks_; 71 } 72 bool cellular_out_of_credits() const { return cellular_out_of_credits_; } 73 const std::string& usage_url() const { return usage_url_; } 74 const std::string& payment_url() const { return payment_url_; } 75 const std::string& post_method() const { return post_method_; } 76 const std::string& post_data() const { return post_data_; } 77 78 bool IsConnectedState() const; 79 bool IsConnectingState() const; 80 81 // Returns true if |error_| contains an authentication error. 82 bool HasAuthenticationError() const; 83 84 // Helpers (used e.g. when a state is cached) 85 static bool StateIsConnected(const std::string& connection_state); 86 static bool StateIsConnecting(const std::string& connection_state); 87 88 // Helper to return a full prefixed version of an IPConfig property 89 // key. 90 static std::string IPConfigProperty(const char* key); 91 92 private: 93 friend class NetworkStateHandler; 94 friend class NetworkChangeNotifierChromeosUpdateTest; 95 96 // Updates the name from hex_ssid_ if provided, and validates name_. 97 void UpdateName(); 98 99 // Called by NetworkStateHandler when the ip config changes. 100 void set_ip_address(const std::string& ip_address) { 101 ip_address_ = ip_address; 102 } 103 void set_dns_servers(const std::vector<std::string>& dns_servers) { 104 dns_servers_ = dns_servers; 105 } 106 107 // TODO(gauravsh): Audit the list of properties that we are caching. We should 108 // only be doing this for commonly accessed properties. crbug.com/252553 109 // Common Network Service properties 110 std::string security_; 111 std::string device_path_; 112 std::string guid_; 113 std::string connection_state_; 114 std::string profile_path_; 115 std::string error_; 116 std::string error_details_; 117 bool auto_connect_; 118 bool favorite_; 119 int priority_; 120 // TODO(pneubeck): Remove ProxyConfig and ONCSource once 121 // NetworkConfigurationHandler provides proxy configuration. crbug/241775 122 base::DictionaryValue proxy_config_; 123 onc::ONCSource onc_source_; 124 // IPConfig properties. 125 // Note: These do not correspond to actual Shill.Service properties 126 // but are derived from the service's corresponding IPConfig object. 127 std::string ip_address_; 128 std::vector<std::string> dns_servers_; 129 // Wireless properties 130 int signal_strength_; 131 bool connectable_; 132 // Wifi properties 133 std::string hex_ssid_; 134 std::string country_code_; 135 bool passphrase_required_; 136 FrequencyList wifi_frequencies_; 137 // Cellular properties 138 std::string technology_; 139 std::string activation_state_; 140 std::string roaming_; 141 bool activate_over_non_cellular_networks_; 142 bool cellular_out_of_credits_; 143 // Cellular payment portal properties. 144 std::string usage_url_; 145 std::string payment_url_; 146 std::string post_method_; 147 std::string post_data_; 148 149 DISALLOW_COPY_AND_ASSIGN(NetworkState); 150}; 151 152} // namespace chromeos 153 154#endif // CHROMEOS_NETWORK_NETWORK_STATE_H_ 155