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 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BR OWSING_CLIENT_REQUEST_H_ | |
6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BR OWSING_CLIENT_REQUEST_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/time/time.h" | |
13 #include "base/timer/timer.h" | |
14 #include "components/safe_browsing_db/database_manager.h" | |
15 #include "components/safe_browsing_db/util.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 safe_browsing { | |
24 struct ThreatMetadata; | |
25 } // namespace safe_browsing | |
26 | |
27 namespace subresource_filter { | |
28 | |
29 class SubresourceFilterSafeBrowsingClient; | |
30 | |
31 // This class is scoped to a single database check, and it lives on the IO | |
32 // thread exclusively. | |
33 class SubresourceFilterSafeBrowsingClientRequest | |
34 : public safe_browsing::SafeBrowsingDatabaseManager::Client { | |
35 public: | |
36 SubresourceFilterSafeBrowsingClientRequest( | |
37 const GURL& url, | |
38 size_t request_id, | |
39 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> | |
40 database_manager, | |
41 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | |
42 SubresourceFilterSafeBrowsingClient* client); | |
43 ~SubresourceFilterSafeBrowsingClientRequest() override; | |
44 | |
45 void Start(); | |
46 | |
47 void OnCheckBrowseUrlResult( | |
Nathan Parker
2017/05/03 00:00:42
nit: Add comment that this implements the SBDB::Cl
Charlie Harrison
2017/05/03 01:20:30
Done.
| |
48 const GURL& url, | |
49 safe_browsing::SBThreatType threat_type, | |
50 const safe_browsing::ThreatMetadata& metadata) override; | |
51 | |
52 const GURL& url() const { return url_; } | |
53 size_t request_id() const { return request_id_; } | |
54 | |
55 // Maximum time in milliseconds to wait for the Safe Browsing service to | |
56 // verify a URL. After this amount of time the outstanding check will be | |
57 // aborted, and the URL will be treated as if it didn't belong to the | |
58 // Subresource Filter only list. | |
59 static constexpr base::TimeDelta kCheckURLTimeout = | |
60 base::TimeDelta::FromSeconds(5); | |
61 | |
62 private: | |
63 // Callback for when the safe browsing check has taken longer than | |
64 // kCheckURLTimeout. | |
65 void OnCheckUrlTimeout(); | |
66 | |
67 void SendCheckResultToClient(bool served_from_network, | |
68 safe_browsing::SBThreatType threat_type, | |
69 const safe_browsing::ThreatMetadata& metadata); | |
70 | |
71 const GURL url_; | |
72 const size_t request_id_; | |
Nathan Parker
2017/05/03 00:00:42
Maybe add a comment as to what request_id is? In w
Charlie Harrison
2017/05/03 01:20:30
Done.
| |
73 | |
74 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; | |
75 SubresourceFilterSafeBrowsingClient* client_ = nullptr; | |
76 | |
77 // Timer to abort the safe browsing check if it takes too long. | |
78 base::OneShotTimer timer_; | |
79 | |
80 base::TimeTicks start_time_; | |
81 | |
82 bool request_completed_ = false; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingClientRequest); | |
85 }; | |
86 | |
87 } // namespace subresource_filter | |
88 | |
89 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE _BROWSING_CLIENT_REQUEST_H_ | |
OLD | NEW |