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/location.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 14 #include "components/subresource_filter/content/browser/subresource_filter_safe_
browsing_activation_throttle.h" |
| 15 #include "components/subresource_filter/content/browser/subresource_filter_safe_
browsing_client_request.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 17 |
| 18 namespace subresource_filter { |
| 19 |
| 20 SubresourceFilterSafeBrowsingClient::SubresourceFilterSafeBrowsingClient( |
| 21 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager, |
| 22 base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle> throttle, |
| 23 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 24 scoped_refptr<base::SingleThreadTaskRunner> throttle_task_runner) |
| 25 : database_manager_(std::move(database_manager)), |
| 26 throttle_(std::move(throttle)), |
| 27 io_task_runner_(std::move(io_task_runner)), |
| 28 throttle_task_runner_(std::move(throttle_task_runner)) {} |
| 29 |
| 30 SubresourceFilterSafeBrowsingClient::~SubresourceFilterSafeBrowsingClient() {} |
| 31 |
| 32 void SubresourceFilterSafeBrowsingClient::CheckUrlOnIO(const GURL& url, |
| 33 size_t request_id) { |
| 34 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 35 DCHECK(!url.is_empty()); |
| 36 |
| 37 auto request = base::MakeUnique<SubresourceFilterSafeBrowsingClientRequest>( |
| 38 url, request_id, database_manager_, io_task_runner_, this); |
| 39 auto* raw_request = request.get(); |
| 40 DCHECK(requests_.find(raw_request) == requests_.end()); |
| 41 requests_[raw_request] = std::move(request); |
| 42 raw_request->Start(); |
| 43 // Careful, |raw_request| can be destroyed after this line. |
| 44 } |
| 45 |
| 46 void SubresourceFilterSafeBrowsingClient::OnCheckBrowseUrlResult( |
| 47 SubresourceFilterSafeBrowsingClientRequest* request, |
| 48 const CheckResult& check_result) { |
| 49 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 50 throttle_task_runner_->PostTask( |
| 51 FROM_HERE, base::Bind(&SubresourceFilterSafeBrowsingActivationThrottle:: |
| 52 OnCheckUrlResultOnUI, |
| 53 throttle_, check_result)); |
| 54 |
| 55 DCHECK(requests_.find(request) != requests_.end()); |
| 56 requests_.erase(request); |
| 57 } |
| 58 |
| 59 } // namespace subresource_filter |
OLD | NEW |