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

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

Issue 12230017: Declarative WR: Enable and measure request blocking until registries are loaded. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 std::make_pair(rules_registries_[profile].get(), false)); 1627 std::make_pair(rules_registries_[profile].get(), false));
1628 } 1628 }
1629 1629
1630 void* cross_profile = GetCrossProfile(profile); 1630 void* cross_profile = GetCrossProfile(profile);
1631 if (cross_profile && 1631 if (cross_profile &&
1632 rules_registries_.find(cross_profile) != rules_registries_.end()) { 1632 rules_registries_.find(cross_profile) != rules_registries_.end()) {
1633 relevant_registries.push_back( 1633 relevant_registries.push_back(
1634 std::make_pair(rules_registries_[cross_profile].get(), true)); 1634 std::make_pair(rules_registries_[cross_profile].get(), true));
1635 } 1635 }
1636 1636
1637 // TODO(mpcomplete): Eventually we'll want to turn this on, but for now, 1637 // The following block is experimentally enabled and its impact on load time
1638 // we won't block startup for declarative webrequest. I want to measure 1638 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961
1639 // its effect first.
1640 #if defined(BLOCK_STARTUP_ON_DECLARATIVE_RULES)
1641 for (RelevantRegistries::iterator i = relevant_registries.begin(); 1639 for (RelevantRegistries::iterator i = relevant_registries.begin();
1642 i != relevant_registries.end(); ++i) { 1640 i != relevant_registries.end(); ++i) {
1643 extensions::WebRequestRulesRegistry* rules_registry = i->first; 1641 extensions::WebRequestRulesRegistry* rules_registry = i->first;
1644 if (!rules_registry->IsReady()) { 1642 if (!rules_registry->IsReady()) {
1645 // The rules registry is still loading. Block this request until it 1643 // The rules registry is still loading. Block this request until it
1646 // finishes. 1644 // finishes.
1647 rules_registry->AddReadyCallback( 1645 rules_registry->AddReadyCallback(
1648 base::Bind(&ExtensionWebRequestEventRouter::OnRulesRegistryReady, 1646 base::Bind(&ExtensionWebRequestEventRouter::OnRulesRegistryReady,
1649 AsWeakPtr(), profile, event_name, request->identifier(), 1647 AsWeakPtr(), profile, event_name, request->identifier(),
1650 request_stage)); 1648 request_stage));
1651 blocked_requests_[request->identifier()].num_handlers_blocking++; 1649 blocked_requests_[request->identifier()].num_handlers_blocking++;
1652 blocked_requests_[request->identifier()].request = request; 1650 blocked_requests_[request->identifier()].request = request;
1653 blocked_requests_[request->identifier()].blocking_time = 1651 blocked_requests_[request->identifier()].blocking_time =
1654 base::Time::Now(); 1652 base::Time::Now();
1655 blocked_requests_[request->identifier()].original_response_headers = 1653 blocked_requests_[request->identifier()].original_response_headers =
1656 original_response_headers; 1654 original_response_headers;
1657 blocked_requests_[request->identifier()].extension_info_map = 1655 blocked_requests_[request->identifier()].extension_info_map =
1658 extension_info_map; 1656 extension_info_map;
1659 return true; 1657 return true;
1660 } 1658 }
1661 } 1659 }
1662 #endif
1663 1660
1664 base::Time start = base::Time::Now(); 1661 base::Time start = base::Time::Now();
1665 1662
1666 bool deltas_created = false; 1663 bool deltas_created = false;
1667 for (RelevantRegistries::iterator i = relevant_registries.begin(); 1664 for (RelevantRegistries::iterator i = relevant_registries.begin();
1668 i != relevant_registries.end(); ++i) { 1665 i != relevant_registries.end(); ++i) {
1669 extensions::WebRequestRulesRegistry* rules_registry = 1666 extensions::WebRequestRulesRegistry* rules_registry =
1670 i->first; 1667 i->first;
1671 helpers::EventResponseDeltas result = 1668 helpers::EventResponseDeltas result =
1672 rules_registry->CreateDeltas( 1669 rules_registry->CreateDeltas(
(...skipping 21 matching lines...) Expand all
1694 void* profile, 1691 void* profile,
1695 const std::string& event_name, 1692 const std::string& event_name,
1696 uint64 request_id, 1693 uint64 request_id,
1697 extensions::RequestStage request_stage) { 1694 extensions::RequestStage request_stage) {
1698 // It's possible that this request was deleted, or cancelled by a previous 1695 // It's possible that this request was deleted, or cancelled by a previous
1699 // event handler. If so, ignore this response. 1696 // event handler. If so, ignore this response.
1700 if (blocked_requests_.find(request_id) == blocked_requests_.end()) 1697 if (blocked_requests_.find(request_id) == blocked_requests_.end())
1701 return; 1698 return;
1702 1699
1703 BlockedRequest& blocked_request = blocked_requests_[request_id]; 1700 BlockedRequest& blocked_request = blocked_requests_[request_id];
1701 base::TimeDelta block_time =
1702 base::Time::Now() - blocked_request.blocking_time;
1703 UMA_HISTOGRAM_TIMES("Extensions.NetworkDelayRegistryLoad", block_time);
1704
1704 ProcessDeclarativeRules(profile, blocked_request.extension_info_map, 1705 ProcessDeclarativeRules(profile, blocked_request.extension_info_map,
1705 event_name, blocked_request.request, request_stage, 1706 event_name, blocked_request.request, request_stage,
1706 blocked_request.original_response_headers); 1707 blocked_request.original_response_headers);
1707 // Reset to NULL so that nobody relies on this being set. 1708 // Reset to NULL so that nobody relies on this being set.
1708 blocked_request.extension_info_map = NULL; 1709 blocked_request.extension_info_map = NULL;
1709 DecrementBlockCount(profile, std::string(), event_name, request_id, NULL); 1710 DecrementBlockCount(profile, std::string(), event_name, request_id, NULL);
1710 } 1711 }
1711 1712
1712 bool ExtensionWebRequestEventRouter::GetAndSetSignaled(uint64 request_id, 1713 bool ExtensionWebRequestEventRouter::GetAndSetSignaled(uint64 request_id,
1713 EventTypes event_type) { 1714 EventTypes event_type) {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 2031 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
2031 adblock = true; 2032 adblock = true;
2032 } else { 2033 } else {
2033 other = true; 2034 other = true;
2034 } 2035 }
2035 } 2036 }
2036 } 2037 }
2037 2038
2038 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 2039 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
2039 } 2040 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698