Supervised users: Don't URLEscape extension update requests
[chromium-blink-merge.git] / chromeos / network / network_state.h
blobe4d9cce2cc090a730d8431e11f259c54abfcb0c5
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.
5 #ifndef CHROMEOS_NETWORK_NETWORK_STATE_H_
6 #define CHROMEOS_NETWORK_NETWORK_STATE_H_
8 #include <stdint.h>
10 #include <string>
11 #include <vector>
13 #include "base/values.h"
14 #include "chromeos/network/managed_state.h"
15 #include "components/onc/onc_constants.h"
16 #include "url/gurl.h"
18 namespace base {
19 class DictionaryValue;
20 class Value;
23 namespace chromeos {
25 // Simple class to provide network state information about a network service.
26 // This class should always be passed as a const* and should never be held
27 // on to. Store network_state->path() (defined in ManagedState) instead and
28 // call NetworkStateHandler::GetNetworkState(path) to retrieve the state for
29 // the network.
31 // Note: NetworkStateHandler will store an entry for each member of
32 // Manager.ServiceCompleteList. The visible() method indicates whether the
33 // network is visible, and the IsInProfile() method indicates whether the
34 // network is saved in a profile.
35 class CHROMEOS_EXPORT NetworkState : public ManagedState {
36 public:
37 explicit NetworkState(const std::string& path);
38 ~NetworkState() override;
40 // ManagedState overrides
41 // If you change this method, update GetProperties too.
42 bool PropertyChanged(const std::string& key,
43 const base::Value& value) override;
44 bool InitialPropertiesReceived(
45 const base::DictionaryValue& properties) override;
46 void GetStateProperties(base::DictionaryValue* dictionary) const override;
48 void IPConfigPropertiesChanged(const base::DictionaryValue& properties);
50 // Returns true, if the network requires a service activation.
51 bool RequiresActivation() const;
53 // Accessors
54 bool visible() const { return visible_; }
55 const std::string& security_class() const { return security_class_; }
56 const std::string& device_path() const { return device_path_; }
57 const std::string& guid() const { return guid_; }
58 const std::string& profile_path() const { return profile_path_; }
59 const std::string& error() const { return error_; }
60 const std::string& last_error() const { return last_error_; }
61 void clear_last_error() { last_error_.clear(); }
63 // Returns |connection_state_| if visible, kStateDisconnect otherwise.
64 std::string connection_state() const;
66 const base::DictionaryValue& proxy_config() const { return proxy_config_; }
68 // IPConfig Properties. These require an extra call to ShillIPConfigClient,
69 // so cache them to avoid excessively complex client code.
70 const std::string& ip_address() const { return ip_address_; }
71 const std::string& gateway() const { return gateway_; }
72 const std::vector<std::string>& dns_servers() const { return dns_servers_; }
73 const GURL& web_proxy_auto_discovery_url() const {
74 return web_proxy_auto_discovery_url_;
77 // Wireless property accessors
78 bool connectable() const { return connectable_; }
79 bool is_captive_portal() const { return is_captive_portal_; }
80 int signal_strength() const { return signal_strength_; }
82 // Wifi property accessors
83 const std::string& eap_method() const { return eap_method_; }
84 const std::vector<uint8_t>& raw_ssid() const { return raw_ssid_; }
86 // Cellular property accessors
87 const std::string& network_technology() const {
88 return network_technology_;
90 const std::string& activation_type() const { return activation_type_; }
91 const std::string& activation_state() const { return activation_state_; }
92 const std::string& roaming() const { return roaming_; }
93 const std::string& payment_url() const { return payment_url_; }
94 bool cellular_out_of_credits() const { return cellular_out_of_credits_; }
96 // VPN property accessors
97 const std::string& vpn_provider_type() const { return vpn_provider_type_; }
98 const std::string& third_party_vpn_provider_extension_id() const {
99 return third_party_vpn_provider_extension_id_;
102 // Returns true if |connection_state_| is a connected/connecting state.
103 bool IsConnectedState() const;
104 bool IsConnectingState() const;
106 // Returns true if this is a network stored in a profile.
107 bool IsInProfile() const;
109 // Returns true if the network properties are stored in a user profile.
110 bool IsPrivate() const;
112 // Returns the |raw_ssid| as a hex-encoded string
113 std::string GetHexSsid() const;
115 // Returns a comma separated string of name servers.
116 std::string GetDnsServersAsString() const;
118 // Converts the prefix length to a netmask string.
119 std::string GetNetmask() const;
121 // Returns a specifier for identifying this network in the absence of a GUID.
122 // This should only be used by NetworkStateHandler for keeping track of
123 // GUIDs assigned to unsaved networks.
124 std::string GetSpecifier() const;
126 // Set the GUID. Called exclusively by NetworkStateHandler.
127 void SetGuid(const std::string& guid);
129 // Helpers (used e.g. when a state, error, or shill dictionary is cached)
130 static bool StateIsConnected(const std::string& connection_state);
131 static bool StateIsConnecting(const std::string& connection_state);
132 static bool NetworkStateIsCaptivePortal(
133 const base::DictionaryValue& shill_properties);
134 static bool ErrorIsValid(const std::string& error);
136 private:
137 friend class MobileActivatorTest;
138 friend class NetworkStateHandler;
139 friend class NetworkChangeNotifierChromeosUpdateTest;
141 // Updates |name_| from WiFi.HexSSID if provided, and validates |name_|.
142 // Returns true if |name_| changes.
143 bool UpdateName(const base::DictionaryValue& properties);
145 // Set to true if the network is a member of Manager.Services.
146 bool visible_;
148 // Network Service properties. Avoid adding any additional properties here.
149 // Instead use NetworkConfigurationHandler::GetProperties() to asynchronously
150 // request properties from Shill.
151 std::string security_class_;
152 std::string eap_method_; // Needed for WiFi EAP networks
153 std::string device_path_;
154 std::string guid_;
155 std::string connection_state_;
156 std::string profile_path_;
157 std::vector<uint8_t> raw_ssid_; // Unknown encoding. Not necessarily UTF-8.
159 // Reflects the current Shill Service.Error property. This might get cleared
160 // by Shill shortly after a failure.
161 std::string error_;
163 // Last non empty Service.Error property. Cleared by NetworkConnectionHandler
164 // when a connection attempt is initiated.
165 std::string last_error_;
167 // IPConfig properties.
168 // Note: These do not correspond to actual Shill.Service properties
169 // but are derived from the service's corresponding IPConfig object.
170 std::string ip_address_;
171 std::string gateway_;
172 std::vector<std::string> dns_servers_;
173 int prefix_length_; // Used by GetNetmask()
174 GURL web_proxy_auto_discovery_url_;
176 // Wireless properties, used for icons and Connect logic.
177 bool connectable_;
178 bool is_captive_portal_;
179 int signal_strength_;
181 // Cellular properties, used for icons, Connect, and Activation.
182 std::string network_technology_;
183 std::string activation_type_;
184 std::string activation_state_;
185 std::string roaming_;
186 std::string payment_url_;
187 bool cellular_out_of_credits_;
189 // VPN properties, used to construct the display name and to show the correct
190 // configuration dialog.
191 std::string vpn_provider_type_;
192 std::string third_party_vpn_provider_extension_id_;
194 // TODO(pneubeck): Remove this once (Managed)NetworkConfigurationHandler
195 // provides proxy configuration. crbug.com/241775
196 base::DictionaryValue proxy_config_;
198 DISALLOW_COPY_AND_ASSIGN(NetworkState);
201 } // namespace chromeos
203 #endif // CHROMEOS_NETWORK_NETWORK_STATE_H_