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

Side by Side Diff: components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle.cc

Issue 2858483003: [subresource_filter] Move throttle insertion into the client (Closed)
Patch Set: fix rebase Created 3 years, 7 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 | « chrome/browser/subresource_filter/navigation_throttle_util.cc ('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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_activation_throttle.h" 5 #include "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_activation_throttle.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
12 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" 12 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h"
13 #include "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_client.h" 13 #include "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_client.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/navigation_handle.h" 15 #include "content/public/browser/navigation_handle.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 17
18 namespace subresource_filter { 18 namespace subresource_filter {
19 19
20 SubresourceFilterSafeBrowsingActivationThrottle:: 20 SubresourceFilterSafeBrowsingActivationThrottle::
21 SubresourceFilterSafeBrowsingActivationThrottle( 21 SubresourceFilterSafeBrowsingActivationThrottle(
22 content::NavigationHandle* handle, 22 content::NavigationHandle* handle,
23 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 23 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
24 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> 24 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
25 database_manager) 25 database_manager)
26 : NavigationThrottle(handle), 26 : NavigationThrottle(handle),
27 database_manager_(std::move(database_manager)), 27 io_task_runner_(std::move(io_task_runner)),
28 io_task_runner_(io_task_runner), 28 // The throttle can be created without a valid database manager. If so, it
29 database_client_(new SubresourceFilterSafeBrowsingClient( 29 // becomes a pass-through throttle and should never defer.
30 database_manager_, 30 database_client_(database_manager
31 AsWeakPtr(), 31 ? new SubresourceFilterSafeBrowsingClient(
32 io_task_runner, 32 std::move(database_manager),
33 base::ThreadTaskRunnerHandle::Get()), 33 AsWeakPtr(),
34 io_task_runner_,
35 base::ThreadTaskRunnerHandle::Get())
36 : nullptr,
34 base::OnTaskRunnerDeleter(io_task_runner_)) {} 37 base::OnTaskRunnerDeleter(io_task_runner_)) {}
35 38
36 SubresourceFilterSafeBrowsingActivationThrottle:: 39 SubresourceFilterSafeBrowsingActivationThrottle::
37 ~SubresourceFilterSafeBrowsingActivationThrottle() { 40 ~SubresourceFilterSafeBrowsingActivationThrottle() {
38 // TODO(csharrison): Log metrics based on check_results_. 41 // TODO(csharrison): Log metrics based on check_results_.
39 } 42 }
40 43
41 content::NavigationThrottle::ThrottleCheckResult 44 content::NavigationThrottle::ThrottleCheckResult
42 SubresourceFilterSafeBrowsingActivationThrottle::WillStartRequest() { 45 SubresourceFilterSafeBrowsingActivationThrottle::WillStartRequest() {
43 CheckCurrentUrl(); 46 CheckCurrentUrl();
44 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; 47 return content::NavigationThrottle::ThrottleCheckResult::PROCEED;
45 } 48 }
46 49
47 content::NavigationThrottle::ThrottleCheckResult 50 content::NavigationThrottle::ThrottleCheckResult
48 SubresourceFilterSafeBrowsingActivationThrottle::WillRedirectRequest() { 51 SubresourceFilterSafeBrowsingActivationThrottle::WillRedirectRequest() {
49 CheckCurrentUrl(); 52 CheckCurrentUrl();
50 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; 53 return content::NavigationThrottle::ThrottleCheckResult::PROCEED;
51 } 54 }
52 55
53 content::NavigationThrottle::ThrottleCheckResult 56 content::NavigationThrottle::ThrottleCheckResult
54 SubresourceFilterSafeBrowsingActivationThrottle::WillProcessResponse() { 57 SubresourceFilterSafeBrowsingActivationThrottle::WillProcessResponse() {
58 if (!database_client_)
59 return content::NavigationThrottle::PROCEED;
60
55 // No need to defer the navigation if the check already happened. 61 // No need to defer the navigation if the check already happened.
56 if (check_results_.back().finished) { 62 if (check_results_.back().finished) {
57 NotifyResult(); 63 NotifyResult();
58 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; 64 return content::NavigationThrottle::ThrottleCheckResult::PROCEED;
59 } 65 }
60 defer_time_ = base::TimeTicks::Now(); 66 defer_time_ = base::TimeTicks::Now();
61 return content::NavigationThrottle::ThrottleCheckResult::DEFER; 67 return content::NavigationThrottle::ThrottleCheckResult::DEFER;
62 } 68 }
63 69
64 const char* 70 const char*
(...skipping 10 matching lines...) Expand all
75 auto& stored_result = check_results_.at(request_id); 81 auto& stored_result = check_results_.at(request_id);
76 DCHECK(!stored_result.finished); 82 DCHECK(!stored_result.finished);
77 stored_result = result; 83 stored_result = result;
78 if (!defer_time_.is_null() && request_id == check_results_.size() - 1) { 84 if (!defer_time_.is_null() && request_id == check_results_.size() - 1) {
79 NotifyResult(); 85 NotifyResult();
80 navigation_handle()->Resume(); 86 navigation_handle()->Resume();
81 } 87 }
82 } 88 }
83 89
84 void SubresourceFilterSafeBrowsingActivationThrottle::CheckCurrentUrl() { 90 void SubresourceFilterSafeBrowsingActivationThrottle::CheckCurrentUrl() {
91 if (!database_client_)
92 return;
85 check_results_.emplace_back(); 93 check_results_.emplace_back();
86 size_t id = check_results_.size() - 1; 94 size_t id = check_results_.size() - 1;
87 io_task_runner_->PostTask( 95 io_task_runner_->PostTask(
88 FROM_HERE, base::Bind(&SubresourceFilterSafeBrowsingClient::CheckUrlOnIO, 96 FROM_HERE, base::Bind(&SubresourceFilterSafeBrowsingClient::CheckUrlOnIO,
89 base::Unretained(database_client_.get()), 97 base::Unretained(database_client_.get()),
90 navigation_handle()->GetURL(), id)); 98 navigation_handle()->GetURL(), id));
91 } 99 }
92 100
93 void SubresourceFilterSafeBrowsingActivationThrottle::NotifyResult() { 101 void SubresourceFilterSafeBrowsingActivationThrottle::NotifyResult() {
94 content::WebContents* web_contents = navigation_handle()->GetWebContents(); 102 content::WebContents* web_contents = navigation_handle()->GetWebContents();
(...skipping 21 matching lines...) Expand all
116 // speculatively checks URLs on WillStartRequest. This is only different from 124 // speculatively checks URLs on WillStartRequest. This is only different from
117 // the actual delay if there was at least one redirect. 125 // the actual delay if there was at least one redirect.
118 base::TimeDelta no_redirect_speculation_delay = 126 base::TimeDelta no_redirect_speculation_delay =
119 check_results_.size() > 1 ? result.check_time : delay; 127 check_results_.size() > 1 ? result.check_time : delay;
120 UMA_HISTOGRAM_TIMES( 128 UMA_HISTOGRAM_TIMES(
121 "SubresourceFilter.PageLoad.SafeBrowsingDelay.NoRedirectSpeculation", 129 "SubresourceFilter.PageLoad.SafeBrowsingDelay.NoRedirectSpeculation",
122 no_redirect_speculation_delay); 130 no_redirect_speculation_delay);
123 } 131 }
124 132
125 } // namespace subresource_filter 133 } // namespace subresource_filter
OLDNEW
« no previous file with comments | « chrome/browser/subresource_filter/navigation_throttle_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698