Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / content / child / background_sync / background_sync_provider.h
blob0dc6d6c3a56d2acdad12b756f4369698ad532373
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.
5 #ifndef CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_
6 #define CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "content/child/worker_task_runner.h"
12 #include "content/common/background_sync_service.mojom.h"
13 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProvider.h"
15 namespace content {
17 class ServiceRegistry;
19 // The BackgroundSyncProvider is called by the SyncManager and SyncRegistration
20 // objects (and their Periodic counterparts) and communicates with the
21 // BackgroundSyncManager object in the browser process. This class is
22 // instantiated on the main thread by BlinkPlatformImpl, and its methods can be
23 // called directly from the main thread.
24 class BackgroundSyncProvider : public blink::WebSyncProvider {
25 public:
26 explicit BackgroundSyncProvider(ServiceRegistry* service_registry);
28 ~BackgroundSyncProvider() override;
30 // blink::WebSyncProvider implementation
31 // TODO(jkarlin) convert int64_t handle_id to int handle_id in all
32 // WebSyncProvider functions.
33 void registerBackgroundSync(
34 const blink::WebSyncRegistration* options,
35 blink::WebServiceWorkerRegistration* service_worker_registration,
36 bool requested_from_service_worker,
37 blink::WebSyncRegistrationCallbacks* callbacks) override;
38 // TODO(jkarlin) remove |tag| parameter.
39 void unregisterBackgroundSync(
40 blink::WebSyncRegistration::Periodicity periodicity,
41 int64_t handle_id,
42 const blink::WebString& tag,
43 blink::WebServiceWorkerRegistration* service_worker_registration,
44 blink::WebSyncUnregistrationCallbacks* callbacks) override;
45 void getRegistration(
46 blink::WebSyncRegistration::Periodicity,
47 const blink::WebString& tag,
48 blink::WebServiceWorkerRegistration* service_worker_registration,
49 blink::WebSyncRegistrationCallbacks* callbacks) override;
50 void getRegistrations(
51 blink::WebSyncRegistration::Periodicity periodicity,
52 blink::WebServiceWorkerRegistration* service_worker_registration,
53 blink::WebSyncGetRegistrationsCallbacks* callbacks) override;
54 void getPermissionStatus(
55 blink::WebSyncRegistration::Periodicity periodicity,
56 blink::WebServiceWorkerRegistration* service_worker_registration,
57 blink::WebSyncGetPermissionStatusCallbacks* callbacks) override;
58 // TODO(jkarlin): Rename to releaseRegistrationHandle.
59 void releaseRegistration(int64_t handle_id) override;
60 void notifyWhenDone(
61 int64_t handle_id,
62 blink::WebSyncNotifyWhenDoneCallbacks* callbacks) override;
64 void DuplicateRegistrationHandle(
65 int handle_id,
66 const BackgroundSyncService::DuplicateRegistrationHandleCallback&
67 callback);
69 private:
70 // Callback handlers
71 void RegisterCallback(
72 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
73 BackgroundSyncError error,
74 const SyncRegistrationPtr& options);
75 void UnregisterCallback(
76 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks,
77 BackgroundSyncError error);
78 void GetRegistrationCallback(
79 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
80 BackgroundSyncError error,
81 const SyncRegistrationPtr& options);
82 void GetRegistrationsCallback(
83 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks,
84 BackgroundSyncError error,
85 const mojo::Array<SyncRegistrationPtr>& registrations);
86 void GetPermissionStatusCallback(
87 scoped_ptr<blink::WebSyncGetPermissionStatusCallbacks> callbacks,
88 BackgroundSyncError error,
89 PermissionStatus status);
90 void NotifyWhenDoneCallback(
91 scoped_ptr<blink::WebSyncNotifyWhenDoneCallbacks> callbacks,
92 BackgroundSyncError error,
93 BackgroundSyncState state);
95 // Helper method that returns an initialized BackgroundSyncServicePtr.
96 BackgroundSyncServicePtr& GetBackgroundSyncServicePtr();
98 ServiceRegistry* service_registry_;
99 BackgroundSyncServicePtr background_sync_service_;
101 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProvider);
104 } // namespace content
106 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_