| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_NETWORK_NETWORK_STATE_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_STATE_H_ |
| 6 #define CHROMEOS_NETWORK_NETWORK_STATE_H_ | 6 #define CHROMEOS_NETWORK_NETWORK_STATE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chromeos/network/managed_state.h" | 12 #include "chromeos/network/managed_state.h" |
| 13 #include "chromeos/network/network_ui_data.h" | 13 #include "chromeos/network/network_ui_data.h" |
| 14 #include "chromeos/network/onc/onc_constants.h" | 14 #include "chromeos/network/onc/onc_constants.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 // Simple class to provide network state information about a network service. | 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 | 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 | 21 // on to. Store network_state->path() (defined in ManagedState) instead and |
| 22 // call NetworkStateHandler::GetNetworkState(path) to retrieve the state for | 22 // call NetworkStateHandler::GetNetworkState(path) to retrieve the state for |
| 23 // the network. | 23 // the network. |
| 24 class CHROMEOS_EXPORT NetworkState : public ManagedState { | 24 class CHROMEOS_EXPORT NetworkState : public ManagedState { |
| 25 public: | 25 public: |
| 26 typedef std::vector<int> FrequencyList; | |
| 27 | |
| 28 explicit NetworkState(const std::string& path); | 26 explicit NetworkState(const std::string& path); |
| 29 virtual ~NetworkState(); | 27 virtual ~NetworkState(); |
| 30 | 28 |
| 31 // ManagedState overrides | 29 // ManagedState overrides |
| 32 // If you change this method, update GetProperties too. | 30 // If you change this method, update GetProperties too. |
| 33 virtual bool PropertyChanged(const std::string& key, | 31 virtual bool PropertyChanged(const std::string& key, |
| 34 const base::Value& value) OVERRIDE; | 32 const base::Value& value) OVERRIDE; |
| 35 virtual bool InitialPropertiesReceived( | 33 virtual bool InitialPropertiesReceived( |
| 36 const base::DictionaryValue& properties) OVERRIDE; | 34 const base::DictionaryValue& properties) OVERRIDE; |
| 37 | 35 |
| 38 // Fills |dictionary| with the state properties. All the properties that are | 36 // Fills |dictionary| with the state properties. All the properties that are |
| 39 // accepted by PropertyChanged are stored in |dictionary|, no other values are | 37 // accepted by PropertyChanged are stored in |dictionary|, no other values are |
| 40 // stored. | 38 // stored. |
| 41 void GetProperties(base::DictionaryValue* dictionary) const; | 39 void GetProperties(base::DictionaryValue* dictionary) const; |
| 42 | 40 |
| 43 // Accessors | 41 // Accessors |
| 44 const std::string& security() const { return security_; } | 42 const std::string& security() const { return security_; } |
| 45 const std::string& device_path() const { return device_path_; } | 43 const std::string& device_path() const { return device_path_; } |
| 46 const std::string& guid() const { return guid_; } | 44 const std::string& guid() const { return guid_; } |
| 47 const std::string& connection_state() const { return connection_state_; } | 45 const std::string& connection_state() const { return connection_state_; } |
| 48 const std::string& profile_path() const { return profile_path_; } | 46 const std::string& profile_path() const { return profile_path_; } |
| 49 const std::string& error() const { return error_; } | 47 const std::string& error() const { return error_; } |
| 50 bool auto_connect() const { return auto_connect_; } | 48 bool connectable() const { return connectable_; } |
| 51 bool favorite() const { return favorite_; } | 49 |
| 52 int priority() const { return priority_; } | |
| 53 const base::DictionaryValue& proxy_config() const { return proxy_config_; } | 50 const base::DictionaryValue& proxy_config() const { return proxy_config_; } |
| 54 const NetworkUIData& ui_data() const { return ui_data_; } | 51 const NetworkUIData& ui_data() const { return ui_data_; } |
| 55 // IPConfig Properties | 52 |
| 53 // IPConfig Properties. These require an extra call to ShillIPConfigClient, |
| 54 // so cache them to avoid excessively complex client code. |
| 56 const std::string& ip_address() const { return ip_address_; } | 55 const std::string& ip_address() const { return ip_address_; } |
| 57 const std::string& gateway() const { return gateway_; } | 56 const std::string& gateway() const { return gateway_; } |
| 58 const std::vector<std::string>& dns_servers() const { return dns_servers_; } | 57 const std::vector<std::string>& dns_servers() const { return dns_servers_; } |
| 59 const int prefix_length() const { return prefix_length_; } | |
| 60 const GURL& web_proxy_auto_discovery_url() const { | 58 const GURL& web_proxy_auto_discovery_url() const { |
| 61 return web_proxy_auto_discovery_url_; | 59 return web_proxy_auto_discovery_url_; |
| 62 } | 60 } |
| 61 |
| 63 // Wireless property accessors | 62 // Wireless property accessors |
| 64 int signal_strength() const { return signal_strength_; } | 63 int signal_strength() const { return signal_strength_; } |
| 65 bool connectable() const { return connectable_; } | 64 |
| 66 // Cellular property accessors | 65 // Cellular property accessors |
| 67 const std::string& network_technology() const { | 66 const std::string& network_technology() const { |
| 68 return network_technology_; | 67 return network_technology_; |
| 69 } | 68 } |
| 70 const std::string& activation_state() const { return activation_state_; } | 69 const std::string& activation_state() const { return activation_state_; } |
| 71 const std::string& roaming() const { return roaming_; } | 70 const std::string& roaming() const { return roaming_; } |
| 72 bool activate_over_non_cellular_networks() const { | 71 bool activate_over_non_cellular_networks() const { |
| 73 return activate_over_non_cellular_networks_; | 72 return activate_over_non_cellular_networks_; |
| 74 } | 73 } |
| 75 bool cellular_out_of_credits() const { return cellular_out_of_credits_; } | 74 bool cellular_out_of_credits() const { return cellular_out_of_credits_; } |
| 76 const std::string& usage_url() const { return usage_url_; } | |
| 77 const std::string& payment_url() const { return payment_url_; } | |
| 78 const std::string& post_method() const { return post_method_; } | |
| 79 const std::string& post_data() const { return post_data_; } | |
| 80 | 75 |
| 81 // Whether this network has a CACertNSS nickname set. | 76 // Whether this network has a CACertNSS nickname set. |
| 82 bool HasCACertNSS() const { return has_ca_cert_nss_; } | 77 bool HasCACertNSS() const { return has_ca_cert_nss_; } |
| 83 | 78 |
| 84 // Returns true if |connection_state_| is a connected/connecting state. | 79 // Returns true if |connection_state_| is a connected/connecting state. |
| 85 bool IsConnectedState() const; | 80 bool IsConnectedState() const; |
| 86 bool IsConnectingState() const; | 81 bool IsConnectingState() const; |
| 87 | 82 |
| 88 // Returns true if the ONC source is a device or user policy. | 83 // Returns true if the ONC source is a device or user policy. |
| 89 bool IsManaged() const; | 84 bool IsManaged() const; |
| 90 | 85 |
| 91 // Returns true if the network properties are stored in a user profile. | 86 // Returns true if the network properties are stored in a user profile. |
| 92 bool IsPrivate() const; | 87 bool IsPrivate() const; |
| 93 | 88 |
| 94 // Returns a comma separated string of name servers. | 89 // Returns a comma separated string of name servers. |
| 95 std::string GetDnsServersAsString() const; | 90 std::string GetDnsServersAsString() const; |
| 96 | 91 |
| 97 // Converts the prefix length to a netmask string. | 92 // Converts the prefix length to a netmask string. |
| 98 std::string GetNetmask() const; | 93 std::string GetNetmask() const; |
| 99 | 94 |
| 100 // Helpers (used e.g. when a state is cached) | 95 // Helpers (used e.g. when a state is cached) |
| 101 static bool StateIsConnected(const std::string& connection_state); | 96 static bool StateIsConnected(const std::string& connection_state); |
| 102 static bool StateIsConnecting(const std::string& connection_state); | 97 static bool StateIsConnecting(const std::string& connection_state); |
| 103 | 98 |
| 104 // Helper to return a full prefixed version of an IPConfig property | 99 // Helper to return a full prefixed version of an IPConfig property key. |
| 105 // key. | |
| 106 static std::string IPConfigProperty(const char* key); | 100 static std::string IPConfigProperty(const char* key); |
| 107 | 101 |
| 108 | 102 |
| 109 private: | 103 private: |
| 110 friend class MobileActivatorTest; | 104 friend class MobileActivatorTest; |
| 111 friend class NetworkStateHandler; | 105 friend class NetworkStateHandler; |
| 112 friend class NetworkChangeNotifierChromeosUpdateTest; | 106 friend class NetworkChangeNotifierChromeosUpdateTest; |
| 113 | 107 |
| 114 // Updates |name_| from WiFi.HexSSID if provided, and validates |name_|. | 108 // Updates |name_| from WiFi.HexSSID if provided, and validates |name_|. |
| 115 // Returns true if |name_| changes. | 109 // Returns true if |name_| changes. |
| 116 bool UpdateName(const base::DictionaryValue& properties); | 110 bool UpdateName(const base::DictionaryValue& properties); |
| 117 | 111 |
| 118 // TODO(gauravsh): Audit the list of properties that we are caching. We should | 112 // Network Service properties. Avoid adding any additional properties here. |
| 119 // only be doing this for commonly accessed properties. crbug.com/252553 | 113 // Instead use NetworkConfigurationHandler::GetProperties() to asynchronously |
| 120 // Common Network Service properties | 114 // request properties from Shill. |
| 121 std::string security_; | 115 std::string security_; |
| 122 std::string device_path_; | 116 std::string device_path_; |
| 123 std::string guid_; | 117 std::string guid_; |
| 124 std::string connection_state_; | 118 std::string connection_state_; |
| 125 std::string profile_path_; | 119 std::string profile_path_; |
| 126 std::string error_; | 120 std::string error_; |
| 127 bool auto_connect_; | 121 bool connectable_; |
| 128 bool favorite_; | 122 |
| 129 int priority_; | |
| 130 // TODO(pneubeck): Remove ProxyConfig once NetworkConfigurationHandler | 123 // TODO(pneubeck): Remove ProxyConfig once NetworkConfigurationHandler |
| 131 // provides proxy configuration. crbug/241775 | 124 // provides proxy configuration. crbug.com/241775 |
| 132 base::DictionaryValue proxy_config_; | 125 base::DictionaryValue proxy_config_; |
| 126 |
| 127 // This is convenient to keep cached for now, but shouldn't be necessary; |
| 128 // avoid using it if possible. |
| 133 NetworkUIData ui_data_; | 129 NetworkUIData ui_data_; |
| 130 |
| 134 // IPConfig properties. | 131 // IPConfig properties. |
| 135 // Note: These do not correspond to actual Shill.Service properties | 132 // Note: These do not correspond to actual Shill.Service properties |
| 136 // but are derived from the service's corresponding IPConfig object. | 133 // but are derived from the service's corresponding IPConfig object. |
| 137 std::string ip_address_; | 134 std::string ip_address_; |
| 138 std::string gateway_; | 135 std::string gateway_; |
| 139 std::vector<std::string> dns_servers_; | 136 std::vector<std::string> dns_servers_; |
| 140 int prefix_length_; | 137 int prefix_length_; // Used by GetNetmask() |
| 141 GURL web_proxy_auto_discovery_url_; | 138 GURL web_proxy_auto_discovery_url_; |
| 142 // Wireless properties | 139 |
| 140 // Wireless properties, used for icons and Connect logic. |
| 143 int signal_strength_; | 141 int signal_strength_; |
| 144 bool connectable_; | 142 |
| 145 // Cellular properties | 143 // Cellular properties, used for icons, Connect, and Activation. |
| 146 std::string network_technology_; | 144 std::string network_technology_; |
| 147 std::string activation_state_; | 145 std::string activation_state_; |
| 148 std::string roaming_; | 146 std::string roaming_; |
| 149 bool activate_over_non_cellular_networks_; | 147 bool activate_over_non_cellular_networks_; |
| 150 bool cellular_out_of_credits_; | 148 bool cellular_out_of_credits_; |
| 151 // Cellular payment portal properties. | |
| 152 std::string usage_url_; | |
| 153 std::string payment_url_; | |
| 154 std::string post_method_; | |
| 155 std::string post_data_; | |
| 156 | 149 |
| 157 // Whether a deprecated CaCertNSS property of this network is set. Required | 150 // Whether a deprecated CaCertNSS property of this network is set. Required |
| 158 // for migration to PEM. | 151 // for migration to PEM. |
| 159 bool has_ca_cert_nss_; | 152 bool has_ca_cert_nss_; |
| 160 | 153 |
| 161 DISALLOW_COPY_AND_ASSIGN(NetworkState); | 154 DISALLOW_COPY_AND_ASSIGN(NetworkState); |
| 162 }; | 155 }; |
| 163 | 156 |
| 164 } // namespace chromeos | 157 } // namespace chromeos |
| 165 | 158 |
| 166 #endif // CHROMEOS_NETWORK_NETWORK_STATE_H_ | 159 #endif // CHROMEOS_NETWORK_NETWORK_STATE_H_ |
| OLD | NEW |