| OLD | NEW |
| 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 "chrome/browser/chromeos/ui_proxy_config_service.h" | 5 #include "chrome/browser/chromeos/ui_proxy_config_service.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/net/proxy_config_handler.h" | 11 #include "chrome/browser/chromeos/net/proxy_config_handler.h" |
| 11 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 12 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 12 #include "chromeos/network/network_state.h" | 13 #include "chromeos/network/network_state.h" |
| 13 #include "chromeos/network/network_state_handler.h" | 14 #include "chromeos/network/network_state_handler.h" |
| 14 #include "components/device_event_log/device_event_log.h" | 15 #include "components/device_event_log/device_event_log.h" |
| 15 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | 16 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" |
| 16 #include "net/proxy/proxy_config.h" | 17 #include "net/proxy/proxy_config.h" |
| 17 | 18 |
| 18 namespace chromeos { | 19 namespace chromeos { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 37 } | 38 } |
| 38 | 39 |
| 39 // Writes the proxy config of |network| to |proxy_config|. Sets |onc_source| to | 40 // Writes the proxy config of |network| to |proxy_config|. Sets |onc_source| to |
| 40 // the source of this configuration. Returns false if no proxy was configured | 41 // the source of this configuration. Returns false if no proxy was configured |
| 41 // for this network. | 42 // for this network. |
| 42 bool GetProxyConfig(const PrefService* profile_prefs, | 43 bool GetProxyConfig(const PrefService* profile_prefs, |
| 43 const PrefService* local_state_prefs, | 44 const PrefService* local_state_prefs, |
| 44 const NetworkState& network, | 45 const NetworkState& network, |
| 45 net::ProxyConfig* proxy_config, | 46 net::ProxyConfig* proxy_config, |
| 46 onc::ONCSource* onc_source) { | 47 onc::ONCSource* onc_source) { |
| 47 scoped_ptr<ProxyConfigDictionary> proxy_dict = | 48 std::unique_ptr<ProxyConfigDictionary> proxy_dict = |
| 48 proxy_config::GetProxyConfigForNetwork( | 49 proxy_config::GetProxyConfigForNetwork(profile_prefs, local_state_prefs, |
| 49 profile_prefs, local_state_prefs, network, onc_source); | 50 network, onc_source); |
| 50 if (!proxy_dict) | 51 if (!proxy_dict) |
| 51 return false; | 52 return false; |
| 52 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict, | 53 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict, |
| 53 proxy_config); | 54 proxy_config); |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Returns true if proxy settings from |onc_source| are editable. | 57 // Returns true if proxy settings from |onc_source| are editable. |
| 57 bool IsNetworkProxySettingsEditable(const onc::ONCSource onc_source) { | 58 bool IsNetworkProxySettingsEditable(const onc::ONCSource onc_source) { |
| 58 return onc_source != onc::ONC_SOURCE_DEVICE_POLICY && | 59 return onc_source != onc::ONC_SOURCE_DEVICE_POLICY && |
| 59 onc_source != onc::ONC_SOURCE_USER_POLICY; | 60 onc_source != onc::ONC_SOURCE_USER_POLICY; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 const NetworkState* network = | 114 const NetworkState* network = |
| 114 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( | 115 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( |
| 115 current_ui_network_guid_); | 116 current_ui_network_guid_); |
| 116 if (!network || !network->IsInProfile()) { | 117 if (!network || !network->IsInProfile()) { |
| 117 NET_LOG(ERROR) << "No configured NetworkState for guid: " | 118 NET_LOG(ERROR) << "No configured NetworkState for guid: " |
| 118 << current_ui_network_guid_; | 119 << current_ui_network_guid_; |
| 119 return; | 120 return; |
| 120 } | 121 } |
| 121 | 122 |
| 122 // Store config for this network. | 123 // Store config for this network. |
| 123 scoped_ptr<base::DictionaryValue> proxy_config_value( | 124 std::unique_ptr<base::DictionaryValue> proxy_config_value( |
| 124 config.ToPrefProxyConfig()); | 125 config.ToPrefProxyConfig()); |
| 125 ProxyConfigDictionary proxy_config_dict(proxy_config_value.get()); | 126 ProxyConfigDictionary proxy_config_dict(proxy_config_value.get()); |
| 126 | 127 |
| 127 VLOG(1) << "Set proxy for " << current_ui_network_guid_ << " to " | 128 VLOG(1) << "Set proxy for " << current_ui_network_guid_ << " to " |
| 128 << *proxy_config_value; | 129 << *proxy_config_value; |
| 129 | 130 |
| 130 proxy_config::SetProxyConfigForNetwork(proxy_config_dict, *network); | 131 proxy_config::SetProxyConfigForNetwork(proxy_config_dict, *network); |
| 131 current_ui_config_.state = ProxyPrefs::CONFIG_SYSTEM; | 132 current_ui_config_.state = ProxyPrefs::CONFIG_SYSTEM; |
| 132 } | 133 } |
| 133 | 134 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } else if (!IsNetworkProxySettingsEditable(onc_source)) { | 177 } else if (!IsNetworkProxySettingsEditable(onc_source)) { |
| 177 current_ui_config_.state = ProxyPrefs::CONFIG_POLICY; | 178 current_ui_config_.state = ProxyPrefs::CONFIG_POLICY; |
| 178 current_ui_config_.user_modifiable = false; | 179 current_ui_config_.user_modifiable = false; |
| 179 } else { | 180 } else { |
| 180 current_ui_config_.user_modifiable = !ProxyConfigServiceImpl::IgnoreProxy( | 181 current_ui_config_.user_modifiable = !ProxyConfigServiceImpl::IgnoreProxy( |
| 181 profile_prefs_, network.profile_path(), onc_source); | 182 profile_prefs_, network.profile_path(), onc_source); |
| 182 } | 183 } |
| 183 } | 184 } |
| 184 | 185 |
| 185 } // namespace chromeos | 186 } // namespace chromeos |
| OLD | NEW |