remote_database_manager.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2015 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. // Implementation of the SafeBrowsingDatabaseManager that sends URLs
  6. // via IPC to a database that chromium doesn't manage locally.
  7. #ifndef COMPONENTS_SAFE_BROWSING_ANDROID_REMOTE_DATABASE_MANAGER_H_
  8. #define COMPONENTS_SAFE_BROWSING_ANDROID_REMOTE_DATABASE_MANAGER_H_
  9. #include <set>
  10. #include <string>
  11. #include <vector>
  12. #include "base/containers/flat_set.h"
  13. #include "base/memory/ref_counted.h"
  14. #include "base/memory/weak_ptr.h"
  15. #include "components/safe_browsing/core/browser/db/database_manager.h"
  16. #include "services/network/public/mojom/fetch_api.mojom.h"
  17. #include "url/gurl.h"
  18. namespace safe_browsing {
  19. struct V4ProtocolConfig;
  20. // An implementation that proxies requests to a service outside of Chromium.
  21. // Does not manage a local database.
  22. class RemoteSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager {
  23. public:
  24. // Construct RemoteSafeBrowsingDatabaseManager.
  25. // Must be initialized by calling StartOnIOThread() before using.
  26. RemoteSafeBrowsingDatabaseManager();
  27. RemoteSafeBrowsingDatabaseManager(const RemoteSafeBrowsingDatabaseManager&) =
  28. delete;
  29. RemoteSafeBrowsingDatabaseManager& operator=(
  30. const RemoteSafeBrowsingDatabaseManager&) = delete;
  31. //
  32. // SafeBrowsingDatabaseManager implementation
  33. //
  34. void CancelCheck(Client* client) override;
  35. bool CanCheckRequestDestination(
  36. network::mojom::RequestDestination request_destination) const override;
  37. bool CanCheckUrl(const GURL& url) const override;
  38. bool ChecksAreAlwaysAsync() const override;
  39. bool CheckBrowseUrl(const GURL& url,
  40. const SBThreatTypeSet& threat_types,
  41. Client* client) override;
  42. bool CheckDownloadUrl(const std::vector<GURL>& url_chain,
  43. Client* client) override;
  44. bool CheckExtensionIDs(const std::set<std::string>& extension_ids,
  45. Client* client) override;
  46. AsyncMatch CheckCsdAllowlistUrl(const GURL& url, Client* client) override;
  47. bool CheckResourceUrl(const GURL& url, Client* client) override;
  48. AsyncMatch CheckUrlForHighConfidenceAllowlist(const GURL& url,
  49. Client* client) override;
  50. bool CheckUrlForAccuracyTips(const GURL& url, Client* client) override;
  51. bool CheckUrlForSubresourceFilter(const GURL& url, Client* client) override;
  52. bool MatchDownloadAllowlistUrl(const GURL& url) override;
  53. bool MatchMalwareIP(const std::string& ip_address) override;
  54. safe_browsing::ThreatSource GetThreatSource() const override;
  55. bool IsDownloadProtectionEnabled() const override;
  56. void StartOnIOThread(
  57. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
  58. const V4ProtocolConfig& config) override;
  59. void StopOnIOThread(bool shutdown) override;
  60. //
  61. // RemoteSafeBrowsingDatabaseManager implementation
  62. //
  63. private:
  64. ~RemoteSafeBrowsingDatabaseManager() override;
  65. class ClientRequest; // Per-request tracker.
  66. // Requests currently outstanding. This owns the ptrs.
  67. std::vector<ClientRequest*> current_requests_;
  68. base::flat_set<network::mojom::RequestDestination>
  69. request_destinations_to_check_;
  70. friend class base::RefCountedThreadSafe<RemoteSafeBrowsingDatabaseManager>;
  71. }; // class RemoteSafeBrowsingDatabaseManager
  72. } // namespace safe_browsing
  73. #endif // COMPONENTS_SAFE_BROWSING_ANDROID_REMOTE_DATABASE_MANAGER_H_