Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: chrome/browser/chromeos/ui_proxy_config_service.cc

Issue 2442313003: Move some proxy config code out of src/chrome (Closed)
Patch Set: Fix DEPS Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #include "chrome/browser/chromeos/ui_proxy_config_service.h"
6
7 #include <memory>
8
9 #include "base/logging.h"
10 #include "base/values.h"
11 #include "chrome/browser/chromeos/net/proxy_config_handler.h"
12 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
13 #include "chromeos/network/network_state.h"
14 #include "chromeos/network/network_state_handler.h"
15 #include "components/device_event_log/device_event_log.h"
16 #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
17 #include "net/proxy/proxy_config.h"
18
19 namespace chromeos {
20
21 namespace {
22
23 const char* ModeToString(UIProxyConfig::Mode mode) {
24 switch (mode) {
25 case UIProxyConfig::MODE_DIRECT:
26 return "direct";
27 case UIProxyConfig::MODE_AUTO_DETECT:
28 return "auto-detect";
29 case UIProxyConfig::MODE_PAC_SCRIPT:
30 return "pacurl";
31 case UIProxyConfig::MODE_SINGLE_PROXY:
32 return "single-proxy";
33 case UIProxyConfig::MODE_PROXY_PER_SCHEME:
34 return "proxy-per-scheme";
35 }
36 NOTREACHED() << "Unrecognized mode type";
37 return "";
38 }
39
40 // Writes the proxy config of |network| to |proxy_config|. Sets |onc_source| to
41 // the source of this configuration. Returns false if no proxy was configured
42 // for this network.
43 bool GetProxyConfig(const PrefService* profile_prefs,
44 const PrefService* local_state_prefs,
45 const NetworkState& network,
46 net::ProxyConfig* proxy_config,
47 onc::ONCSource* onc_source) {
48 std::unique_ptr<ProxyConfigDictionary> proxy_dict =
49 proxy_config::GetProxyConfigForNetwork(profile_prefs, local_state_prefs,
50 network, onc_source);
51 if (!proxy_dict)
52 return false;
53 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict,
54 proxy_config);
55 }
56
57 // Returns true if proxy settings from |onc_source| are editable.
58 bool IsNetworkProxySettingsEditable(const onc::ONCSource onc_source) {
59 return onc_source != onc::ONC_SOURCE_DEVICE_POLICY &&
60 onc_source != onc::ONC_SOURCE_USER_POLICY;
61 }
62
63 } // namespace
64
65 UIProxyConfigService::UIProxyConfigService()
66 : profile_prefs_(nullptr), local_state_prefs_(nullptr) {
67 }
68
69 UIProxyConfigService::~UIProxyConfigService() {
70 }
71
72 void UIProxyConfigService::SetPrefs(PrefService* profile_prefs,
73 PrefService* local_state_prefs) {
74 profile_prefs_ = profile_prefs;
75 local_state_prefs_ = local_state_prefs;
76 }
77
78 void UIProxyConfigService::SetCurrentNetworkGuid(
79 const std::string& current_guid) {
80 current_ui_network_guid_ = current_guid;
81 }
82
83 void UIProxyConfigService::UpdateFromPrefs() {
84 const NetworkState* network = nullptr;
85 if (!current_ui_network_guid_.empty()) {
86 network =
87 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid(
88 current_ui_network_guid_);
89 }
90 if (!network || !network->IsInProfile()) {
91 NET_LOG(ERROR) << "No configured NetworkState for guid: "
92 << current_ui_network_guid_;
93 current_ui_network_guid_.clear();
94 current_ui_config_ = UIProxyConfig();
95 return;
96 }
97
98 DetermineEffectiveConfig(*network);
99 VLOG(1) << "Current ui network: " << network->name() << ", "
100 << ModeToString(current_ui_config_.mode) << ", "
101 << ProxyPrefs::ConfigStateToDebugString(current_ui_config_.state)
102 << ", modifiable:" << current_ui_config_.user_modifiable;
103 }
104
105 void UIProxyConfigService::GetProxyConfig(UIProxyConfig* config) const {
106 *config = current_ui_config_;
107 }
108
109 void UIProxyConfigService::SetProxyConfig(const UIProxyConfig& config) {
110 current_ui_config_ = config;
111 if (current_ui_network_guid_.empty())
112 return;
113
114 const NetworkState* network =
115 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid(
116 current_ui_network_guid_);
117 if (!network || !network->IsInProfile()) {
118 NET_LOG(ERROR) << "No configured NetworkState for guid: "
119 << current_ui_network_guid_;
120 return;
121 }
122
123 // Store config for this network.
124 std::unique_ptr<base::DictionaryValue> proxy_config_value(
125 config.ToPrefProxyConfig());
126 ProxyConfigDictionary proxy_config_dict(proxy_config_value.get());
127
128 VLOG(1) << "Set proxy for " << current_ui_network_guid_ << " to "
129 << *proxy_config_value;
130
131 proxy_config::SetProxyConfigForNetwork(proxy_config_dict, *network);
132 current_ui_config_.state = ProxyPrefs::CONFIG_SYSTEM;
133 }
134
135 void UIProxyConfigService::DetermineEffectiveConfig(
136 const NetworkState& network) {
137 DCHECK(local_state_prefs_);
138
139 // The pref service to read proxy settings that apply to all networks.
140 // Settings from the profile overrule local state.
141 PrefService* top_pref_service =
142 profile_prefs_ ? profile_prefs_ : local_state_prefs_;
143
144 // Get prefs proxy config if available.
145 net::ProxyConfig pref_config;
146 ProxyPrefs::ConfigState pref_state = ProxyConfigServiceImpl::ReadPrefConfig(
147 top_pref_service, &pref_config);
148
149 // Get network proxy config if available.
150 net::ProxyConfig network_config;
151 net::ProxyConfigService::ConfigAvailability network_availability =
152 net::ProxyConfigService::CONFIG_UNSET;
153 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE;
154 if (chromeos::GetProxyConfig(profile_prefs_,
155 local_state_prefs_,
156 network,
157 &network_config,
158 &onc_source)) {
159 // Network is private or shared with user using shared proxies.
160 VLOG(1) << this << ": using proxy of network: " << network.path();
161 network_availability = net::ProxyConfigService::CONFIG_VALID;
162 }
163
164 // Determine effective proxy config, either from prefs or network.
165 ProxyPrefs::ConfigState effective_config_state;
166 net::ProxyConfig effective_config;
167 ProxyConfigServiceImpl::GetEffectiveProxyConfig(
168 pref_state, pref_config,
169 network_availability, network_config, false,
170 &effective_config_state, &effective_config);
171
172 // Store effective proxy into |current_ui_config_|.
173 current_ui_config_.FromNetProxyConfig(effective_config);
174 current_ui_config_.state = effective_config_state;
175 if (ProxyConfigServiceImpl::PrefPrecedes(effective_config_state)) {
176 current_ui_config_.user_modifiable = false;
177 } else if (!IsNetworkProxySettingsEditable(onc_source)) {
178 current_ui_config_.state = ProxyPrefs::CONFIG_POLICY;
179 current_ui_config_.user_modifiable = false;
180 } else {
181 current_ui_config_.user_modifiable = !ProxyConfigServiceImpl::IgnoreProxy(
182 profile_prefs_, network.profile_path(), onc_source);
183 }
184 }
185
186 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/ui_proxy_config_service.h ('k') | chrome/browser/net/proxy_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698