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

Side by Side Diff: extensions/browser/api/web_request/web_request_api_helpers.cc

Issue 2899743002: Remove raw base::DictionaryValue::Set in //extensions (Closed)
Patch Set: Addressed nit Created 3 years, 6 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 #include "extensions/browser/api/web_request/web_request_api_helpers.h" 5 #include "extensions/browser/api/web_request/web_request_api_helpers.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <cmath> 11 #include <cmath>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 #include "base/values.h" 21 #include "base/values.h"
21 #include "components/web_cache/browser/web_cache_manager.h" 22 #include "components/web_cache/browser/web_cache_manager.h"
22 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
24 #include "extensions/browser/api/web_request/web_request_api_constants.h" 25 #include "extensions/browser/api/web_request/web_request_api_constants.h"
25 #include "extensions/browser/extension_registry.h" 26 #include "extensions/browser/extension_registry.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // callback. 217 // callback.
217 net::NetLogParametersCallback CreateNetLogExtensionIdCallback( 218 net::NetLogParametersCallback CreateNetLogExtensionIdCallback(
218 const EventResponseDelta* delta) { 219 const EventResponseDelta* delta) {
219 return net::NetLog::StringCallback("extension_id", &delta->extension_id); 220 return net::NetLog::StringCallback("extension_id", &delta->extension_id);
220 } 221 }
221 222
222 // Creates NetLog parameters to indicate that an extension modified a request. 223 // Creates NetLog parameters to indicate that an extension modified a request.
223 std::unique_ptr<base::Value> NetLogModificationCallback( 224 std::unique_ptr<base::Value> NetLogModificationCallback(
224 const EventResponseDelta* delta, 225 const EventResponseDelta* delta,
225 net::NetLogCaptureMode capture_mode) { 226 net::NetLogCaptureMode capture_mode) {
226 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 227 auto dict = base::MakeUnique<base::DictionaryValue>();
227 dict->SetString("extension_id", delta->extension_id); 228 dict->SetString("extension_id", delta->extension_id);
228 229
229 base::ListValue* modified_headers = new base::ListValue(); 230 auto modified_headers = base::MakeUnique<base::ListValue>();
230 net::HttpRequestHeaders::Iterator modification( 231 net::HttpRequestHeaders::Iterator modification(
231 delta->modified_request_headers); 232 delta->modified_request_headers);
232 while (modification.GetNext()) { 233 while (modification.GetNext()) {
233 std::string line = modification.name() + ": " + modification.value(); 234 std::string line = modification.name() + ": " + modification.value();
234 modified_headers->AppendString(line); 235 modified_headers->AppendString(line);
235 } 236 }
236 dict->Set("modified_headers", modified_headers); 237 dict->Set("modified_headers", std::move(modified_headers));
237 238
238 base::ListValue* deleted_headers = new base::ListValue(); 239 auto deleted_headers = base::MakeUnique<base::ListValue>();
239 for (std::vector<std::string>::const_iterator key = 240 for (std::vector<std::string>::const_iterator key =
240 delta->deleted_request_headers.begin(); 241 delta->deleted_request_headers.begin();
241 key != delta->deleted_request_headers.end(); 242 key != delta->deleted_request_headers.end();
242 ++key) { 243 ++key) {
243 deleted_headers->AppendString(*key); 244 deleted_headers->AppendString(*key);
244 } 245 }
245 dict->Set("deleted_headers", deleted_headers); 246 dict->Set("deleted_headers", std::move(deleted_headers));
246 return std::move(dict); 247 return std::move(dict);
247 } 248 }
248 249
249 bool InDecreasingExtensionInstallationTimeOrder( 250 bool InDecreasingExtensionInstallationTimeOrder(
250 const linked_ptr<EventResponseDelta>& a, 251 const linked_ptr<EventResponseDelta>& a,
251 const linked_ptr<EventResponseDelta>& b) { 252 const linked_ptr<EventResponseDelta>& b) {
252 return a->extension_install_time > b->extension_install_time; 253 return a->extension_install_time > b->extension_install_time;
253 } 254 }
254 255
255 base::ListValue* StringToCharList(const std::string& s) { 256 std::unique_ptr<base::ListValue> StringToCharList(const std::string& s) {
256 base::ListValue* result = new base::ListValue; 257 auto result = base::MakeUnique<base::ListValue>();
257 for (size_t i = 0, n = s.size(); i < n; ++i) { 258 for (size_t i = 0, n = s.size(); i < n; ++i) {
258 result->AppendInteger(*reinterpret_cast<const unsigned char*>(&s[i])); 259 result->AppendInteger(*reinterpret_cast<const unsigned char*>(&s[i]));
259 } 260 }
260 return result; 261 return result;
261 } 262 }
262 263
263 bool CharListToString(const base::ListValue* list, std::string* out) { 264 bool CharListToString(const base::ListValue* list, std::string* out) {
264 if (!list) 265 if (!list)
265 return false; 266 return false;
266 const size_t list_length = list->GetSize(); 267 const size_t list_length = list->GetSize();
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 1204 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
1204 base::Bind(&ClearCacheOnNavigationOnUI)); 1205 base::Bind(&ClearCacheOnNavigationOnUI));
1205 } 1206 }
1206 } 1207 }
1207 1208
1208 // Converts the |name|, |value| pair of a http header to a HttpHeaders 1209 // Converts the |name|, |value| pair of a http header to a HttpHeaders
1209 // dictionary. 1210 // dictionary.
1210 std::unique_ptr<base::DictionaryValue> CreateHeaderDictionary( 1211 std::unique_ptr<base::DictionaryValue> CreateHeaderDictionary(
1211 const std::string& name, 1212 const std::string& name,
1212 const std::string& value) { 1213 const std::string& value) {
1213 std::unique_ptr<base::DictionaryValue> header(new base::DictionaryValue()); 1214 auto header = base::MakeUnique<base::DictionaryValue>();
1214 header->SetString(keys::kHeaderNameKey, name); 1215 header->SetString(keys::kHeaderNameKey, name);
1215 if (base::IsStringUTF8(value)) { 1216 if (base::IsStringUTF8(value)) {
1216 header->SetString(keys::kHeaderValueKey, value); 1217 header->SetString(keys::kHeaderValueKey, value);
1217 } else { 1218 } else {
1218 header->Set(keys::kHeaderBinaryValueKey, 1219 header->Set(keys::kHeaderBinaryValueKey,
1219 StringToCharList(value)); 1220 StringToCharList(value));
1220 } 1221 }
1221 return header; 1222 return header;
1222 } 1223 }
1223 1224
1224 } // namespace extension_web_request_api_helpers 1225 } // namespace extension_web_request_api_helpers
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698