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

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

Issue 2721793002: Extensions: Make ExtensionWebRequestEventRouter leaky. (Closed)
Patch Set: Address review. 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // Note that details.event_name includes the sub-event details (e.g. "/123"). 394 // Note that details.event_name includes the sub-event details (e.g. "/123").
395 // TODO(fsamuel): <webview> events will not be removed through this code path. 395 // TODO(fsamuel): <webview> events will not be removed through this code path.
396 // <webview> events will be removed in RemoveWebViewEventListeners. Ideally, 396 // <webview> events will be removed in RemoveWebViewEventListeners. Ideally,
397 // this code should be decoupled from extensions, we should use the host ID 397 // this code should be decoupled from extensions, we should use the host ID
398 // instead, and not have two different code paths. This is a huge undertaking 398 // instead, and not have two different code paths. This is a huge undertaking
399 // unfortunately, so we'll resort to two code paths for now. 399 // unfortunately, so we'll resort to two code paths for now.
400 // 400 //
401 // Note that details.event_name is actually the sub_event_name! 401 // Note that details.event_name is actually the sub_event_name!
402 ExtensionWebRequestEventRouter::EventListener::ID id( 402 ExtensionWebRequestEventRouter::EventListener::ID id(
403 details.browser_context, details.extension_id, details.event_name, 0, 0); 403 details.browser_context, details.extension_id, details.event_name, 0, 0);
404
405 // This Unretained is safe because the ExtensionWebRequestEventRouter
406 // singleton is leaked.
404 BrowserThread::PostTask( 407 BrowserThread::PostTask(
405 BrowserThread::IO, FROM_HERE, 408 BrowserThread::IO, FROM_HERE,
406 base::Bind( 409 base::Bind(
407 &ExtensionWebRequestEventRouter::RemoveEventListener, 410 &ExtensionWebRequestEventRouter::RemoveEventListener,
408 base::Unretained(ExtensionWebRequestEventRouter::GetInstance()), id, 411 base::Unretained(ExtensionWebRequestEventRouter::GetInstance()), id,
409 false /* not strict */)); 412 false /* not strict */));
410 } 413 }
411 414
412 // Represents a single unique listener to an event, along with whatever filter 415 // Represents a single unique listener to an event, along with whatever filter
413 // parameters and extra_info_spec were specified at the time the listener was 416 // parameters and extra_info_spec were specified at the time the listener was
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 559
557 ExtensionWebRequestEventRouter::RequestFilter::~RequestFilter() { 560 ExtensionWebRequestEventRouter::RequestFilter::~RequestFilter() {
558 } 561 }
559 562
560 // 563 //
561 // ExtensionWebRequestEventRouter 564 // ExtensionWebRequestEventRouter
562 // 565 //
563 566
564 // static 567 // static
565 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() { 568 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() {
566 return base::Singleton<ExtensionWebRequestEventRouter>::get(); 569 CR_DEFINE_STATIC_LOCAL(ExtensionWebRequestEventRouter, instance, ());
Wez 2017/03/01 17:28:16 Will this have the correct behaviour with respect
karandeepb 2017/03/01 18:07:21 Yeah state will be carried over for unit tests run
Wez 2017/03/01 18:09:47 My recollection was that Singleton and LazyInstanc
karandeepb 2017/03/01 19:17:51 Yeah so there's the ShadowingAtExitManager which y
570 return &instance;
567 } 571 }
568 572
569 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter() 573 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter()
570 : request_time_tracker_(new ExtensionWebRequestTimeTracker), 574 : request_time_tracker_(new ExtensionWebRequestTimeTracker),
571 web_request_event_router_delegate_( 575 web_request_event_router_delegate_(
572 ExtensionsAPIClient::Get()->CreateWebRequestEventRouterDelegate()) {} 576 ExtensionsAPIClient::Get()->CreateWebRequestEventRouterDelegate()) {}
573 577
574 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() {
575 }
576
577 void ExtensionWebRequestEventRouter::RegisterRulesRegistry( 578 void ExtensionWebRequestEventRouter::RegisterRulesRegistry(
578 void* browser_context, 579 void* browser_context,
579 int rules_registry_id, 580 int rules_registry_id,
580 scoped_refptr<WebRequestRulesRegistry> rules_registry) { 581 scoped_refptr<WebRequestRulesRegistry> rules_registry) {
581 RulesRegistryKey key(browser_context, rules_registry_id); 582 RulesRegistryKey key(browser_context, rules_registry_id);
582 if (rules_registry.get()) 583 if (rules_registry.get())
583 rules_registries_[key] = rules_registry; 584 rules_registries_[key] = rules_registry;
584 else 585 else
585 rules_registries_.erase(key); 586 rules_registries_.erase(key);
586 } 587 }
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 // (eg when created by a URLFetcher instead of the ResourceDispatcherHost). 1102 // (eg when created by a URLFetcher instead of the ResourceDispatcherHost).
1102 const content::ResourceRequestInfo* info = 1103 const content::ResourceRequestInfo* info =
1103 content::ResourceRequestInfo::ForRequest(request); 1104 content::ResourceRequestInfo::ForRequest(request);
1104 if (content::IsBrowserSideNavigationEnabled() && info && 1105 if (content::IsBrowserSideNavigationEnabled() && info &&
1105 IsResourceTypeFrame(info->GetResourceType())) { 1106 IsResourceTypeFrame(info->GetResourceType())) {
1106 DCHECK(navigation_ui_data); 1107 DCHECK(navigation_ui_data);
1107 event_details->SetFrameData(navigation_ui_data->frame_data()); 1108 event_details->SetFrameData(navigation_ui_data->frame_data());
1108 DispatchEventToListeners(browser_context, std::move(listeners_to_dispatch), 1109 DispatchEventToListeners(browser_context, std::move(listeners_to_dispatch),
1109 std::move(event_details)); 1110 std::move(event_details));
1110 } else { 1111 } else {
1111 event_details.release()->DetermineFrameDataOnIO(base::Bind( 1112 // This Unretained is safe because the ExtensionWebRequestEventRouter
1112 &ExtensionWebRequestEventRouter::DispatchEventToListeners, AsWeakPtr(), 1113 // singleton is leaked.
1113 browser_context, base::Passed(&listeners_to_dispatch))); 1114 event_details.release()->DetermineFrameDataOnIO(
1115 base::Bind(&ExtensionWebRequestEventRouter::DispatchEventToListeners,
1116 base::Unretained(this), browser_context,
1117 base::Passed(&listeners_to_dispatch)));
1114 } 1118 }
1115 1119
1116 if (num_handlers_blocking > 0) { 1120 if (num_handlers_blocking > 0) {
1117 BlockedRequest& blocked_request = blocked_requests_[request->identifier()]; 1121 BlockedRequest& blocked_request = blocked_requests_[request->identifier()];
1118 blocked_request.request = request; 1122 blocked_request.request = request;
1119 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context); 1123 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context);
1120 blocked_request.num_handlers_blocking += num_handlers_blocking; 1124 blocked_request.num_handlers_blocking += num_handlers_blocking;
1121 blocked_request.blocking_time = base::Time::Now(); 1125 blocked_request.blocking_time = base::Time::Now();
1122 return true; 1126 return true;
1123 } 1127 }
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 1937
1934 // The following block is experimentally enabled and its impact on load time 1938 // The following block is experimentally enabled and its impact on load time
1935 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961 1939 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961
1936 for (auto it : relevant_registries) { 1940 for (auto it : relevant_registries) {
1937 WebRequestRulesRegistry* rules_registry = it.first; 1941 WebRequestRulesRegistry* rules_registry = it.first;
1938 if (rules_registry->ready().is_signaled()) 1942 if (rules_registry->ready().is_signaled())
1939 continue; 1943 continue;
1940 1944
1941 // The rules registry is still loading. Block this request until it 1945 // The rules registry is still loading. Block this request until it
1942 // finishes. 1946 // finishes.
1947 // This Unretained is safe because the ExtensionWebRequestEventRouter
1948 // singleton is leaked.
1943 rules_registry->ready().Post( 1949 rules_registry->ready().Post(
1944 FROM_HERE, 1950 FROM_HERE,
1945 base::Bind(&ExtensionWebRequestEventRouter::OnRulesRegistryReady, 1951 base::Bind(&ExtensionWebRequestEventRouter::OnRulesRegistryReady,
1946 AsWeakPtr(), browser_context, event_name, 1952 base::Unretained(this), browser_context, event_name,
1947 request->identifier(), request_stage)); 1953 request->identifier(), request_stage));
1948 BlockedRequest& blocked_request = blocked_requests_[request->identifier()]; 1954 BlockedRequest& blocked_request = blocked_requests_[request->identifier()];
1949 blocked_request.num_handlers_blocking++; 1955 blocked_request.num_handlers_blocking++;
1950 blocked_request.request = request; 1956 blocked_request.request = request;
1951 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context); 1957 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context);
1952 blocked_request.blocking_time = base::Time::Now(); 1958 blocked_request.blocking_time = base::Time::Now();
1953 blocked_request.original_response_headers = original_response_headers; 1959 blocked_request.original_response_headers = original_response_headers;
1954 blocked_request.extension_info_map = extension_info_map; 1960 blocked_request.extension_info_map = extension_info_map;
1955 return true; 1961 return true;
1956 } 1962 }
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 // Since EventListeners are segmented by browser_context, check that 2396 // Since EventListeners are segmented by browser_context, check that
2391 // last, as it is exceedingly unlikely to be different. 2397 // last, as it is exceedingly unlikely to be different.
2392 return extension_id == that.extension_id && 2398 return extension_id == that.extension_id &&
2393 sub_event_name == that.sub_event_name && 2399 sub_event_name == that.sub_event_name &&
2394 web_view_instance_id == that.web_view_instance_id && 2400 web_view_instance_id == that.web_view_instance_id &&
2395 embedder_process_id == that.embedder_process_id && 2401 embedder_process_id == that.embedder_process_id &&
2396 browser_context == that.browser_context; 2402 browser_context == that.browser_context;
2397 } 2403 }
2398 2404
2399 } // namespace extensions 2405 } // 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