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: components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h

Issue 2834543003: [subresource_filter] SB throttle can send multiple speculative requests. (Closed)
Patch Set: add cancelling navigation throttle Created 3 years, 8 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 (c) 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 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BR OWSING_CLIENT_H_
6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BR OWSING_CLIENT_H_
7
8 #include <memory>
9
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "components/safe_browsing_db/v4_local_database_manager.h"
14 #include "url/gurl.h"
15
16 namespace base {
17 class SingleThreadTaskRunner;
18 class Timer;
19 } // namespace base
20
21 namespace subresource_filter {
22
23 class SubresourceFilterSafeBrowsingActivationThrottle;
24 class SubresourceFilterSafeBrowsingClientRequest;
25
26 // Created on the UI thread but used on the IO thread to communicate with the
27 // safe browsing service.
28 //
29 // The class is expected to accompany a single navigation. If a check request
30 // comes in for URL B while URL A is in flight, we cancel the check to URL A.
31 //
32 // Consumers of the class need some way of determining the order of requests, so
33 // they send in request_ids which are paired with each check.
34 class SubresourceFilterSafeBrowsingClient {
35 public:
36 SubresourceFilterSafeBrowsingClient(
37 std::unique_ptr<base::Timer> timer,
38 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
39 database_manager,
40 const base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle>&
41 throttle,
42 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
43
44 ~SubresourceFilterSafeBrowsingClient();
45
46 void CheckUrlOnIO(const GURL& url, int request_id);
47
48 void OnCheckBrowseUrlResult(
49 SubresourceFilterSafeBrowsingClientRequest* request,
50 safe_browsing::SBThreatType threat_type,
51 const safe_browsing::ThreatMetadata& metadata);
52
53 private:
54 // Only set from the default for testing.
55 std::unique_ptr<base::Timer> timer_;
56 std::unique_ptr<SubresourceFilterSafeBrowsingClientRequest> current_request_;
57
58 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_;
59
60 base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle> throttle_;
61 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
62
63 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingClient);
64 };
65
66 // This class is scoped to a single database check, and it lives on the IO
67 // thread exclusively.
68 class SubresourceFilterSafeBrowsingClientRequest
69 : public safe_browsing::SafeBrowsingDatabaseManager::Client {
70 public:
71 SubresourceFilterSafeBrowsingClientRequest(
72 base::Timer* timer,
73 const GURL& url,
74 int request_id,
75 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
76 database_manager,
77 SubresourceFilterSafeBrowsingClient* client);
78 ~SubresourceFilterSafeBrowsingClientRequest() override;
79
80 void Start();
81
82 void OnCheckBrowseUrlResult(
83 const GURL& url,
84 safe_browsing::SBThreatType threat_type,
85 const safe_browsing::ThreatMetadata& metadata) override;
86
87 const GURL& url() const { return url_; }
88
89 int request_id() const { return request_id_; }
90
91 static const base::TimeDelta kCheckURLTimeout;
92
93 private:
94 // Callback for when the safe browsing check has taken longer than
95 // kCheckURLTimeout.
96 void OnCheckUrlTimeout();
97
98 const GURL url_;
99 const int request_id_;
100
101 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_;
102 SubresourceFilterSafeBrowsingClient* client_ = nullptr;
103
104 // Timer to abort the safe browsing check if it takes too long. Must outlive
105 // this class.
106 base::Timer* timer_;
107
108 // Only used for DCHECKing.
109 bool is_cancelled_ = false;
110
111 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingClientRequest);
112 };
113
114 } // namespace subresource_filter
115
116 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE _BROWSING_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698