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 // Sets |out| to the UIData specified by |value|. Returns true if successfully | 102 // Sets |out| to the UIData specified by |value|. Returns true if successfully |
109 // parsed. | 103 // parsed. |
110 static bool GetUIDataFromValue(const base::Value& value, NetworkUIData* out); | 104 static bool GetUIDataFromValue(const base::Value& value, NetworkUIData* out); |
111 | 105 |
112 // Generates a name from properties."Wifi.HexSSID" if present, otherwise | 106 // Generates a name from properties."Wifi.HexSSID" if present, otherwise |
113 // validates properties.Name and returns a valid utf8 version. | 107 // validates properties.Name and returns a valid utf8 version. |
114 static std::string GetNameFromProperties( | 108 static std::string GetNameFromProperties( |
115 const std::string& service_path, | 109 const std::string& service_path, |
116 const base::DictionaryValue& properties); | 110 const base::DictionaryValue& properties); |
117 | 111 |
118 private: | 112 private: |
119 friend class MobileActivatorTest; | 113 friend class MobileActivatorTest; |
120 friend class NetworkStateHandler; | 114 friend class NetworkStateHandler; |
121 friend class NetworkChangeNotifierChromeosUpdateTest; | 115 friend class NetworkChangeNotifierChromeosUpdateTest; |
122 | 116 |
123 // Updates |name_| from WiFi.HexSSID if provided, and validates |name_|. | 117 // Updates |name_| from WiFi.HexSSID if provided, and validates |name_|. |
124 // Returns true if |name_| changes. | 118 // Returns true if |name_| changes. |
125 bool UpdateName(const base::DictionaryValue& properties); | 119 bool UpdateName(const base::DictionaryValue& properties); |
126 | 120 |
127 // TODO(gauravsh): Audit the list of properties that we are caching. We should | 121 // Network Service properties. Avoid adding any additional properties here. |
128 // only be doing this for commonly accessed properties. crbug.com/252553 | 122 // Instead use NetworkConfigurationHandler::GetProperties() to asynchronously |
129 // Common Network Service properties | 123 // request properties from Shill. |
130 std::string security_; | 124 std::string security_; |
131 std::string device_path_; | 125 std::string device_path_; |
132 std::string guid_; | 126 std::string guid_; |
133 std::string connection_state_; | 127 std::string connection_state_; |
134 std::string profile_path_; | 128 std::string profile_path_; |
135 std::string error_; | 129 std::string error_; |
136 bool auto_connect_; | 130 bool connectable_; |
137 bool favorite_; | 131 |
138 int priority_; | |
139 // TODO(pneubeck): Remove ProxyConfig once NetworkConfigurationHandler | 132 // TODO(pneubeck): Remove ProxyConfig once NetworkConfigurationHandler |
140 // provides proxy configuration. crbug/241775 | 133 // provides proxy configuration. crbug.com/241775 |
141 base::DictionaryValue proxy_config_; | 134 base::DictionaryValue proxy_config_; |
| 135 |
| 136 // This is convenient to keep cached for now, but shouldn't be necessary; |
| 137 // avoid using it if possible. |
142 NetworkUIData ui_data_; | 138 NetworkUIData ui_data_; |
| 139 |
143 // IPConfig properties. | 140 // IPConfig properties. |
144 // Note: These do not correspond to actual Shill.Service properties | 141 // Note: These do not correspond to actual Shill.Service properties |
145 // but are derived from the service's corresponding IPConfig object. | 142 // but are derived from the service's corresponding IPConfig object. |
146 std::string ip_address_; | 143 std::string ip_address_; |
147 std::string gateway_; | 144 std::string gateway_; |
148 std::vector<std::string> dns_servers_; | 145 std::vector<std::string> dns_servers_; |
149 int prefix_length_; | 146 int prefix_length_; // Used by GetNetmask() |
150 GURL web_proxy_auto_discovery_url_; | 147 GURL web_proxy_auto_discovery_url_; |
151 // Wireless properties | 148 |
| 149 // Wireless properties, used for icons and Connect logic. |
152 int signal_strength_; | 150 int signal_strength_; |
153 bool connectable_; | 151 |
154 // Cellular properties | 152 // Cellular properties, used for icons, Connect, and Activation. |
155 std::string network_technology_; | 153 std::string network_technology_; |
156 std::string activation_state_; | 154 std::string activation_state_; |
157 std::string roaming_; | 155 std::string roaming_; |
158 bool activate_over_non_cellular_networks_; | 156 bool activate_over_non_cellular_networks_; |
159 bool cellular_out_of_credits_; | 157 bool cellular_out_of_credits_; |
160 // Cellular payment portal properties. | |
161 std::string usage_url_; | |
162 std::string payment_url_; | |
163 std::string post_method_; | |
164 std::string post_data_; | |
165 | 158 |
166 // Whether a deprecated CaCertNSS property of this network is set. Required | 159 // Whether a deprecated CaCertNSS property of this network is set. Required |
167 // for migration to PEM. | 160 // for migration to PEM. |
168 bool has_ca_cert_nss_; | 161 bool has_ca_cert_nss_; |
169 | 162 |
170 DISALLOW_COPY_AND_ASSIGN(NetworkState); | 163 DISALLOW_COPY_AND_ASSIGN(NetworkState); |
171 }; | 164 }; |
172 | 165 |
173 } // namespace chromeos | 166 } // namespace chromeos |
174 | 167 |
175 #endif // CHROMEOS_NETWORK_NETWORK_STATE_H_ | 168 #endif // CHROMEOS_NETWORK_NETWORK_STATE_H_ |
OLD | NEW |