| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/net/proxy_config_handler.h" | 10 #include "chrome/browser/chromeos/net/proxy_config_handler.h" |
| 11 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 11 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 12 #include "chromeos/network/favorite_state.h" | 12 #include "chromeos/network/network_state.h" |
| 13 #include "chromeos/network/network_state_handler.h" | 13 #include "chromeos/network/network_state_handler.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "net/proxy/proxy_config.h" | 15 #include "net/proxy/proxy_config.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const char* ModeToString(UIProxyConfig::Mode mode) { | 21 const char* ModeToString(UIProxyConfig::Mode mode) { |
| 22 switch (mode) { | 22 switch (mode) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 NOTREACHED() << "Unrecognized mode type"; | 34 NOTREACHED() << "Unrecognized mode type"; |
| 35 return ""; | 35 return ""; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Writes the proxy config of |network| to |proxy_config|. Sets |onc_source| to | 38 // Writes the proxy config of |network| to |proxy_config|. Sets |onc_source| to |
| 39 // the source of this configuration. Returns false if no proxy was configured | 39 // the source of this configuration. Returns false if no proxy was configured |
| 40 // for this network. | 40 // for this network. |
| 41 bool GetProxyConfig(const PrefService* profile_prefs, | 41 bool GetProxyConfig(const PrefService* profile_prefs, |
| 42 const PrefService* local_state_prefs, | 42 const PrefService* local_state_prefs, |
| 43 const FavoriteState& network, | 43 const NetworkState& network, |
| 44 net::ProxyConfig* proxy_config, | 44 net::ProxyConfig* proxy_config, |
| 45 onc::ONCSource* onc_source) { | 45 onc::ONCSource* onc_source) { |
| 46 scoped_ptr<ProxyConfigDictionary> proxy_dict = | 46 scoped_ptr<ProxyConfigDictionary> proxy_dict = |
| 47 proxy_config::GetProxyConfigForFavoriteNetwork( | 47 proxy_config::GetProxyConfigForNetwork( |
| 48 profile_prefs, local_state_prefs, network, onc_source); | 48 profile_prefs, local_state_prefs, network, onc_source); |
| 49 if (!proxy_dict) | 49 if (!proxy_dict) |
| 50 return false; | 50 return false; |
| 51 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict, | 51 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict, |
| 52 proxy_config); | 52 proxy_config); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Returns true if proxy settings from |onc_source| are editable. | 55 // Returns true if proxy settings from |onc_source| are editable. |
| 56 bool IsNetworkProxySettingsEditable(const onc::ONCSource onc_source) { | 56 bool IsNetworkProxySettingsEditable(const onc::ONCSource onc_source) { |
| 57 return onc_source != onc::ONC_SOURCE_DEVICE_POLICY && | 57 return onc_source != onc::ONC_SOURCE_DEVICE_POLICY && |
| (...skipping 14 matching lines...) Expand all Loading... |
| 72 profile_prefs_ = profile_prefs; | 72 profile_prefs_ = profile_prefs; |
| 73 local_state_prefs_ = local_state_prefs; | 73 local_state_prefs_ = local_state_prefs; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void UIProxyConfigService::SetCurrentNetwork( | 76 void UIProxyConfigService::SetCurrentNetwork( |
| 77 const std::string& current_network) { | 77 const std::string& current_network) { |
| 78 current_ui_network_ = current_network; | 78 current_ui_network_ = current_network; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void UIProxyConfigService::UpdateFromPrefs() { | 81 void UIProxyConfigService::UpdateFromPrefs() { |
| 82 const FavoriteState* network = NULL; | 82 const NetworkState* network = NULL; |
| 83 if (!current_ui_network_.empty()) { | 83 if (!current_ui_network_.empty()) { |
| 84 network = NetworkHandler::Get() | 84 network = NetworkHandler::Get() |
| 85 ->network_state_handler() | 85 ->network_state_handler() |
| 86 ->GetFavoriteStateFromServicePath(current_ui_network_, | 86 ->GetNetworkStateFromServicePath(current_ui_network_, |
| 87 true /* configured_only */); | 87 true /* configured_only */); |
| 88 LOG_IF(ERROR, !network) << "Couldn't find FavoriteState for network " | 88 LOG_IF(ERROR, !network) << "Couldn't find NetworkState for network " |
| 89 << current_ui_network_; | 89 << current_ui_network_; |
| 90 } | 90 } |
| 91 if (!network) { | 91 if (!network) { |
| 92 current_ui_network_.clear(); | 92 current_ui_network_.clear(); |
| 93 current_ui_config_ = UIProxyConfig(); | 93 current_ui_config_ = UIProxyConfig(); |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 | 96 |
| 97 DetermineEffectiveConfig(*network); | 97 DetermineEffectiveConfig(*network); |
| 98 VLOG(1) << "Current ui network: " << network->name() << ", " | 98 VLOG(1) << "Current ui network: " << network->name() << ", " |
| 99 << ModeToString(current_ui_config_.mode) << ", " | 99 << ModeToString(current_ui_config_.mode) << ", " |
| 100 << ProxyPrefs::ConfigStateToDebugString(current_ui_config_.state) | 100 << ProxyPrefs::ConfigStateToDebugString(current_ui_config_.state) |
| 101 << ", modifiable:" << current_ui_config_.user_modifiable; | 101 << ", modifiable:" << current_ui_config_.user_modifiable; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void UIProxyConfigService::GetProxyConfig(UIProxyConfig* config) const { | 104 void UIProxyConfigService::GetProxyConfig(UIProxyConfig* config) const { |
| 105 *config = current_ui_config_; | 105 *config = current_ui_config_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 void UIProxyConfigService::SetProxyConfig(const UIProxyConfig& config) { | 108 void UIProxyConfigService::SetProxyConfig(const UIProxyConfig& config) { |
| 109 current_ui_config_ = config; | 109 current_ui_config_ = config; |
| 110 if (current_ui_network_.empty()) | 110 if (current_ui_network_.empty()) |
| 111 return; | 111 return; |
| 112 | 112 |
| 113 const FavoriteState* network = | 113 const NetworkState* network = |
| 114 NetworkHandler::Get() | 114 NetworkHandler::Get() |
| 115 ->network_state_handler() | 115 ->network_state_handler() |
| 116 ->GetFavoriteStateFromServicePath(current_ui_network_, | 116 ->GetNetworkStateFromServicePath(current_ui_network_, |
| 117 true /* configured_only */); | 117 true /* configured_only */); |
| 118 if (!network) { | 118 if (!network) { |
| 119 LOG(ERROR) << "Couldn't find FavoriteState for network " | 119 LOG(ERROR) << "Couldn't find NetworkState for network " |
| 120 << current_ui_network_; | 120 << current_ui_network_; |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Store config for this network. | 124 // Store config for this network. |
| 125 scoped_ptr<base::DictionaryValue> proxy_config_value( | 125 scoped_ptr<base::DictionaryValue> proxy_config_value( |
| 126 config.ToPrefProxyConfig()); | 126 config.ToPrefProxyConfig()); |
| 127 ProxyConfigDictionary proxy_config_dict(proxy_config_value.get()); | 127 ProxyConfigDictionary proxy_config_dict(proxy_config_value.get()); |
| 128 | 128 |
| 129 VLOG(1) << "Set proxy for " << current_ui_network_ | 129 VLOG(1) << "Set proxy for " << current_ui_network_ |
| 130 << " to " << *proxy_config_value; | 130 << " to " << *proxy_config_value; |
| 131 | 131 |
| 132 proxy_config::SetProxyConfigForFavoriteNetwork(proxy_config_dict, *network); | 132 proxy_config::SetProxyConfigForNetwork(proxy_config_dict, *network); |
| 133 current_ui_config_.state = ProxyPrefs::CONFIG_SYSTEM; | 133 current_ui_config_.state = ProxyPrefs::CONFIG_SYSTEM; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void UIProxyConfigService::DetermineEffectiveConfig( | 136 void UIProxyConfigService::DetermineEffectiveConfig( |
| 137 const FavoriteState& network) { | 137 const NetworkState& network) { |
| 138 DCHECK(local_state_prefs_); | 138 DCHECK(local_state_prefs_); |
| 139 | 139 |
| 140 // The pref service to read proxy settings that apply to all networks. | 140 // The pref service to read proxy settings that apply to all networks. |
| 141 // Settings from the profile overrule local state. | 141 // Settings from the profile overrule local state. |
| 142 PrefService* top_pref_service = | 142 PrefService* top_pref_service = |
| 143 profile_prefs_ ? profile_prefs_ : local_state_prefs_; | 143 profile_prefs_ ? profile_prefs_ : local_state_prefs_; |
| 144 | 144 |
| 145 // Get prefs proxy config if available. | 145 // Get prefs proxy config if available. |
| 146 net::ProxyConfig pref_config; | 146 net::ProxyConfig pref_config; |
| 147 ProxyPrefs::ConfigState pref_state = ProxyConfigServiceImpl::ReadPrefConfig( | 147 ProxyPrefs::ConfigState pref_state = ProxyConfigServiceImpl::ReadPrefConfig( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 178 } else if (!IsNetworkProxySettingsEditable(onc_source)) { | 178 } else if (!IsNetworkProxySettingsEditable(onc_source)) { |
| 179 current_ui_config_.state = ProxyPrefs::CONFIG_POLICY; | 179 current_ui_config_.state = ProxyPrefs::CONFIG_POLICY; |
| 180 current_ui_config_.user_modifiable = false; | 180 current_ui_config_.user_modifiable = false; |
| 181 } else { | 181 } else { |
| 182 current_ui_config_.user_modifiable = !ProxyConfigServiceImpl::IgnoreProxy( | 182 current_ui_config_.user_modifiable = !ProxyConfigServiceImpl::IgnoreProxy( |
| 183 profile_prefs_, network.profile_path(), onc_source); | 183 profile_prefs_, network.profile_path(), onc_source); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace chromeos | 187 } // namespace chromeos |
| OLD | NEW |