Commit 4ea27b9f authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Add ProxyMode to NetworkStateProperties

This also eliminates a NetworkHandler dependency in ash/system/network.

Bug: 919691
Change-Id: Ie315a3a6589cd3f68a980ec17db9db8c83dba859
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626684Reviewed-by: default avatarPavol Marko <pmarko@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664031}
parent af294a5a
......@@ -27,8 +27,6 @@
#include "ash/system/tray/tri_view.h"
#include "base/i18n/number_formatting.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/proxy/ui_proxy_config_service.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_util.h"
#include "chromeos/services/network_config/public/mojom/constants.mojom.h"
#include "components/device_event_log/device_event_log.h"
......@@ -51,9 +49,11 @@ using chromeos::network_config::mojom::DeviceStatePropertiesPtr;
using chromeos::network_config::mojom::DeviceStateType;
using chromeos::network_config::mojom::FilterType;
using chromeos::network_config::mojom::NetworkFilter;
using chromeos::network_config::mojom::NetworkStateProperties;
using chromeos::network_config::mojom::NetworkStatePropertiesPtr;
using chromeos::network_config::mojom::NetworkType;
using chromeos::network_config::mojom::ONCSource;
using chromeos::network_config::mojom::ProxyMode;
namespace ash {
namespace tray {
......@@ -223,15 +223,9 @@ NetworkListView::UpdateNetworkListEntries() {
// Keep an index where the next child should be inserted.
int index = 0;
bool using_proxy = false;
// TODO(https://crbug.com/718072): Create UIProxyConfigService under mash, or
// provide this via network_config.mojom.
if (!::features::IsMultiProcessMash()) {
using_proxy = chromeos::NetworkHandler::Get()
->ui_proxy_config_service()
->HasDefaultNetworkProxyConfigured();
}
const NetworkStateProperties* default_network = model_->default_network();
bool using_proxy = default_network &&
default_network->proxy_mode == ProxyMode::kFixedServers;
// Show a warning that the connection might be monitored if connected to a VPN
// or if the default network has a proxy installed.
if (vpn_connected_ || using_proxy) {
......
......@@ -283,13 +283,20 @@ bool UIProxyConfigService::HasDefaultNetworkProxyConfigured() {
NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
if (!network)
return false;
return ProxyModeForNetwork(network) == ProxyPrefs::MODE_FIXED_SERVERS;
}
ProxyPrefs::ProxyMode UIProxyConfigService::ProxyModeForNetwork(
const NetworkState* network) {
// TODO(919691): Include proxies set by an extension and per-user proxies.
onc::ONCSource onc_source = onc::ONC_SOURCE_NONE;
std::unique_ptr<ProxyConfigDictionary> proxy_dict =
proxy_config::GetProxyConfigForNetwork(nullptr, local_state_prefs_,
*network, &onc_source);
ProxyPrefs::ProxyMode mode;
return (proxy_dict && proxy_dict->GetMode(&mode) &&
mode == ProxyPrefs::MODE_FIXED_SERVERS);
if (!proxy_dict || !proxy_dict->GetMode(&mode))
return ProxyPrefs::MODE_DIRECT;
return mode;
}
void UIProxyConfigService::OnPreferenceChanged(const std::string& pref_name) {
......
......@@ -10,6 +10,7 @@
#include "base/component_export.h"
#include "base/macros.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/proxy_config/proxy_prefs.h"
class PrefService;
......@@ -19,6 +20,8 @@ class Value;
namespace chromeos {
class NetworkState;
// This class provides an interface to the UI for getting a network proxy
// configuration.
// NOTE: This class must be rebuilt with the primary user's profile prefs when
......@@ -57,6 +60,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) UIProxyConfigService {
// with mode == MODE_FIXED_SERVERS.
bool HasDefaultNetworkProxyConfigured();
// Returns the ProxyMode for |network| using |local_state_prefs_|
ProxyPrefs::ProxyMode ProxyModeForNetwork(const NetworkState* network);
private:
void OnPreferenceChanged(const std::string& pref_name);
......
......@@ -19,6 +19,7 @@ static_library("network_config") {
"//chromeos/services/network_config/public/mojom",
"//components/device_event_log",
"//components/onc",
"//components/proxy_config",
"//services/service_manager/public/cpp",
]
}
......
include_rules = [
"+components/onc",
"+components/proxy_config",
]
......@@ -5,10 +5,12 @@
#include "chromeos/services/network_config/cros_network_config.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_type_pattern.h"
#include "chromeos/network/onc/onc_translation_tables.h"
#include "chromeos/network/proxy/ui_proxy_config_service.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_util.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config_mojom_traits.h"
#include "components/device_event_log/device_event_log.h"
......@@ -143,6 +145,17 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo(const NetworkState* network,
result->prohibited_by_policy = network->blocked_by_policy();
result->source = mojom::ONCSource(network->onc_source());
// NetworkHandler and UIProxyConfigService may not exist in tests.
UIProxyConfigService* ui_proxy_config_service =
NetworkHandler::IsInitialized()
? NetworkHandler::Get()->ui_proxy_config_service()
: nullptr;
result->proxy_mode =
ui_proxy_config_service
? mojom::ProxyMode(
ui_proxy_config_service->ProxyModeForNetwork(network))
: mojom::ProxyMode::kDirect;
const NetworkState::CaptivePortalProviderInfo* captive_portal_provider =
network->captive_portal_provider();
if (captive_portal_provider) {
......
......@@ -153,6 +153,7 @@ TEST_F(CrosNetworkConfigTest, GetNetworkState) {
ASSERT_TRUE(result->vpn);
EXPECT_EQ(mojom::VPNType::kL2TPIPsec, result->vpn->type);
}));
// TODO(919691): Test ProxyMode once UIProxyConfigService logic is improved.
}
TEST_F(CrosNetworkConfigTest, GetNetworkStateList) {
......
......@@ -46,15 +46,6 @@ enum DeviceStateType {
kUnavailable,
};
// The ONC source for policy or imported networks.
enum ONCSource {
kUnknown,
kNone,
kUserImport,
kDevicePolicy,
kUserPolicy,
};
// The network technology type. NOTE: 'All' and 'Wireless' are only used by
// FilterType for requesting groups of networks.
enum NetworkType {
......@@ -71,6 +62,28 @@ enum NetworkType {
kWiMAX,
};
// The ONC source for policy or imported networks.
enum ONCSource {
kUnknown,
kNone,
kUserImport,
kDevicePolicy,
kUserPolicy,
};
enum ProxyMode {
// Direct connection to the network.
kDirect,
// Try to retrieve a PAC script from http://wpad/wpad.dat.
kAutoDetect,
// Try to retrieve a PAC script from kProxyPacURL.
kPacScript,
// Use a specified list of servers.
kFixedServers,
// Use the system's proxy settings.
kSystem,
};
// The security type for WiFi Ethernet networks.
enum SecurityType {
kNone,
......@@ -189,6 +202,9 @@ struct NetworkStateProperties {
string name;
// The relative priority of the network. Larger values have higher priority.
int32 priority;
// The proxy mode affecting this network. Includes any settings that affect
// this network (i.e. global proxy settings are also considered).
ProxyMode proxy_mode;
// True for visible networks that are blocked / disallowed by policy.
bool prohibited_by_policy = false;
ONCSource source;
......
......@@ -7,6 +7,7 @@ mojom =
public_deps = [
"//components/onc",
"//components/proxy_config",
]
public_headers = [ "//components/onc/onc_constants.h" ]
......
......@@ -53,4 +53,52 @@ bool EnumTraits<chromeos::network_config::mojom::ONCSource, onc::ONCSource>::
return false;
}
chromeos::network_config::mojom::ProxyMode
EnumTraits<chromeos::network_config::mojom::ProxyMode,
ProxyPrefs::ProxyMode>::ToMojom(ProxyPrefs::ProxyMode input) {
switch (input) {
case ProxyPrefs::MODE_DIRECT:
return chromeos::network_config::mojom::ProxyMode::kDirect;
case ProxyPrefs::MODE_AUTO_DETECT:
return chromeos::network_config::mojom::ProxyMode::kAutoDetect;
case ProxyPrefs::MODE_PAC_SCRIPT:
return chromeos::network_config::mojom::ProxyMode::kPacScript;
case ProxyPrefs::MODE_FIXED_SERVERS:
return chromeos::network_config::mojom::ProxyMode::kFixedServers;
case ProxyPrefs::MODE_SYSTEM:
return chromeos::network_config::mojom::ProxyMode::kSystem;
case ProxyPrefs::kModeCount:
break;
}
NOTREACHED();
return chromeos::network_config::mojom::ProxyMode::kDirect;
}
bool EnumTraits<chromeos::network_config::mojom::ProxyMode,
ProxyPrefs::ProxyMode>::
FromMojom(chromeos::network_config::mojom::ProxyMode input,
ProxyPrefs::ProxyMode* out) {
switch (input) {
case chromeos::network_config::mojom::ProxyMode::kDirect:
*out = ProxyPrefs::MODE_DIRECT;
return true;
case chromeos::network_config::mojom::ProxyMode::kAutoDetect:
*out = ProxyPrefs::MODE_AUTO_DETECT;
return true;
case chromeos::network_config::mojom::ProxyMode::kPacScript:
*out = ProxyPrefs::MODE_PAC_SCRIPT;
return true;
case chromeos::network_config::mojom::ProxyMode::kFixedServers:
*out = ProxyPrefs::MODE_FIXED_SERVERS;
return true;
case chromeos::network_config::mojom::ProxyMode::kSystem:
*out = ProxyPrefs::MODE_SYSTEM;
return true;
}
NOTREACHED();
return false;
}
} // namespace mojo
......@@ -7,6 +7,7 @@
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
#include "components/onc/onc_constants.h"
#include "components/proxy_config/proxy_prefs.h"
#include "mojo/public/cpp/bindings/enum_traits.h"
namespace mojo {
......@@ -20,6 +21,16 @@ class EnumTraits<chromeos::network_config::mojom::ONCSource, onc::ONCSource> {
onc::ONCSource* out);
};
template <>
class EnumTraits<chromeos::network_config::mojom::ProxyMode,
ProxyPrefs::ProxyMode> {
public:
static chromeos::network_config::mojom::ProxyMode ToMojom(
ProxyPrefs::ProxyMode input);
static bool FromMojom(chromeos::network_config::mojom::ProxyMode input,
ProxyPrefs::ProxyMode* out);
};
} // namespace mojo
#endif // CHROMEOS_SERVICES_NETWORK_CONFIG_PUBLIC_MOJOM_CROS_NETWORK_CONFIG_MOJOM_TRAITS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment