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

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: 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
OLDNEW
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <vector> 7 #include <vector>
8 8
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "components/safe_browsing_db/v4_local_database_manager.h" 10 #include "components/safe_browsing_db/v4_local_database_manager.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 }; 95 };
96 96
97 SubresourceFilterSafeBrowsingActivationThrottle:: 97 SubresourceFilterSafeBrowsingActivationThrottle::
98 SubresourceFilterSafeBrowsingActivationThrottle( 98 SubresourceFilterSafeBrowsingActivationThrottle(
99 content::NavigationHandle* handle, 99 content::NavigationHandle* handle,
100 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> 100 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
101 database_manager) 101 database_manager)
102 : NavigationThrottle(handle), 102 : NavigationThrottle(handle),
103 io_task_runner_(content::BrowserThread::GetTaskRunnerForThread( 103 io_task_runner_(content::BrowserThread::GetTaskRunnerForThread(
104 content::BrowserThread::IO)), 104 content::BrowserThread::IO)),
105 database_client_( 105 database_client_(nullptr, base::OnTaskRunnerDeleter(io_task_runner_)) {
106 new SubresourceFilterSafeBrowsingActivationThrottle::SBDatabaseClient( 106 // The throttle can be created without a valid database manager. If so, it
107 std::move(database_manager), 107 // becomes a pass-through throttle and should never defer.
108 AsWeakPtr(), 108 if (database_manager) {
109 base::ThreadTaskRunnerHandle::Get()), 109 std::unique_ptr<SBDatabaseClient, base::OnTaskRunnerDeleter>
110 base::OnTaskRunnerDeleter(io_task_runner_)) {} 110 database_client(
111 new SubresourceFilterSafeBrowsingActivationThrottle::
112 SBDatabaseClient(std::move(database_manager), AsWeakPtr(),
113 base::ThreadTaskRunnerHandle::Get()),
114 base::OnTaskRunnerDeleter(io_task_runner_));
115 database_client_ = std::move(database_client);
engedy 2017/05/02 18:21:54 nit: Does .reset() work for unique_ptr's with cust
Charlie Harrison 2017/05/02 20:08:49 Nope, but you can use the move equality operator.
116 }
117 }
111 118
112 SubresourceFilterSafeBrowsingActivationThrottle:: 119 SubresourceFilterSafeBrowsingActivationThrottle::
113 ~SubresourceFilterSafeBrowsingActivationThrottle() {} 120 ~SubresourceFilterSafeBrowsingActivationThrottle() {}
114 121
115 content::NavigationThrottle::ThrottleCheckResult 122 content::NavigationThrottle::ThrottleCheckResult
116 SubresourceFilterSafeBrowsingActivationThrottle::WillProcessResponse() { 123 SubresourceFilterSafeBrowsingActivationThrottle::WillProcessResponse() {
124 if (!database_client_)
125 return content::NavigationThrottle::PROCEED;
117 io_task_runner_->PostTask( 126 io_task_runner_->PostTask(
118 FROM_HERE, base::Bind(&SubresourceFilterSafeBrowsingActivationThrottle:: 127 FROM_HERE, base::Bind(&SubresourceFilterSafeBrowsingActivationThrottle::
119 SBDatabaseClient::CheckUrlOnIO, 128 SBDatabaseClient::CheckUrlOnIO,
120 base::Unretained(database_client_.get()), 129 base::Unretained(database_client_.get()),
121 navigation_handle()->GetURL())); 130 navigation_handle()->GetURL()));
122 return content::NavigationThrottle::ThrottleCheckResult::DEFER; 131 return content::NavigationThrottle::ThrottleCheckResult::DEFER;
123 } 132 }
124 133
125 const char* 134 const char*
126 SubresourceFilterSafeBrowsingActivationThrottle::GetNameForLogging() { 135 SubresourceFilterSafeBrowsingActivationThrottle::GetNameForLogging() {
(...skipping 13 matching lines...) Expand all
140 149
141 driver_factory->OnMainResourceMatchedSafeBrowsingBlacklist( 150 driver_factory->OnMainResourceMatchedSafeBrowsingBlacklist(
142 url, std::vector<GURL>(), threat_type, pattern_type); 151 url, std::vector<GURL>(), threat_type, pattern_type);
143 } 152 }
144 // TODO(https://crbug.com/704508): We should measure the delay introduces by 153 // TODO(https://crbug.com/704508): We should measure the delay introduces by
145 // this check. Similarly, as it's done the Safe Browsing Resource throttle. 154 // this check. Similarly, as it's done the Safe Browsing Resource throttle.
146 navigation_handle()->Resume(); 155 navigation_handle()->Resume();
147 } 156 }
148 157
149 } // namespace subresource_filter 158 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698