| 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..3505974d03b44721c1d9e81b0c87108e0246f5fd
|
| --- /dev/null
|
| +++ b/components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h
|
| @@ -0,0 +1,116 @@
|
| +// Copyright (c) 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 <memory>
|
| +
|
| +#include "base/macros.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "components/safe_browsing_db/v4_local_database_manager.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace base {
|
| +class SingleThreadTaskRunner;
|
| +class Timer;
|
| +} // 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. If a check request
|
| +// comes in for URL B while URL A is in flight, we cancel the check to URL A.
|
| +//
|
| +// Consumers of the class need some way of determining the order of requests, so
|
| +// they send in request_ids which are paired with each check.
|
| +class SubresourceFilterSafeBrowsingClient {
|
| + public:
|
| + SubresourceFilterSafeBrowsingClient(
|
| + std::unique_ptr<base::Timer> timer,
|
| + scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
|
| + database_manager,
|
| + const base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle>&
|
| + throttle,
|
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
|
| +
|
| + ~SubresourceFilterSafeBrowsingClient();
|
| +
|
| + void CheckUrlOnIO(const GURL& url, int request_id);
|
| +
|
| + void OnCheckBrowseUrlResult(
|
| + SubresourceFilterSafeBrowsingClientRequest* request,
|
| + safe_browsing::SBThreatType threat_type,
|
| + const safe_browsing::ThreatMetadata& metadata);
|
| +
|
| + private:
|
| + // Only set from the default for testing.
|
| + std::unique_ptr<base::Timer> timer_;
|
| + std::unique_ptr<SubresourceFilterSafeBrowsingClientRequest> current_request_;
|
| +
|
| + scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_;
|
| +
|
| + base::WeakPtr<SubresourceFilterSafeBrowsingActivationThrottle> throttle_;
|
| + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(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(
|
| + base::Timer* timer,
|
| + const GURL& url,
|
| + int request_id,
|
| + scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
|
| + database_manager,
|
| + SubresourceFilterSafeBrowsingClient* client);
|
| + ~SubresourceFilterSafeBrowsingClientRequest() override;
|
| +
|
| + void Start();
|
| +
|
| + void OnCheckBrowseUrlResult(
|
| + const GURL& url,
|
| + safe_browsing::SBThreatType threat_type,
|
| + const safe_browsing::ThreatMetadata& metadata) override;
|
| +
|
| + const GURL& url() const { return url_; }
|
| +
|
| + int request_id() const { return request_id_; }
|
| +
|
| + static const base::TimeDelta kCheckURLTimeout;
|
| +
|
| + private:
|
| + // Callback for when the safe browsing check has taken longer than
|
| + // kCheckURLTimeout.
|
| + void OnCheckUrlTimeout();
|
| +
|
| + const GURL url_;
|
| + const int request_id_;
|
| +
|
| + scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_;
|
| + SubresourceFilterSafeBrowsingClient* client_ = nullptr;
|
| +
|
| + // Timer to abort the safe browsing check if it takes too long. Must outlive
|
| + // this class.
|
| + base::Timer* timer_;
|
| +
|
| + // Only used for DCHECKing.
|
| + bool is_cancelled_ = false;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingClientRequest);
|
| +};
|
| +
|
| +} // namespace subresource_filter
|
| +
|
| +#endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BROWSING_CLIENT_H_
|
|
|