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

Side by Side Diff: chromeos/network/proxy/ui_proxy_config_service.cc

Issue 2446893008: NetworkHandler: Add ui_proxy_config_service (Closed)
Patch Set: Add NetworkHandler::ShutdownPrefServices 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
« no previous file with comments | « chromeos/network/proxy/ui_proxy_config_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 #include "chromeos/network/proxy/ui_proxy_config_service.h" 5 #include "chromeos/network/proxy/ui_proxy_config_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "chromeos/network/network_state.h" 13 #include "chromeos/network/network_state.h"
12 #include "chromeos/network/network_state_handler.h" 14 #include "chromeos/network/network_state_handler.h"
13 #include "chromeos/network/proxy/proxy_config_handler.h" 15 #include "chromeos/network/proxy/proxy_config_handler.h"
14 #include "chromeos/network/proxy/proxy_config_service_impl.h" 16 #include "chromeos/network/proxy/proxy_config_service_impl.h"
15 #include "components/device_event_log/device_event_log.h" 17 #include "components/device_event_log/device_event_log.h"
16 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" 18 #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
19 #include "components/proxy_config/proxy_config_pref_names.h"
17 #include "net/proxy/proxy_config.h" 20 #include "net/proxy/proxy_config.h"
18 21
19 namespace chromeos { 22 namespace chromeos {
20 23
21 namespace { 24 namespace {
22 25
23 const char* ModeToString(UIProxyConfig::Mode mode) { 26 const char* ModeToString(UIProxyConfig::Mode mode) {
24 switch (mode) { 27 switch (mode) {
25 case UIProxyConfig::MODE_DIRECT: 28 case UIProxyConfig::MODE_DIRECT:
26 return "direct"; 29 return "direct";
(...skipping 28 matching lines...) Expand all
55 } 58 }
56 59
57 // Returns true if proxy settings from |onc_source| are editable. 60 // Returns true if proxy settings from |onc_source| are editable.
58 bool IsNetworkProxySettingsEditable(const onc::ONCSource onc_source) { 61 bool IsNetworkProxySettingsEditable(const onc::ONCSource onc_source) {
59 return onc_source != onc::ONC_SOURCE_DEVICE_POLICY && 62 return onc_source != onc::ONC_SOURCE_DEVICE_POLICY &&
60 onc_source != onc::ONC_SOURCE_USER_POLICY; 63 onc_source != onc::ONC_SOURCE_USER_POLICY;
61 } 64 }
62 65
63 } // namespace 66 } // namespace
64 67
65 UIProxyConfigService::UIProxyConfigService() 68 UIProxyConfigService::UIProxyConfigService(PrefService* profile_prefs,
66 : profile_prefs_(nullptr), local_state_prefs_(nullptr) {} 69 PrefService* local_state_prefs)
70 : profile_prefs_(profile_prefs), local_state_prefs_(local_state_prefs) {
71 if (profile_prefs_) {
72 profile_registrar_.Init(profile_prefs_);
73 profile_registrar_.Add(
74 ::proxy_config::prefs::kProxy,
75 base::Bind(&UIProxyConfigService::OnPreferenceChanged,
76 base::Unretained(this)));
77 profile_registrar_.Add(
78 ::proxy_config::prefs::kUseSharedProxies,
79 base::Bind(&UIProxyConfigService::OnPreferenceChanged,
80 base::Unretained(this)));
81 }
82
83 DCHECK(local_state_prefs_);
84 local_state_registrar_.Init(local_state_prefs_);
85 local_state_registrar_.Add(
86 ::proxy_config::prefs::kProxy,
87 base::Bind(&UIProxyConfigService::OnPreferenceChanged,
88 base::Unretained(this)));
89 }
67 90
68 UIProxyConfigService::~UIProxyConfigService() {} 91 UIProxyConfigService::~UIProxyConfigService() {}
69 92
70 void UIProxyConfigService::SetPrefs(PrefService* profile_prefs, 93 void UIProxyConfigService::UpdateFromPrefs(const std::string& network_guid) {
71 PrefService* local_state_prefs) { 94 current_ui_network_guid_ = network_guid;
72 profile_prefs_ = profile_prefs;
73 local_state_prefs_ = local_state_prefs;
74 }
75
76 void UIProxyConfigService::SetCurrentNetworkGuid(
77 const std::string& current_guid) {
78 current_ui_network_guid_ = current_guid;
79 }
80
81 void UIProxyConfigService::UpdateFromPrefs() {
82 const NetworkState* network = nullptr; 95 const NetworkState* network = nullptr;
83 if (!current_ui_network_guid_.empty()) { 96 if (!network_guid.empty()) {
84 network = 97 network =
85 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( 98 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid(
86 current_ui_network_guid_); 99 network_guid);
100 if (!network) {
101 NET_LOG(ERROR) << "No NetworkState for guid: " << network_guid;
102 } else if (!network->IsInProfile()) {
103 NET_LOG(ERROR) << "Network not in profile: " << network_guid;
104 network = nullptr;
105 }
87 } 106 }
88 if (!network || !network->IsInProfile()) { 107 if (!network) {
89 NET_LOG(ERROR) << "No configured NetworkState for guid: "
90 << current_ui_network_guid_;
91 current_ui_network_guid_.clear(); 108 current_ui_network_guid_.clear();
92 current_ui_config_ = UIProxyConfig(); 109 current_ui_config_ = UIProxyConfig();
93 return; 110 return;
94 } 111 }
95 112
96 DetermineEffectiveConfig(*network); 113 DetermineEffectiveConfig(*network);
97 VLOG(1) << "Current ui network: " << network->name() << ", " 114 VLOG(1) << "Current ui network: " << network->name() << ", "
98 << ModeToString(current_ui_config_.mode) << ", " 115 << ModeToString(current_ui_config_.mode) << ", "
99 << ProxyPrefs::ConfigStateToDebugString(current_ui_config_.state) 116 << ProxyPrefs::ConfigStateToDebugString(current_ui_config_.state)
100 << ", modifiable:" << current_ui_config_.user_modifiable; 117 << ", modifiable:" << current_ui_config_.user_modifiable;
101 } 118 }
102 119
103 void UIProxyConfigService::GetProxyConfig(UIProxyConfig* config) const { 120 void UIProxyConfigService::GetProxyConfig(const std::string& network_guid,
121 UIProxyConfig* config) {
122 if (network_guid != current_ui_network_guid_)
123 UpdateFromPrefs(network_guid);
104 *config = current_ui_config_; 124 *config = current_ui_config_;
105 } 125 }
106 126
107 void UIProxyConfigService::SetProxyConfig(const UIProxyConfig& config) { 127 void UIProxyConfigService::SetProxyConfig(const std::string& network_guid,
128 const UIProxyConfig& config) {
129 current_ui_network_guid_ = network_guid;
108 current_ui_config_ = config; 130 current_ui_config_ = config;
109 if (current_ui_network_guid_.empty()) 131 if (current_ui_network_guid_.empty())
110 return; 132 return;
111 133
112 const NetworkState* network = 134 const NetworkState* network =
113 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( 135 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid(
114 current_ui_network_guid_); 136 current_ui_network_guid_);
115 if (!network || !network->IsInProfile()) { 137 if (!network || !network->IsInProfile()) {
116 NET_LOG(ERROR) << "No configured NetworkState for guid: " 138 NET_LOG(ERROR) << "No configured NetworkState for guid: "
117 << current_ui_network_guid_; 139 << current_ui_network_guid_;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 current_ui_config_.user_modifiable = false; 192 current_ui_config_.user_modifiable = false;
171 } else if (!IsNetworkProxySettingsEditable(onc_source)) { 193 } else if (!IsNetworkProxySettingsEditable(onc_source)) {
172 current_ui_config_.state = ProxyPrefs::CONFIG_POLICY; 194 current_ui_config_.state = ProxyPrefs::CONFIG_POLICY;
173 current_ui_config_.user_modifiable = false; 195 current_ui_config_.user_modifiable = false;
174 } else { 196 } else {
175 current_ui_config_.user_modifiable = !ProxyConfigServiceImpl::IgnoreProxy( 197 current_ui_config_.user_modifiable = !ProxyConfigServiceImpl::IgnoreProxy(
176 profile_prefs_, network.profile_path(), onc_source); 198 profile_prefs_, network.profile_path(), onc_source);
177 } 199 }
178 } 200 }
179 201
202 void UIProxyConfigService::OnPreferenceChanged(const std::string& pref_name) {
203 if (!current_ui_network_guid_.empty())
204 UpdateFromPrefs(current_ui_network_guid_);
205 }
206
180 } // namespace chromeos 207 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/proxy/ui_proxy_config_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698