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

Side by Side Diff: chrome/browser/net/pref_proxy_config_service.cc

Issue 6240013: Make proxy settings one atomic dictionary in the PrefStores such that modifications are atomic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/out/Debug
Patch Set: Updated to ToT and addressed Matt's comments in base-CL Created 9 years, 10 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/net/pref_proxy_config_service.h" 5 #include "chrome/browser/net/pref_proxy_config_service.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/browser_thread.h" 8 #include "chrome/browser/browser_thread.h"
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/prefs/pref_set_observer.h" 10 #include "chrome/browser/prefs/pref_set_observer.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 FOR_EACH_OBSERVER(Observer, observers_, OnPrefProxyConfigChanged()); 79 FOR_EACH_OBSERVER(Observer, observers_, OnPrefProxyConfigChanged());
80 } 80 }
81 } 81 }
82 82
83 bool PrefProxyConfigTracker::ReadPrefConfig(net::ProxyConfig* config) { 83 bool PrefProxyConfigTracker::ReadPrefConfig(net::ProxyConfig* config) {
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
85 85
86 // Clear the configuration. 86 // Clear the configuration.
87 *config = net::ProxyConfig(); 87 *config = net::ProxyConfig();
88 88
89 ProxyPrefsDictionary proxy_dict(pref_service_->GetDictionary(prefs::kProxy));
danno 2011/02/04 10:32:13 Perhaps there should be a specific constructor on
battre 2011/02/07 14:13:47 I think this change is a great idea if we can hand
90
89 ProxyPrefs::ProxyMode mode; 91 ProxyPrefs::ProxyMode mode;
90 int proxy_mode = pref_service_->GetInteger(prefs::kProxyMode); 92 if (!proxy_dict.GetMode(&mode)) {
91 if (!ProxyPrefs::IntToProxyMode(proxy_mode, &mode)) {
92 // Fall back to system settings if the mode preference is invalid. 93 // Fall back to system settings if the mode preference is invalid.
93 return false; 94 return false;
94 } 95 }
95 96
96 switch (mode) { 97 switch (mode) {
97 case ProxyPrefs::MODE_SYSTEM: 98 case ProxyPrefs::MODE_SYSTEM:
98 // Use system settings. 99 // Use system settings.
99 return false; 100 return false;
100 case ProxyPrefs::MODE_DIRECT: 101 case ProxyPrefs::MODE_DIRECT:
101 // Ignore all the other proxy config preferences if the use of a proxy 102 // Ignore all the other proxy config preferences if the use of a proxy
102 // has been explicitly disabled. 103 // has been explicitly disabled.
103 return true; 104 return true;
104 case ProxyPrefs::MODE_AUTO_DETECT: 105 case ProxyPrefs::MODE_AUTO_DETECT:
105 config->set_auto_detect(true); 106 config->set_auto_detect(true);
106 return true; 107 return true;
107 case ProxyPrefs::MODE_PAC_SCRIPT: { 108 case ProxyPrefs::MODE_PAC_SCRIPT: {
108 if (!pref_service_->HasPrefPath(prefs::kProxyPacUrl)) { 109 std::string proxy_pac;
110 if (!proxy_dict.GetPacUrl(&proxy_pac)) {
109 LOG(ERROR) << "Proxy settings request PAC script but do not specify " 111 LOG(ERROR) << "Proxy settings request PAC script but do not specify "
110 << "its URL. Falling back to direct connection."; 112 << "its URL. Falling back to direct connection.";
111 return true; 113 return true;
112 } 114 }
113 std::string proxy_pac = pref_service_->GetString(prefs::kProxyPacUrl);
114 GURL proxy_pac_url(proxy_pac); 115 GURL proxy_pac_url(proxy_pac);
115 if (!proxy_pac_url.is_valid()) { 116 if (!proxy_pac_url.is_valid()) {
116 LOG(ERROR) << "Invalid proxy PAC url: " << proxy_pac; 117 LOG(ERROR) << "Invalid proxy PAC url: " << proxy_pac;
117 return true; 118 return true;
118 } 119 }
119 config->set_pac_url(proxy_pac_url); 120 config->set_pac_url(proxy_pac_url);
120 return true; 121 return true;
121 } 122 }
122 case ProxyPrefs::MODE_FIXED_SERVERS: { 123 case ProxyPrefs::MODE_FIXED_SERVERS: {
123 if (!pref_service_->HasPrefPath(prefs::kProxyServer)) { 124 std::string proxy_server;
125 if (!proxy_dict.GetProxyServer(&proxy_server)) {
124 LOG(ERROR) << "Proxy settings request fixed proxy servers but do not " 126 LOG(ERROR) << "Proxy settings request fixed proxy servers but do not "
125 << "specify their URLs. Falling back to direct connection."; 127 << "specify their URLs. Falling back to direct connection.";
126 return true; 128 return true;
127 } 129 }
128 std::string proxy_server =
129 pref_service_->GetString(prefs::kProxyServer);
130 config->proxy_rules().ParseFromString(proxy_server); 130 config->proxy_rules().ParseFromString(proxy_server);
131 131
132 if (pref_service_->HasPrefPath(prefs::kProxyBypassList)) { 132 std::string proxy_bypass;
133 std::string proxy_bypass = 133 if (proxy_dict.GetBypassList(&proxy_bypass)) {
134 pref_service_->GetString(prefs::kProxyBypassList);
135 config->proxy_rules().bypass_rules.ParseFromString(proxy_bypass); 134 config->proxy_rules().bypass_rules.ParseFromString(proxy_bypass);
136 } 135 }
137 return true; 136 return true;
138 } 137 }
139 case ProxyPrefs::kModeCount: { 138 case ProxyPrefs::kModeCount: {
140 // Fall through to NOTREACHED(). 139 // Fall through to NOTREACHED().
141 } 140 }
142 } 141 }
143 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; 142 NOTREACHED() << "Unknown proxy mode, falling back to system settings.";
144 return false; 143 return false;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 if (!registered_observers_) { 221 if (!registered_observers_) {
223 base_service_->AddObserver(this); 222 base_service_->AddObserver(this);
224 pref_config_tracker_->AddObserver(this); 223 pref_config_tracker_->AddObserver(this);
225 registered_observers_ = true; 224 registered_observers_ = true;
226 } 225 }
227 } 226 }
228 227
229 // static 228 // static
230 void PrefProxyConfigService::RegisterUserPrefs( 229 void PrefProxyConfigService::RegisterUserPrefs(
231 PrefService* pref_service) { 230 PrefService* pref_service) {
232 pref_service->RegisterIntegerPref(prefs::kProxyMode, ProxyPrefs::MODE_SYSTEM); 231 DictionaryValue* default_settings = ProxyPrefsDictionary::CreateSystem();
233 pref_service->RegisterStringPref(prefs::kProxyServer, ""); 232 pref_service->RegisterDictionaryPref(prefs::kProxy, default_settings);
234 pref_service->RegisterStringPref(prefs::kProxyPacUrl, "");
235 pref_service->RegisterStringPref(prefs::kProxyBypassList, "");
236 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698