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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_browser_throttle.cc

Issue 2924723002: Network service: SafeBrowsing check for frame-resources from browser. (Closed)
Patch Set: . Created 3 years, 6 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
(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() = default;
24
25 void SafeBrowsingBrowserThrottle::WillStartRequest(
26 const GURL& url,
27 int load_flags,
28 content::ResourceType resource_type,
29 bool* defer) {
30 DCHECK_EQ(0u, pending_checks_);
31 DCHECK(!blocked_);
32 DCHECK(!url_checker_);
33
34 pending_checks_++;
35 url_checker_ = base::MakeUnique<SafeBrowsingUrlCheckerImpl>(
36 load_flags, resource_type, std::move(database_manager_),
37 std::move(ui_manager_), web_contents_getter_);
38 url_checker_->CheckUrl(
39 url, base::Bind(&SafeBrowsingBrowserThrottle::OnCheckUrlResult,
40 base::Unretained(this)));
41 }
42
43 void SafeBrowsingBrowserThrottle::WillRedirectRequest(
44 const net::RedirectInfo& redirect_info,
45 bool* defer) {
46 // If |blocked_| is true, the resource load has been canceled and there
47 // shouldn't be such a notification.
48 DCHECK(!blocked_);
49
50 pending_checks_++;
51 url_checker_->CheckUrl(
52 redirect_info.new_url,
53 base::BindOnce(&SafeBrowsingBrowserThrottle::OnCheckUrlResult,
54 base::Unretained(this)));
55 }
56
57 void SafeBrowsingBrowserThrottle::WillProcessResponse(bool* defer) {
58 // If |blocked_| is true, the resource load has been canceled and there
59 // shouldn't be such a notification.
60 DCHECK(!blocked_);
61
62 if (pending_checks_ > 0)
63 *defer = true;
64 }
65
66 void SafeBrowsingBrowserThrottle::OnCheckUrlResult(bool safe) {
67 if (blocked_)
68 return;
69
70 DCHECK_LT(0u, pending_checks_);
71 pending_checks_--;
72
73 if (safe) {
74 if (pending_checks_ == 0) {
75 // The resource load is not necessarily deferred, in that case Resume() is
76 // a no-op.
77 delegate_->Resume();
78 }
79 } else {
80 url_checker_.reset();
81 blocked_ = true;
82 pending_checks_ = 0;
83 delegate_->CancelWithError(net::ERR_ABORTED);
84 }
85 }
86
87 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698