background_sync_delegate.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2020 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. #ifndef COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_H_
  5. #define COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_H_
  6. #include <set>
  7. #include "base/callback.h"
  8. #include "base/time/time.h"
  9. #include "build/build_config.h"
  10. #include "content/public/browser/background_sync_controller.h"
  11. #include "services/metrics/public/cpp/ukm_source_id.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. #include "third_party/blink/public/mojom/background_sync/background_sync.mojom-forward.h"
  14. #include "url/origin.h"
  15. class HostContentSettingsMap;
  16. class GURL;
  17. namespace background_sync {
  18. // Allows the component embedder to override the behavior of Background Sync
  19. // component.
  20. class BackgroundSyncDelegate {
  21. public:
  22. virtual ~BackgroundSyncDelegate() = default;
  23. #if !BUILDFLAG(IS_ANDROID)
  24. // Keeps the browser and profile alive to allow a one-shot Background Sync
  25. // registration to finish firing one sync event.
  26. virtual std::unique_ptr<
  27. content::BackgroundSyncController::BackgroundSyncEventKeepAlive>
  28. CreateBackgroundSyncEventKeepAlive() = 0;
  29. #endif
  30. // Gets the source_ID to log the UKM event for, and calls |callback| with that
  31. // source_id, or with absl::nullopt if UKM recording is not allowed.
  32. virtual void GetUkmSourceId(
  33. const url::Origin& origin,
  34. base::OnceCallback<void(absl::optional<ukm::SourceId>)> callback) = 0;
  35. // Handles browser shutdown.
  36. virtual void Shutdown() = 0;
  37. // Returns the content settings map.
  38. virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0;
  39. // Returns true if the profile associated with the delegate is off-the-record.
  40. virtual bool IsProfileOffTheRecord() = 0;
  41. // Notes the origins for which Periodic Background Sync is suspended.
  42. virtual void NoteSuspendedPeriodicSyncOrigins(
  43. std::set<url::Origin> suspended_origins) = 0;
  44. // Gets the site engagement penalty to add to the Periodic Background Sync
  45. // interval for the origin corresponding to |url|.
  46. // The site engagement penalty is inversely proportional to the engagement
  47. // level. The lower the engagement levels with the site, the less often
  48. // periodic sync events will be fired.
  49. // Returns 0 if the engagement level is blink::mojom::EngagementLevel::NONE.
  50. virtual int GetSiteEngagementPenalty(const GURL& url) = 0;
  51. #if BUILDFLAG(IS_ANDROID)
  52. // Schedules the browser to be woken up when the device is online to process
  53. // registrations of type |sync| after a minimum delay |delay|.
  54. virtual void ScheduleBrowserWakeUpWithDelay(
  55. blink::mojom::BackgroundSyncType sync_type,
  56. base::TimeDelta delay) = 0;
  57. // Cancels browser wakeup for registrations of type |sync_type|.
  58. virtual void CancelBrowserWakeup(
  59. blink::mojom::BackgroundSyncType sync_type) = 0;
  60. // Whether Background Sync should be disabled.
  61. virtual bool ShouldDisableBackgroundSync() = 0;
  62. // Whether to disable Android network detection for connectivity checks.
  63. virtual bool ShouldDisableAndroidNetworkDetection() = 0;
  64. #endif
  65. };
  66. } // namespace background_sync
  67. #endif // COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_H_