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

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

Issue 2721793002: Extensions: Make ExtensionWebRequestEventRouter leaky. (Closed)
Patch Set: Delete default destructor Created 3 years, 9 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
« no previous file with comments | « extensions/browser/api/web_request/web_request_api.h ('k') | 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 "extensions/browser/api/web_request/web_request_api.h" 5 #include "extensions/browser/api/web_request/web_request_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 556
557 ExtensionWebRequestEventRouter::RequestFilter::~RequestFilter() { 557 ExtensionWebRequestEventRouter::RequestFilter::~RequestFilter() {
558 } 558 }
559 559
560 // 560 //
561 // ExtensionWebRequestEventRouter 561 // ExtensionWebRequestEventRouter
562 // 562 //
563 563
564 // static 564 // static
565 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() { 565 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() {
566 return base::Singleton<ExtensionWebRequestEventRouter>::get(); 566 static ExtensionWebRequestEventRouter* instance =
Devlin 2017/02/28 22:10:04 nit: Let's use CR_DEFINE_STATIC_LOCAL() just so th
karandeepb 2017/02/28 23:01:14 Done.
567 new ExtensionWebRequestEventRouter();
568 return instance;
567 } 569 }
568 570
569 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter() 571 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter()
570 : request_time_tracker_(new ExtensionWebRequestTimeTracker), 572 : request_time_tracker_(new ExtensionWebRequestTimeTracker),
571 web_request_event_router_delegate_( 573 web_request_event_router_delegate_(
572 ExtensionsAPIClient::Get()->CreateWebRequestEventRouterDelegate()) {} 574 ExtensionsAPIClient::Get()->CreateWebRequestEventRouterDelegate()) {}
573 575
574 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() {
575 }
576
577 void ExtensionWebRequestEventRouter::RegisterRulesRegistry( 576 void ExtensionWebRequestEventRouter::RegisterRulesRegistry(
578 void* browser_context, 577 void* browser_context,
579 int rules_registry_id, 578 int rules_registry_id,
580 scoped_refptr<WebRequestRulesRegistry> rules_registry) { 579 scoped_refptr<WebRequestRulesRegistry> rules_registry) {
581 RulesRegistryKey key(browser_context, rules_registry_id); 580 RulesRegistryKey key(browser_context, rules_registry_id);
582 if (rules_registry.get()) 581 if (rules_registry.get())
583 rules_registries_[key] = rules_registry; 582 rules_registries_[key] = rules_registry;
584 else 583 else
585 rules_registries_.erase(key); 584 rules_registries_.erase(key);
586 } 585 }
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 // (eg when created by a URLFetcher instead of the ResourceDispatcherHost). 1100 // (eg when created by a URLFetcher instead of the ResourceDispatcherHost).
1102 const content::ResourceRequestInfo* info = 1101 const content::ResourceRequestInfo* info =
1103 content::ResourceRequestInfo::ForRequest(request); 1102 content::ResourceRequestInfo::ForRequest(request);
1104 if (content::IsBrowserSideNavigationEnabled() && info && 1103 if (content::IsBrowserSideNavigationEnabled() && info &&
1105 IsResourceTypeFrame(info->GetResourceType())) { 1104 IsResourceTypeFrame(info->GetResourceType())) {
1106 DCHECK(navigation_ui_data); 1105 DCHECK(navigation_ui_data);
1107 event_details->SetFrameData(navigation_ui_data->frame_data()); 1106 event_details->SetFrameData(navigation_ui_data->frame_data());
1108 DispatchEventToListeners(browser_context, std::move(listeners_to_dispatch), 1107 DispatchEventToListeners(browser_context, std::move(listeners_to_dispatch),
1109 std::move(event_details)); 1108 std::move(event_details));
1110 } else { 1109 } else {
1111 event_details.release()->DetermineFrameDataOnIO(base::Bind( 1110 event_details.release()->DetermineFrameDataOnIO(
1112 &ExtensionWebRequestEventRouter::DispatchEventToListeners, AsWeakPtr(), 1111 base::Bind(&ExtensionWebRequestEventRouter::DispatchEventToListeners,
1113 browser_context, base::Passed(&listeners_to_dispatch))); 1112 base::Unretained(this), browser_context,
Devlin 2017/02/28 22:10:04 nit: when using Unretained, it's good practice to
karandeepb 2017/02/28 23:01:14 Done.
1113 base::Passed(&listeners_to_dispatch)));
1114 } 1114 }
1115 1115
1116 if (num_handlers_blocking > 0) { 1116 if (num_handlers_blocking > 0) {
1117 BlockedRequest& blocked_request = blocked_requests_[request->identifier()]; 1117 BlockedRequest& blocked_request = blocked_requests_[request->identifier()];
1118 blocked_request.request = request; 1118 blocked_request.request = request;
1119 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context); 1119 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context);
1120 blocked_request.num_handlers_blocking += num_handlers_blocking; 1120 blocked_request.num_handlers_blocking += num_handlers_blocking;
1121 blocked_request.blocking_time = base::Time::Now(); 1121 blocked_request.blocking_time = base::Time::Now();
1122 return true; 1122 return true;
1123 } 1123 }
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 for (auto it : relevant_registries) { 1936 for (auto it : relevant_registries) {
1937 WebRequestRulesRegistry* rules_registry = it.first; 1937 WebRequestRulesRegistry* rules_registry = it.first;
1938 if (rules_registry->ready().is_signaled()) 1938 if (rules_registry->ready().is_signaled())
1939 continue; 1939 continue;
1940 1940
1941 // The rules registry is still loading. Block this request until it 1941 // The rules registry is still loading. Block this request until it
1942 // finishes. 1942 // finishes.
1943 rules_registry->ready().Post( 1943 rules_registry->ready().Post(
1944 FROM_HERE, 1944 FROM_HERE,
1945 base::Bind(&ExtensionWebRequestEventRouter::OnRulesRegistryReady, 1945 base::Bind(&ExtensionWebRequestEventRouter::OnRulesRegistryReady,
1946 AsWeakPtr(), browser_context, event_name, 1946 base::Unretained(this), browser_context, event_name,
1947 request->identifier(), request_stage)); 1947 request->identifier(), request_stage));
1948 BlockedRequest& blocked_request = blocked_requests_[request->identifier()]; 1948 BlockedRequest& blocked_request = blocked_requests_[request->identifier()];
1949 blocked_request.num_handlers_blocking++; 1949 blocked_request.num_handlers_blocking++;
1950 blocked_request.request = request; 1950 blocked_request.request = request;
1951 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context); 1951 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context);
1952 blocked_request.blocking_time = base::Time::Now(); 1952 blocked_request.blocking_time = base::Time::Now();
1953 blocked_request.original_response_headers = original_response_headers; 1953 blocked_request.original_response_headers = original_response_headers;
1954 blocked_request.extension_info_map = extension_info_map; 1954 blocked_request.extension_info_map = extension_info_map;
1955 return true; 1955 return true;
1956 } 1956 }
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 // Since EventListeners are segmented by browser_context, check that 2390 // Since EventListeners are segmented by browser_context, check that
2391 // last, as it is exceedingly unlikely to be different. 2391 // last, as it is exceedingly unlikely to be different.
2392 return extension_id == that.extension_id && 2392 return extension_id == that.extension_id &&
2393 sub_event_name == that.sub_event_name && 2393 sub_event_name == that.sub_event_name &&
2394 web_view_instance_id == that.web_view_instance_id && 2394 web_view_instance_id == that.web_view_instance_id &&
2395 embedder_process_id == that.embedder_process_id && 2395 embedder_process_id == that.embedder_process_id &&
2396 browser_context == that.browser_context; 2396 browser_context == that.browser_context;
2397 } 2397 }
2398 2398
2399 } // namespace extensions 2399 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/web_request/web_request_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698