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

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: reviews, etc 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 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 <map>
9 #include <memory>
10
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "base/timer/timer.h"
16 #include "components/safe_browsing_db/v4_local_database_manager.h"
17 #include "url/gurl.h"
18
19 namespace base {
20 class SingleThreadTaskRunner;
21 } // namespace base
22
23 namespace subresource_filter {
24
25 class SubresourceFilterSafeBrowsingActivationThrottle;
26 class SubresourceFilterSafeBrowsingClientRequest;
27
28 // Created on the UI thread but used on the IO thread to communicate with the
29 // safe browsing service.
30 //
31 // The class is expected to accompany a single navigation. If a check request
32 // comes in for URL B while URL A is in flight, we cancel the check to URL A.
engedy 2017/04/25 22:03:54 comment nit: Update this line.
Charlie Harrison 2017/04/26 14:30:25 Done.
33 class SubresourceFilterSafeBrowsingClient {
34 public:
35 SubresourceFilterSafeBrowsingClient(
36 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
37 database_manager,
38 const base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle>&
engedy 2017/04/25 22:03:54 nit: I believe the latest style is to not pass sma
Charlie Harrison 2017/04/26 14:30:25 Done.
39 throttle,
40 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
41 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
42
43 ~SubresourceFilterSafeBrowsingClient();
44
45 void CheckUrlOnIO(const GURL& url, size_t request_id);
engedy 2017/04/25 22:03:54 #include <stddef.h> for size_t (in all places)
Charlie Harrison 2017/04/26 14:30:25 Done.
46
47 void OnCheckBrowseUrlResult(
48 SubresourceFilterSafeBrowsingClientRequest* request,
49 safe_browsing::SBThreatType threat_type,
50 const safe_browsing::ThreatMetadata& metadata);
51
52 private:
53 // This is stored as a map to allow for ergonomic deletion.
54 std::map<SubresourceFilterSafeBrowsingClientRequest*,
55 std::unique_ptr<SubresourceFilterSafeBrowsingClientRequest>>
56 requests_;
57
58 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_;
59
60 base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle> throttle_;
61 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
62 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
63
64 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingClient);
65 };
66
67 // This class is scoped to a single database check, and it lives on the IO
68 // thread exclusively.
69 class SubresourceFilterSafeBrowsingClientRequest
engedy 2017/04/25 22:03:54 Can this be moved to the .cc file?
Charlie Harrison 2017/04/26 14:30:25 Do you mind if I move it to a separate file (that'
engedy 2017/04/26 14:56:39 Fine by me!
70 : public safe_browsing::SafeBrowsingDatabaseManager::Client {
71 public:
72 SubresourceFilterSafeBrowsingClientRequest(
73 const GURL& url,
74 size_t request_id,
75 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
76 database_manager,
77 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
78 SubresourceFilterSafeBrowsingClient* client);
79 ~SubresourceFilterSafeBrowsingClientRequest() override;
80
81 void Start();
82
83 void OnCheckBrowseUrlResult(
84 const GURL& url,
85 safe_browsing::SBThreatType threat_type,
86 const safe_browsing::ThreatMetadata& metadata) override;
87
88 const GURL& url() const { return url_; }
89 size_t request_id() const { return request_id_; }
90
91 // Maximum time in milliseconds to wait for the Safe Browsing service to
92 // verify a URL. After this amount of time the outstanding check will be
93 // aborted, and the URL will be treated as if it didn't belong to the
94 // Subresource Filter only list.
95 static constexpr base::TimeDelta kCheckURLTimeout =
96 base::TimeDelta::FromSeconds(5);
97
98 private:
99 // Callback for when the safe browsing check has taken longer than
100 // kCheckURLTimeout.
101 void OnCheckUrlTimeout();
102
103 const GURL url_;
104 const size_t request_id_;
105
106 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_;
107 SubresourceFilterSafeBrowsingClient* client_ = nullptr;
108
109 // Timer to abort the safe browsing check if it takes too long.
110 base::OneShotTimer timer_;
111
112 base::TimeTicks start_time_;
113
114 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingClientRequest);
115 };
116
117 } // namespace subresource_filter
118
119 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE _BROWSING_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698