Index: components/subresource_filter/content/browser/subresource_filter_safe_browsing_client_request.h |
diff --git a/components/subresource_filter/content/browser/subresource_filter_safe_browsing_client_request.h b/components/subresource_filter/content/browser/subresource_filter_safe_browsing_client_request.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2920b749ce17918c5a9790ee8ca264e8fa8fc550 |
--- /dev/null |
+++ b/components/subresource_filter/content/browser/subresource_filter_safe_browsing_client_request.h |
@@ -0,0 +1,89 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BROWSING_CLIENT_REQUEST_H_ |
+#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BROWSING_CLIENT_REQUEST_H_ |
+ |
+#include <stddef.h> |
+ |
+#include "base/macros.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/time/time.h" |
+#include "base/timer/timer.h" |
+#include "components/safe_browsing_db/database_manager.h" |
+#include "components/safe_browsing_db/util.h" |
+#include "components/safe_browsing_db/v4_local_database_manager.h" |
+#include "url/gurl.h" |
+ |
+namespace base { |
+class SingleThreadTaskRunner; |
+} // namespace base |
+ |
+namespace safe_browsing { |
+struct ThreatMetadata; |
+} // namespace safe_browsing |
+ |
+namespace subresource_filter { |
+ |
+class SubresourceFilterSafeBrowsingClient; |
+ |
+// This class is scoped to a single database check, and it lives on the IO |
+// thread exclusively. |
+class SubresourceFilterSafeBrowsingClientRequest |
+ : public safe_browsing::SafeBrowsingDatabaseManager::Client { |
+ public: |
+ SubresourceFilterSafeBrowsingClientRequest( |
+ const GURL& url, |
+ size_t request_id, |
+ scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> |
+ database_manager, |
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
+ SubresourceFilterSafeBrowsingClient* client); |
+ ~SubresourceFilterSafeBrowsingClientRequest() override; |
+ |
+ void Start(); |
+ |
+ 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.
|
+ const GURL& url, |
+ safe_browsing::SBThreatType threat_type, |
+ const safe_browsing::ThreatMetadata& metadata) override; |
+ |
+ const GURL& url() const { return url_; } |
+ size_t request_id() const { return request_id_; } |
+ |
+ // Maximum time in milliseconds to wait for the Safe Browsing service to |
+ // verify a URL. After this amount of time the outstanding check will be |
+ // aborted, and the URL will be treated as if it didn't belong to the |
+ // Subresource Filter only list. |
+ static constexpr base::TimeDelta kCheckURLTimeout = |
+ base::TimeDelta::FromSeconds(5); |
+ |
+ private: |
+ // Callback for when the safe browsing check has taken longer than |
+ // kCheckURLTimeout. |
+ void OnCheckUrlTimeout(); |
+ |
+ void SendCheckResultToClient(bool served_from_network, |
+ safe_browsing::SBThreatType threat_type, |
+ const safe_browsing::ThreatMetadata& metadata); |
+ |
+ const GURL url_; |
+ 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.
|
+ |
+ scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; |
+ SubresourceFilterSafeBrowsingClient* client_ = nullptr; |
+ |
+ // Timer to abort the safe browsing check if it takes too long. |
+ base::OneShotTimer timer_; |
+ |
+ base::TimeTicks start_time_; |
+ |
+ bool request_completed_ = false; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingClientRequest); |
+}; |
+ |
+} // namespace subresource_filter |
+ |
+#endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BROWSING_CLIENT_REQUEST_H_ |