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

Side by Side Diff: chrome/browser/extensions/api/proxy/proxy_api.cc

Issue 2806283002: Revert of Stop passing raw pointers to base::Value API in c/b/chromeos and c/b/extensions (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implementation of the Chrome Extensions Proxy Settings API. 5 // Implementation of the Chrome Extensions Proxy Settings API.
6 6
7 #include "chrome/browser/extensions/api/proxy/proxy_api.h" 7 #include "chrome/browser/extensions/api/proxy/proxy_api.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 std::move(args), GURL()); 89 std::move(args), GURL());
90 } 90 }
91 } 91 }
92 92
93 ProxyPrefTransformer::ProxyPrefTransformer() { 93 ProxyPrefTransformer::ProxyPrefTransformer() {
94 } 94 }
95 95
96 ProxyPrefTransformer::~ProxyPrefTransformer() { 96 ProxyPrefTransformer::~ProxyPrefTransformer() {
97 } 97 }
98 98
99 std::unique_ptr<base::Value> ProxyPrefTransformer::ExtensionToBrowserPref( 99 base::Value* ProxyPrefTransformer::ExtensionToBrowserPref(
100 const base::Value* extension_pref, 100 const base::Value* extension_pref,
101 std::string* error, 101 std::string* error,
102 bool* bad_message) { 102 bool* bad_message) {
103 // When ExtensionToBrowserPref is called, the format of |extension_pref| 103 // When ExtensionToBrowserPref is called, the format of |extension_pref|
104 // has been verified already by the extension API to match the schema 104 // has been verified already by the extension API to match the schema
105 // defined in the extension API JSON. 105 // defined in the extension API JSON.
106 CHECK(extension_pref->IsType(base::Value::Type::DICTIONARY)); 106 CHECK(extension_pref->IsType(base::Value::Type::DICTIONARY));
107 const base::DictionaryValue* config = 107 const base::DictionaryValue* config =
108 static_cast<const base::DictionaryValue*>(extension_pref); 108 static_cast<const base::DictionaryValue*>(extension_pref);
109 109
(...skipping 13 matching lines...) Expand all
123 !helpers::GetPacMandatoryFromExtensionPref( 123 !helpers::GetPacMandatoryFromExtensionPref(
124 config, &pac_mandatory, error, bad_message) || 124 config, &pac_mandatory, error, bad_message) ||
125 !helpers::GetPacUrlFromExtensionPref( 125 !helpers::GetPacUrlFromExtensionPref(
126 config, &pac_url, error, bad_message) || 126 config, &pac_url, error, bad_message) ||
127 !helpers::GetPacDataFromExtensionPref( 127 !helpers::GetPacDataFromExtensionPref(
128 config, &pac_data, error, bad_message) || 128 config, &pac_data, error, bad_message) ||
129 !helpers::GetProxyRulesStringFromExtensionPref( 129 !helpers::GetProxyRulesStringFromExtensionPref(
130 config, &proxy_rules_string, error, bad_message) || 130 config, &proxy_rules_string, error, bad_message) ||
131 !helpers::GetBypassListFromExtensionPref( 131 !helpers::GetBypassListFromExtensionPref(
132 config, &bypass_list, error, bad_message)) { 132 config, &bypass_list, error, bad_message)) {
133 return nullptr; 133 return NULL;
134 } 134 }
135 135
136 return helpers::CreateProxyConfigDict(mode_enum, pac_mandatory, pac_url, 136 return helpers::CreateProxyConfigDict(mode_enum, pac_mandatory, pac_url,
137 pac_data, proxy_rules_string, 137 pac_data, proxy_rules_string,
138 bypass_list, error); 138 bypass_list, error)
139 .release();
139 } 140 }
140 141
141 std::unique_ptr<base::Value> ProxyPrefTransformer::BrowserToExtensionPref( 142 base::Value* ProxyPrefTransformer::BrowserToExtensionPref(
142 const base::Value* browser_pref) { 143 const base::Value* browser_pref) {
143 CHECK(browser_pref->IsType(base::Value::Type::DICTIONARY)); 144 CHECK(browser_pref->IsType(base::Value::Type::DICTIONARY));
144 145
145 // This is a dictionary wrapper that exposes the proxy configuration stored in 146 // This is a dictionary wrapper that exposes the proxy configuration stored in
146 // the browser preferences. 147 // the browser preferences.
147 ProxyConfigDictionary config( 148 ProxyConfigDictionary config(
148 static_cast<const base::DictionaryValue*>(browser_pref) 149 static_cast<const base::DictionaryValue*>(browser_pref)
149 ->CreateDeepCopy()); 150 ->CreateDeepCopy());
150 151
151 ProxyPrefs::ProxyMode mode; 152 ProxyPrefs::ProxyMode mode;
152 if (!config.GetMode(&mode)) { 153 if (!config.GetMode(&mode)) {
153 LOG(ERROR) << "Cannot determine proxy mode."; 154 LOG(ERROR) << "Cannot determine proxy mode.";
154 return nullptr; 155 return NULL;
155 } 156 }
156 157
157 // Build a new ProxyConfig instance as defined in the extension API. 158 // Build a new ProxyConfig instance as defined in the extension API.
158 std::unique_ptr<base::DictionaryValue> extension_pref( 159 std::unique_ptr<base::DictionaryValue> extension_pref(
159 new base::DictionaryValue); 160 new base::DictionaryValue);
160 161
161 extension_pref->SetString(keys::kProxyConfigMode, 162 extension_pref->SetString(keys::kProxyConfigMode,
162 ProxyPrefs::ProxyModeToString(mode)); 163 ProxyPrefs::ProxyModeToString(mode));
163 164
164 switch (mode) { 165 switch (mode) {
165 case ProxyPrefs::MODE_DIRECT: 166 case ProxyPrefs::MODE_DIRECT:
166 case ProxyPrefs::MODE_AUTO_DETECT: 167 case ProxyPrefs::MODE_AUTO_DETECT:
167 case ProxyPrefs::MODE_SYSTEM: 168 case ProxyPrefs::MODE_SYSTEM:
168 // These modes have no further parameters. 169 // These modes have no further parameters.
169 break; 170 break;
170 case ProxyPrefs::MODE_PAC_SCRIPT: { 171 case ProxyPrefs::MODE_PAC_SCRIPT: {
171 // A PAC URL either point to a PAC script or contain a base64 encoded 172 // A PAC URL either point to a PAC script or contain a base64 encoded
172 // PAC script. In either case we build a PacScript dictionary as defined 173 // PAC script. In either case we build a PacScript dictionary as defined
173 // in the extension API. 174 // in the extension API.
174 base::DictionaryValue* pac_dict = helpers::CreatePacScriptDict(config); 175 base::DictionaryValue* pac_dict = helpers::CreatePacScriptDict(config);
175 if (!pac_dict) 176 if (!pac_dict)
176 return nullptr; 177 return NULL;
177 extension_pref->Set(keys::kProxyConfigPacScript, pac_dict); 178 extension_pref->Set(keys::kProxyConfigPacScript, pac_dict);
178 break; 179 break;
179 } 180 }
180 case ProxyPrefs::MODE_FIXED_SERVERS: { 181 case ProxyPrefs::MODE_FIXED_SERVERS: {
181 // Build ProxyRules dictionary according to the extension API. 182 // Build ProxyRules dictionary according to the extension API.
182 base::DictionaryValue* proxy_rules_dict = 183 base::DictionaryValue* proxy_rules_dict =
183 helpers::CreateProxyRulesDict(config); 184 helpers::CreateProxyRulesDict(config);
184 if (!proxy_rules_dict) 185 if (!proxy_rules_dict)
185 return nullptr; 186 return NULL;
186 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); 187 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict);
187 break; 188 break;
188 } 189 }
189 case ProxyPrefs::kModeCount: 190 case ProxyPrefs::kModeCount:
190 NOTREACHED(); 191 NOTREACHED();
191 } 192 }
192 return extension_pref; 193 return extension_pref.release();
193 } 194 }
194 195
195 } // namespace extensions 196 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/proxy/proxy_api.h ('k') | chrome/browser/extensions/api/proxy/proxy_api_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698