network_state.h revision c2db58bd994c04d98e4ee2cd7565b71548655fe3
145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Copyright (c) 2012 The Chromium Authors. All rights reserved. 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Use of this source code is governed by a BSD-style license that can be 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// found in the LICENSE file. 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef CHROMEOS_NETWORK_NETWORK_STATE_H_ 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define CHROMEOS_NETWORK_NETWORK_STATE_H_ 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <string> 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <vector> 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "base/values.h" 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "chromeos/network/managed_state.h" 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "chromeos/network/network_ui_data.h" 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "chromeos/network/onc/onc_constants.h" 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnamespace chromeos { 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Simple class to provide network state information about a network service. 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// This class should always be passed as a const* and should never be held 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// on to. Store network_state->path() (defined in ManagedState) instead and 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// call NetworkStateHandler::GetNetworkState(path) to retrieve the state for 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// the network. 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgclass CHROMEOS_EXPORT NetworkState : public ManagedState { 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org public: 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org typedef std::vector<int> FrequencyList; 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org explicit NetworkState(const std::string& path); 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org virtual ~NetworkState(); 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // ManagedState overrides 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // If you change this method, update GetProperties too. 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org virtual bool PropertyChanged(const std::string& key, 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const base::Value& value) OVERRIDE; 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org virtual bool InitialPropertiesReceived( 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const base::DictionaryValue& properties) OVERRIDE; 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Fills |dictionary| with the state properties. All the properties that are 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // accepted by PropertyChanged are stored in |dictionary|, no other values are 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // stored. 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org void GetProperties(base::DictionaryValue* dictionary) const; 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Accessors 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& security() const { return security_; } 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& device_path() const { return device_path_; } 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& guid() const { return guid_; } 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& connection_state() const { return connection_state_; } 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& profile_path() const { return profile_path_; } 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& error() const { return error_; } 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& error_details() const { return error_details_; } 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool auto_connect() const { return auto_connect_; } 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool favorite() const { return favorite_; } 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int priority() const { return priority_; } 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const base::DictionaryValue& proxy_config() const { return proxy_config_; } 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const NetworkUIData& ui_data() const { return ui_data_; } 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // IPConfig Properties 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& ip_address() const { return ip_address_; } 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& gateway() const { return gateway_; } 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::vector<std::string>& dns_servers() const { return dns_servers_; } 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const int prefix_length() const { return prefix_length_; } 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Wireless property accessors 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int signal_strength() const { return signal_strength_; } 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool connectable() const { return connectable_; } 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Cellular property accessors 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& network_technology() const { 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return network_technology_; 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& activation_state() const { return activation_state_; } 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& roaming() const { return roaming_; } 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool activate_over_non_cellular_networks() const { 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return activate_over_non_cellular_networks_; 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool cellular_out_of_credits() const { return cellular_out_of_credits_; } 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& usage_url() const { return usage_url_; } 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& payment_url() const { return payment_url_; } 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& post_method() const { return post_method_; } 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& post_data() const { return post_data_; } 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Whether this network has a CACertNSS nickname set. 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool HasCACertNSS() const { return has_ca_cert_nss_; } 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Returns true if |connection_state_| is a connected/connecting state. 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool IsConnectedState() const; 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool IsConnectingState() const; 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Returns true if the ONC source is a device or user policy. 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool IsManaged() const; 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Returns true if the network properties are stored in a user profile. 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool IsPrivate() const; 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Returns a comma separated string of name servers. 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string GetDnsServersAsString() const; 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Converts the prefix length to a netmask string. 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string GetNetmask() const; 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Helpers (used e.g. when a state is cached) 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org static bool StateIsConnected(const std::string& connection_state); 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org static bool StateIsConnecting(const std::string& connection_state); 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Helper to return a full prefixed version of an IPConfig property 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // key. 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org static std::string IPConfigProperty(const char* key); 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Sets |out| to the UIData specified by |value|. Returns true if successfully 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // parsed. 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org static bool GetUIDataFromValue(const base::Value& value, NetworkUIData* out); 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Generates a name from properties."Wifi.HexSSID" if present, otherwise 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // validates properties.Name and returns a valid utf8 version. 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org static std::string GetNameFromProperties( 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const std::string& service_path, 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const base::DictionaryValue& properties); 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org private: 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org friend class NetworkStateHandler; 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org friend class NetworkChangeNotifierChromeosUpdateTest; 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Updates |name_| from WiFi.HexSSID if provided, and validates |name_|. 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Returns true if |name_| changes. 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool UpdateName(const base::DictionaryValue& properties); 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // TODO(gauravsh): Audit the list of properties that we are caching. We should 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // only be doing this for commonly accessed properties. crbug.com/252553 12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Common Network Service properties 12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string security_; 12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string device_path_; 12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string guid_; 12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string connection_state_; 13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string profile_path_; 13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string error_; 13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string error_details_; 13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool auto_connect_; 13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool favorite_; 13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int priority_; 13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // TODO(pneubeck): Remove ProxyConfig once NetworkConfigurationHandler 13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // provides proxy configuration. crbug/241775 13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org base::DictionaryValue proxy_config_; 13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org NetworkUIData ui_data_; 14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // IPConfig properties. 14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Note: These do not correspond to actual Shill.Service properties 14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // but are derived from the service's corresponding IPConfig object. 14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string ip_address_; 14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string gateway_; 14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::vector<std::string> dns_servers_; 14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int prefix_length_; 14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Wireless properties 14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int signal_strength_; 14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool connectable_; 15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Cellular properties 15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string network_technology_; 15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string activation_state_; 15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string roaming_; 15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool activate_over_non_cellular_networks_; 15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool cellular_out_of_credits_; 15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Cellular payment portal properties. 15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string usage_url_; 15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string payment_url_; 15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string post_method_; 16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::string post_data_; 16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Whether a deprecated CaCertNSS property of this network is set. Required 16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // for migration to PEM. 16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool has_ca_cert_nss_; 16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org DISALLOW_COPY_AND_ASSIGN(NetworkState); 16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}; 16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} // namespace chromeos 17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif // CHROMEOS_NETWORK_NETWORK_STATE_H_ 17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org