1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66

content / public / browser / background_sync_context.h [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_PUBLIC_BROWSER_BACKGROUND_SYNC_CONTEXT_H_
#define CONTENT_PUBLIC_BROWSER_BACKGROUND_SYNC_CONTEXT_H_

#include "base/functional/callback_forward.h"
#include "build/build_config.h"
#include "content/common/content_export.h"
#include "third_party/blink/public/mojom/background_sync/background_sync.mojom.h"
#include "url/origin.h"

#if BUILDFLAG(IS_ANDROID)
#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#endif

namespace content {

class BrowserContext;
class StoragePartition;

// One instance of this exists per StoragePartition, and services multiple child
// processes/origins. It contains the context for processing Background Sync
// registrations, and delegates most of this processing to owned instances of
// other components.
class CONTENT_EXPORT BackgroundSyncContext {
 public:
#if BUILDFLAG(IS_ANDROID)
  // Processes pending Background Sync registrations of |sync_type| for all the
  // storage partitions in |browser_context|, and then runs  the |j_runnable|
  // when done.
  static void FireBackgroundSyncEventsAcrossPartitions(
      BrowserContext* browser_context,
      blink::mojom::BackgroundSyncType sync_type,
      const base::android::JavaParamRef<jobject>& j_runnable);
#endif

  BackgroundSyncContext() = default;

  BackgroundSyncContext(const BackgroundSyncContext&) = delete;
  BackgroundSyncContext& operator=(const BackgroundSyncContext&) = delete;

  // Process any pending Background Sync registrations.
  // This involves firing any sync events ready to be fired, and optionally
  // scheduling a job to wake up the browser when the next event needs to be
  // fired.
  virtual void FireBackgroundSyncEvents(
      blink::mojom::BackgroundSyncType sync_type,
      base::OnceClosure done_closure) = 0;

  // Revives any suspended periodic Background Sync registrations for |origin|.
  virtual void RevivePeriodicBackgroundSyncRegistrations(
      url::Origin origin) = 0;

  // Unregisters any periodic Background Sync registrations for |origin|.
  virtual void UnregisterPeriodicSyncForOrigin(url::Origin origin) = 0;

 protected:
  virtual ~BackgroundSyncContext() = default;
};

}  // namespace content

#endif  // CONTENT_PUBLIC_BROWSER_BACKGROUND_SYNC_CONTEXT_H_