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

Side by Side Diff: chrome/browser/prefs/proxy_prefs.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/prefs/proxy_prefs.h" 5 #include "chrome/browser/prefs/proxy_prefs.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 namespace ProxyPrefs { 10 namespace ProxyPrefs {
11 11
12 const char kDirectProxyModeName[] = "direct"; 12 const char kDirectProxyModeName[] = "direct";
13 const char kAutoDetectProxyModeName[] = "auto_detect"; 13 const char kAutoDetectProxyModeName[] = "auto_detect";
14 const char kPacScriptProxyModeName[] = "pac_script"; 14 const char kPacScriptProxyModeName[] = "pac_script";
15 const char kFixedServersProxyModeName[] = "fixed_servers"; 15 const char kFixedServersProxyModeName[] = "fixed_servers";
16 const char kSystemProxyModeName[] = "system"; 16 const char kSystemProxyModeName[] = "system";
17 17
18 } 18 }
19 19
20 namespace { 20 namespace {
21 21
22 // These names are exposed to the proxy extension API. They must be in sync 22 // These names are exposed to the proxy extension API. They must be in sync
23 // with the constants of ProxyPrefs. 23 // with the constants of ProxyPrefs.
24 const char* kProxyModeNames[] = { ProxyPrefs::kDirectProxyModeName, 24 const char* kProxyModeNames[] = { ProxyPrefs::kDirectProxyModeName,
25 ProxyPrefs::kAutoDetectProxyModeName, 25 ProxyPrefs::kAutoDetectProxyModeName,
26 ProxyPrefs::kPacScriptProxyModeName, 26 ProxyPrefs::kPacScriptProxyModeName,
27 ProxyPrefs::kFixedServersProxyModeName, 27 ProxyPrefs::kFixedServersProxyModeName,
28 ProxyPrefs::kSystemProxyModeName }; 28 ProxyPrefs::kSystemProxyModeName };
29 29
30 // Integer to specify the type of proxy settings.
31 // See ProxyPrefs for possible values and interactions with the other proxy
32 // preferences.
33 const char kProxyMode[] = "mode";
34 // String specifying the proxy server. For a specification of the expected
35 // syntax see net::ProxyConfig::ProxyRules::ParseFromString().
36 const char kProxyServer[] = "server";
37 // URL to the proxy .pac file.
38 const char kProxyPacUrl[] = "pac_url";
39 // String containing proxy bypass rules. For a specification of the
40 // expected syntax see net::ProxyBypassRules::ParseFromString().
41 const char kProxyBypassList[] = "bypass_list";
42
30 } // namespace 43 } // namespace
31 44
32 namespace ProxyPrefs { 45 namespace ProxyPrefs {
33 46
34 COMPILE_ASSERT(arraysize(kProxyModeNames) == kModeCount, 47 COMPILE_ASSERT(arraysize(kProxyModeNames) == kModeCount,
35 kProxyModeNames_must_have_size_of_NUM_MODES); 48 kProxyModeNames_must_have_size_of_NUM_MODES);
36 49
37 bool IntToProxyMode(int in_value, ProxyMode* out_value) { 50 bool IntToProxyMode(int in_value, ProxyMode* out_value) {
38 DCHECK(out_value); 51 DCHECK(out_value);
39 if (in_value < 0 || in_value >= kModeCount) 52 if (in_value < 0 || in_value >= kModeCount)
40 return false; 53 return false;
41 *out_value = static_cast<ProxyMode>(in_value); 54 *out_value = static_cast<ProxyMode>(in_value);
42 return true; 55 return true;
43 } 56 }
44 57
45 // static 58 // static
46 bool StringToProxyMode(const std::string& in_value, ProxyMode* out_value) { 59 bool StringToProxyMode(const std::string& in_value, ProxyMode* out_value) {
47 DCHECK(out_value); 60 DCHECK(out_value);
48 for (int i = 0; i < kModeCount; i++) { 61 for (int i = 0; i < kModeCount; i++) {
49 if (in_value == kProxyModeNames[i]) 62 if (in_value == kProxyModeNames[i])
50 return IntToProxyMode(i, out_value); 63 return IntToProxyMode(i, out_value);
51 } 64 }
52 return false; 65 return false;
53 } 66 }
54 67
55 } // namespace 68 } // namespace
69
70 ProxyPrefsDictionary::ProxyPrefsDictionary(const DictionaryValue* dict)
71 : dict_(dict) {
72 CHECK(dict);
73 }
74
75 bool ProxyPrefsDictionary::GetMode(ProxyPrefs::ProxyMode* out) const {
76 std::string mode_str;
77 return dict_->GetString(kProxyMode, &mode_str)
78 && StringToProxyMode(mode_str, out);
79 }
80
81 bool ProxyPrefsDictionary::GetPacUrl(std::string* out) const {
82 return dict_->GetString(kProxyPacUrl, out);
83 }
84
85 bool ProxyPrefsDictionary::GetProxyServer(std::string* out) const {
86 return dict_->GetString(kProxyServer, out);
87 }
88
89 bool ProxyPrefsDictionary::GetBypassList(std::string* out) const {
90 return dict_->GetString(kProxyBypassList, out);
91 }
92
93 // static
94 DictionaryValue* ProxyPrefsDictionary::CreateDirect() {
95 return CreateDictionary(ProxyPrefs::MODE_DIRECT, "", "", "");
96 }
97
98 // static
99 DictionaryValue* ProxyPrefsDictionary::CreateAutoDetect() {
100 return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, "", "", "");
101 }
102
103 // static
104 DictionaryValue* ProxyPrefsDictionary::CreatePacScript(
105 const std::string& pac_url) {
106 return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, pac_url, "", "");
107 }
108
109 // static
110 DictionaryValue* ProxyPrefsDictionary::CreateFixedServers(
111 const std::string& proxy_server,
112 const std::string& bypass_list) {
113 return CreateDictionary(
114 ProxyPrefs::MODE_FIXED_SERVERS, "", proxy_server, bypass_list);
115 }
116
117 // static
118 DictionaryValue* ProxyPrefsDictionary::CreateSystem() {
119 return CreateDictionary(ProxyPrefs::MODE_SYSTEM, "", "", "");
120 }
121
122 // static
123 DictionaryValue* ProxyPrefsDictionary::CreateDictionary(
124 ProxyPrefs::ProxyMode mode,
125 const std::string& pac_url,
126 const std::string& proxy_server,
127 const std::string& bypass_list) {
128 DictionaryValue* dict = new DictionaryValue();
129 dict->SetString(kProxyMode, kProxyModeNames[mode]);
130 if (!pac_url.empty())
131 dict->SetString(kProxyPacUrl, pac_url);
132 if (!proxy_server.empty())
133 dict->SetString(kProxyServer, proxy_server);
134 if (!bypass_list.empty())
135 dict->SetString(kProxyBypassList, bypass_list);
136 return dict;
137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698