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 "chrome/browser/safe_browsing/safe_browsing_browser_throttle.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "chrome/browser/safe_browsing/safe_browsing_url_checker_impl.h" | |
| 9 #include "chrome/browser/safe_browsing/ui_manager.h" | |
| 10 #include "components/safe_browsing_db/database_manager.h" | |
| 11 #include "net/url_request/redirect_info.h" | |
| 12 | |
| 13 namespace safe_browsing { | |
| 14 | |
| 15 SafeBrowsingBrowserThrottle::SafeBrowsingBrowserThrottle( | |
| 16 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, | |
| 17 scoped_refptr<SafeBrowsingUIManager> ui_manager, | |
| 18 const base::Callback<content::WebContents*()>& web_contents_getter) | |
| 19 : database_manager_(database_manager), | |
| 20 ui_manager_(ui_manager), | |
| 21 web_contents_getter_(web_contents_getter) {} | |
| 22 | |
| 23 SafeBrowsingBrowserThrottle::~SafeBrowsingBrowserThrottle() { | |
| 24 during_destruction_ = true; | |
|
vakh (use Gerrit instead)
2017/06/15 21:52:58
What's the use of setting this flag in the ~?
Once
yzshen1
2017/06/16 21:27:09
Because destruction of the SafeBrowsingUrlCheckerI
| |
| 25 } | |
| 26 | |
| 27 void SafeBrowsingBrowserThrottle::WillStartRequest( | |
| 28 const GURL& url, | |
| 29 int load_flags, | |
| 30 content::ResourceType resource_type, | |
| 31 bool* defer) { | |
| 32 DCHECK_EQ(0u, pending_checks_); | |
| 33 DCHECK(!blocked_); | |
| 34 DCHECK(!url_checker_); | |
| 35 | |
| 36 pending_checks_++; | |
| 37 url_checker_ = base::MakeUnique<SafeBrowsingUrlCheckerImpl>( | |
| 38 load_flags, resource_type, std::move(database_manager_), | |
| 39 std::move(ui_manager_), web_contents_getter_); | |
| 40 url_checker_->CheckUrl( | |
| 41 url, base::Bind(&SafeBrowsingBrowserThrottle::OnCheckUrlResult, | |
| 42 base::Unretained(this))); | |
| 43 } | |
| 44 | |
| 45 void SafeBrowsingBrowserThrottle::WillRedirectRequest( | |
| 46 const net::RedirectInfo& redirect_info, | |
| 47 bool* defer) { | |
| 48 // If |blocked_| is true, the resource load has been canceled and there | |
| 49 // shouldn't be such a notification. | |
| 50 DCHECK(!blocked_); | |
| 51 | |
| 52 pending_checks_++; | |
| 53 url_checker_->CheckUrl( | |
| 54 redirect_info.new_url, | |
| 55 base::BindOnce(&SafeBrowsingBrowserThrottle::OnCheckUrlResult, | |
| 56 base::Unretained(this))); | |
| 57 } | |
| 58 | |
| 59 void SafeBrowsingBrowserThrottle::WillProcessResponse(bool* defer) { | |
| 60 // If |blocked_| is true, the resource load has been canceled and there | |
| 61 // shouldn't be such a notification. | |
| 62 DCHECK(!blocked_); | |
| 63 | |
| 64 if (pending_checks_ > 0) | |
| 65 *defer = true; | |
| 66 } | |
| 67 | |
| 68 void SafeBrowsingBrowserThrottle::OnCheckUrlResult(bool safe) { | |
| 69 if (blocked_ || during_destruction_) | |
| 70 return; | |
| 71 | |
| 72 DCHECK_LT(0u, pending_checks_); | |
| 73 pending_checks_--; | |
| 74 | |
| 75 if (safe) { | |
| 76 if (pending_checks_ == 0) { | |
| 77 // The resource load is not necessarily deferred, in that case Resume() is | |
| 78 // a no-op. | |
| 79 delegate_->Resume(); | |
| 80 } | |
| 81 } else { | |
| 82 url_checker_.reset(); | |
| 83 blocked_ = true; | |
| 84 pending_checks_ = 0; | |
| 85 delegate_->CancelWithError(net::ERR_ABORTED); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 } // namespace safe_browsing | |
| OLD | NEW |