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 // safe_browsing::SafeBrowsingDatabaseManager::Client: |
| 48 void OnCheckBrowseUrlResult( |
| 49 const GURL& url, |
| 50 safe_browsing::SBThreatType threat_type, |
| 51 const safe_browsing::ThreatMetadata& metadata) override; |
| 52 |
| 53 const GURL& url() const { return url_; } |
| 54 size_t request_id() const { return request_id_; } |
| 55 |
| 56 // Maximum time in milliseconds to wait for the Safe Browsing service to |
| 57 // verify a URL. After this amount of time the outstanding check will be |
| 58 // aborted, and the URL will be treated as if it didn't belong to the |
| 59 // Subresource Filter only list. |
| 60 static constexpr base::TimeDelta kCheckURLTimeout = |
| 61 base::TimeDelta::FromSeconds(5); |
| 62 |
| 63 private: |
| 64 // Callback for when the safe browsing check has taken longer than |
| 65 // kCheckURLTimeout. |
| 66 void OnCheckUrlTimeout(); |
| 67 |
| 68 void SendCheckResultToClient(bool served_from_network, |
| 69 safe_browsing::SBThreatType threat_type, |
| 70 const safe_browsing::ThreatMetadata& metadata); |
| 71 |
| 72 const GURL url_; |
| 73 |
| 74 // The |request_id_| identifies a particular request, as issued from the |
| 75 // SubresourceFilterSafeBrowsingClient. It will be unique in the scope of a |
| 76 // single navigation (i.e. the scope of the |
| 77 // SubresourceFilterSafeBrowsingClient). |
| 78 const size_t request_id_; |
| 79 |
| 80 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; |
| 81 SubresourceFilterSafeBrowsingClient* client_ = nullptr; |
| 82 |
| 83 // Timer to abort the safe browsing check if it takes too long. |
| 84 base::OneShotTimer timer_; |
| 85 |
| 86 base::TimeTicks start_time_; |
| 87 |
| 88 bool request_completed_ = false; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingClientRequest); |
| 91 }; |
| 92 |
| 93 } // namespace subresource_filter |
| 94 |
| 95 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE
_BROWSING_CLIENT_REQUEST_H_ |
OLD | NEW |