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

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api.cc

Issue 10831150: Refactor request parameters into RequestData struct. Also make RequestStage singular. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ?? Created 8 years, 4 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 "chrome/browser/extensions/api/web_request/web_request_api.h" 5 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 blocked_requests_.erase(request_id); 1393 blocked_requests_.erase(request_id);
1394 } 1394 }
1395 return rv; 1395 return rv;
1396 } 1396 }
1397 1397
1398 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( 1398 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules(
1399 void* profile, 1399 void* profile,
1400 ExtensionInfoMap* extension_info_map, 1400 ExtensionInfoMap* extension_info_map,
1401 const std::string& event_name, 1401 const std::string& event_name,
1402 net::URLRequest* request, 1402 net::URLRequest* request,
1403 extensions::RequestStages request_stage, 1403 extensions::RequestStage request_stage,
1404 net::HttpResponseHeaders* original_response_headers) { 1404 net::HttpResponseHeaders* original_response_headers) {
1405 // Rules of the current |profile| may apply but we need to check also whether 1405 // Rules of the current |profile| may apply but we need to check also whether
1406 // there are applicable rules from extensions whose background page 1406 // there are applicable rules from extensions whose background page
1407 // spans from regular to incognito mode. 1407 // spans from regular to incognito mode.
1408 1408
1409 // First parameter identifies the registry, the second indicates whether the 1409 // First parameter identifies the registry, the second indicates whether the
1410 // registry belongs to the cross profile. 1410 // registry belongs to the cross profile.
1411 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> 1411 typedef std::pair<extensions::WebRequestRulesRegistry*, bool>
1412 RelevantRegistry; 1412 RelevantRegistry;
1413 typedef std::vector<RelevantRegistry> RelevantRegistries; 1413 typedef std::vector<RelevantRegistry> RelevantRegistries;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 } 1452 }
1453 #endif 1453 #endif
1454 1454
1455 base::Time start = base::Time::Now(); 1455 base::Time start = base::Time::Now();
1456 1456
1457 bool deltas_created = false; 1457 bool deltas_created = false;
1458 for (RelevantRegistries::iterator i = relevant_registries.begin(); 1458 for (RelevantRegistries::iterator i = relevant_registries.begin();
1459 i != relevant_registries.end(); ++i) { 1459 i != relevant_registries.end(); ++i) {
1460 extensions::WebRequestRulesRegistry* rules_registry = 1460 extensions::WebRequestRulesRegistry* rules_registry =
1461 i->first; 1461 i->first;
1462 extensions::WebRequestRule::OptionalRequestData optional_request_data;
1463 optional_request_data.original_response_headers =
1464 original_response_headers;
1465 helpers::EventResponseDeltas result = 1462 helpers::EventResponseDeltas result =
1466 rules_registry->CreateDeltas(extension_info_map, request, 1463 rules_registry->CreateDeltas(
1467 i->second, request_stage, optional_request_data); 1464 extension_info_map,
1465 extensions::WebRequestRule::RequestData(
1466 request, request_stage, original_response_headers),
1467 i->second);
1468 1468
1469 if (!result.empty()) { 1469 if (!result.empty()) {
1470 helpers::EventResponseDeltas& deltas = 1470 helpers::EventResponseDeltas& deltas =
1471 blocked_requests_[request->identifier()].response_deltas; 1471 blocked_requests_[request->identifier()].response_deltas;
1472 deltas.insert(deltas.end(), result.begin(), result.end()); 1472 deltas.insert(deltas.end(), result.begin(), result.end());
1473 deltas_created = true; 1473 deltas_created = true;
1474 } 1474 }
1475 } 1475 }
1476 1476
1477 base::TimeDelta elapsed_time = start - base::Time::Now(); 1477 base::TimeDelta elapsed_time = start - base::Time::Now();
1478 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeWebRequestNetworkDelay", 1478 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeWebRequestNetworkDelay",
1479 elapsed_time); 1479 elapsed_time);
1480 1480
1481 return deltas_created; 1481 return deltas_created;
1482 } 1482 }
1483 1483
1484 void ExtensionWebRequestEventRouter::OnRulesRegistryReady( 1484 void ExtensionWebRequestEventRouter::OnRulesRegistryReady(
1485 void* profile, 1485 void* profile,
1486 const std::string& event_name, 1486 const std::string& event_name,
1487 uint64 request_id, 1487 uint64 request_id,
1488 extensions::RequestStages request_stage) { 1488 extensions::RequestStage request_stage) {
1489 // It's possible that this request was deleted, or cancelled by a previous 1489 // It's possible that this request was deleted, or cancelled by a previous
1490 // event handler. If so, ignore this response. 1490 // event handler. If so, ignore this response.
1491 if (blocked_requests_.find(request_id) == blocked_requests_.end()) 1491 if (blocked_requests_.find(request_id) == blocked_requests_.end())
1492 return; 1492 return;
1493 1493
1494 BlockedRequest& blocked_request = blocked_requests_[request_id]; 1494 BlockedRequest& blocked_request = blocked_requests_[request_id];
1495 ProcessDeclarativeRules(profile, blocked_request.extension_info_map, 1495 ProcessDeclarativeRules(profile, blocked_request.extension_info_map,
1496 event_name, blocked_request.request, request_stage, 1496 event_name, blocked_request.request, request_stage,
1497 blocked_request.original_response_headers); 1497 blocked_request.original_response_headers);
1498 // Reset to NULL so that nobody relies on this being set. 1498 // Reset to NULL so that nobody relies on this being set.
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 1820 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
1821 adblock = true; 1821 adblock = true;
1822 } else { 1822 } else {
1823 other = true; 1823 other = true;
1824 } 1824 }
1825 } 1825 }
1826 } 1826 }
1827 1827
1828 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 1828 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
1829 } 1829 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_request/web_request_api.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698