Chromium Code Reviews| Index: components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h |
| diff --git a/components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h b/components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e7c3dd282a97ab946b537b78ebf62710a69cb235 |
| --- /dev/null |
| +++ b/components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h |
| @@ -0,0 +1,81 @@ |
| +// 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_H_ |
| +#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BROWSING_CLIENT_H_ |
| + |
| +#include <stddef.h> |
| + |
| +#include <map> |
| +#include <memory> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/time/time.h" |
| +#include "components/safe_browsing_db/util.h" |
| +#include "components/safe_browsing_db/v4_local_database_manager.h" |
| + |
| +class GURL; |
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| +} // namespace base |
| + |
| +namespace subresource_filter { |
| + |
| +class SubresourceFilterSafeBrowsingActivationThrottle; |
| +class SubresourceFilterSafeBrowsingClientRequest; |
| + |
| +// Created on the UI thread but used on the IO thread to communicate with the |
| +// safe browsing service. |
| +// |
| +// The class is expected to accompany a single navigation, and can maintain many |
| +// database requests. It will cancel cancel any outgoing requests when it is |
| +// destroyed. |
| +class SubresourceFilterSafeBrowsingClient { |
| + public: |
| + struct CheckResult { |
| + size_t request_id = 0; |
| + safe_browsing::SBThreatType threat_type = |
| + safe_browsing::SBThreatType::SB_THREAT_TYPE_SAFE; |
| + safe_browsing::ThreatPatternType pattern_type = |
| + safe_browsing::ThreatPatternType::NONE; |
| + base::TimeDelta check_time; |
| + bool finished = false; |
| + }; |
| + |
| + SubresourceFilterSafeBrowsingClient( |
| + scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> |
| + database_manager, |
| + base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle> throttle, |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
|
Nathan Parker
2017/05/03 00:00:42
The args here are different than in the .cc file.
Charlie Harrison
2017/05/03 01:20:30
Renamed the task runner to throttle_task_runner. A
|
| + |
| + ~SubresourceFilterSafeBrowsingClient(); |
| + |
| + void CheckUrlOnIO(const GURL& url, size_t request_id); |
| + |
| + void OnCheckBrowseUrlResult( |
| + SubresourceFilterSafeBrowsingClientRequest* request, |
| + const CheckResult& check_result); |
| + |
| + private: |
| + // This is stored as a map to allow for ergonomic deletion. |
| + std::map<SubresourceFilterSafeBrowsingClientRequest*, |
|
Nathan Parker
2017/05/03 00:00:42
nit: flat_map would likely have better RAM/CPU per
Charlie Harrison
2017/05/03 01:20:30
Good call, done.
|
| + std::unique_ptr<SubresourceFilterSafeBrowsingClientRequest>> |
| + requests_; |
| + |
| + scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; |
| + |
| + base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle> throttle_; |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| + scoped_refptr<base::SingleThreadTaskRunner> throttle_task_runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingClient); |
| +}; |
| + |
| +} // namespace subresource_filter |
| + |
| +#endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BROWSING_CLIENT_H_ |