Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_client.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/single_thread_task_runner.h" | |
| 12 #include "base/timer/timer.h" | |
| 13 #include "components/safe_browsing_db/util.h" | |
| 14 #include "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_activation_throttle.h" | |
| 15 #include "content/public/browser/browser_thread.h" | |
| 16 | |
| 17 namespace subresource_filter { | |
| 18 | |
| 19 constexpr base::TimeDelta | |
| 20 SubresourceFilterSafeBrowsingClientRequest::kCheckURLTimeout; | |
| 21 | |
| 22 SubresourceFilterSafeBrowsingClient::SubresourceFilterSafeBrowsingClient( | |
| 23 std::unique_ptr<base::Timer> timer, | |
| 24 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager, | |
| 25 const base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle>& | |
| 26 throttle, | |
| 27 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | |
| 28 : timer_(std::move(timer)), | |
| 29 database_manager_(std::move(database_manager)), | |
| 30 throttle_(throttle), | |
| 31 ui_task_runner_(io_task_runner) {} | |
| 32 | |
| 33 SubresourceFilterSafeBrowsingClient::~SubresourceFilterSafeBrowsingClient() {} | |
| 34 | |
| 35 void SubresourceFilterSafeBrowsingClient::CheckUrlOnIO(const GURL& url, | |
| 36 int request_id) { | |
| 37 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 38 DCHECK(!url.is_empty()); | |
| 39 | |
| 40 // Will cancel the previous request, and it should never complete. This | |
| 41 // ensures that requests are notified in order. | |
| 42 current_request_ = | |
|
engedy
2017/04/20 18:56:23
Have you checked with the Safe Browsing folks if t
engedy
2017/04/20 18:58:17
... redirect chain patterns *histogram* ...
| |
| 43 base::MakeUnique<SubresourceFilterSafeBrowsingClientRequest>( | |
| 44 timer_.get(), url, request_id, database_manager_, this); | |
| 45 current_request_->Start(); | |
| 46 } | |
| 47 | |
| 48 void SubresourceFilterSafeBrowsingClient::OnCheckBrowseUrlResult( | |
| 49 SubresourceFilterSafeBrowsingClientRequest* request, | |
| 50 safe_browsing::SBThreatType threat_type, | |
| 51 const safe_browsing::ThreatMetadata& metadata) { | |
| 52 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 53 DCHECK_EQ(request->request_id(), current_request_->request_id()); | |
| 54 ui_task_runner_->PostTask( | |
| 55 FROM_HERE, base::Bind(&SubresourceFilterSafeBrowsingActivationThrottle:: | |
| 56 OnCheckUrlResultOnUI, | |
| 57 throttle_, request->url(), request->request_id(), | |
| 58 threat_type, metadata.threat_pattern_type)); | |
| 59 | |
| 60 current_request_.reset(); | |
| 61 } | |
| 62 | |
| 63 SubresourceFilterSafeBrowsingClientRequest:: | |
| 64 SubresourceFilterSafeBrowsingClientRequest( | |
| 65 base::Timer* timer, | |
| 66 const GURL& url, | |
| 67 int request_id, | |
| 68 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> | |
| 69 database_manager, | |
| 70 SubresourceFilterSafeBrowsingClient* client) | |
| 71 : url_(url), | |
| 72 request_id_(request_id), | |
| 73 database_manager_(std::move(database_manager)), | |
| 74 client_(client), | |
| 75 timer_(timer) { | |
| 76 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 77 } | |
| 78 | |
| 79 SubresourceFilterSafeBrowsingClientRequest:: | |
| 80 ~SubresourceFilterSafeBrowsingClientRequest() { | |
| 81 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 82 database_manager_->CancelCheck(this); | |
| 83 timer_->Stop(); | |
| 84 } | |
| 85 | |
| 86 void SubresourceFilterSafeBrowsingClientRequest::Start() { | |
| 87 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 88 if (database_manager_->CheckUrlForSubresourceFilter(url_, this)) { | |
| 89 OnCheckBrowseUrlResult(url_, safe_browsing::SB_THREAT_TYPE_SAFE, | |
| 90 safe_browsing::ThreatMetadata()); | |
| 91 return; | |
| 92 } | |
| 93 timer_->Start( | |
| 94 FROM_HERE, kCheckURLTimeout, | |
| 95 base::Bind(&SubresourceFilterSafeBrowsingClientRequest::OnCheckUrlTimeout, | |
| 96 base::Unretained(this))); | |
| 97 } | |
| 98 | |
| 99 void SubresourceFilterSafeBrowsingClientRequest::OnCheckBrowseUrlResult( | |
| 100 const GURL& url, | |
| 101 safe_browsing::SBThreatType threat_type, | |
| 102 const safe_browsing::ThreatMetadata& metadata) { | |
| 103 DCHECK_EQ(url_, url); | |
| 104 DCHECK(!timer_->IsRunning()); | |
| 105 client_->OnCheckBrowseUrlResult(this, threat_type, metadata); | |
| 106 } | |
| 107 | |
| 108 void SubresourceFilterSafeBrowsingClientRequest::OnCheckUrlTimeout() { | |
| 109 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 110 database_manager_->CancelCheck(this); | |
| 111 OnCheckBrowseUrlResult(url_, safe_browsing::SB_THREAT_TYPE_SAFE, | |
| 112 safe_browsing::ThreatMetadata()); | |
| 113 } | |
| 114 | |
| 115 } // namespace subresource_filter | |
| OLD | NEW |