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_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_SERVICE_IMPL_H_
8 #include "base/id_map.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_vector.h"
11 #include "content/browser/background_sync/background_sync_manager.h"
12 #include "content/common/background_sync_service.mojom.h"
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
17 class BackgroundSyncContextImpl
;
19 class CONTENT_EXPORT BackgroundSyncServiceImpl
20 : public NON_EXPORTED_BASE(BackgroundSyncService
) {
22 BackgroundSyncServiceImpl(
23 BackgroundSyncContextImpl
* background_sync_context
,
24 mojo::InterfaceRequest
<BackgroundSyncService
> request
);
26 ~BackgroundSyncServiceImpl() override
;
29 friend class BackgroundSyncServiceImplTest
;
31 // BackgroundSyncService methods:
32 void Register(content::SyncRegistrationPtr options
,
33 int64_t sw_registration_id
,
34 bool requested_from_service_worker
,
35 const RegisterCallback
& callback
) override
;
36 void Unregister(BackgroundSyncPeriodicity periodicity
,
37 BackgroundSyncRegistrationHandle::HandleId handle_id
,
38 int64_t sw_registration_id
,
39 const UnregisterCallback
& callback
) override
;
40 void GetRegistration(BackgroundSyncPeriodicity periodicity
,
41 const mojo::String
& tag
,
42 int64_t sw_registration_id
,
43 const GetRegistrationCallback
& callback
) override
;
44 void GetRegistrations(BackgroundSyncPeriodicity periodicity
,
45 int64_t sw_registration_id
,
46 const GetRegistrationsCallback
& callback
) override
;
47 void GetPermissionStatus(
48 BackgroundSyncPeriodicity periodicity
,
49 int64_t sw_registration_id
,
50 const GetPermissionStatusCallback
& callback
) override
;
51 void DuplicateRegistrationHandle(
52 BackgroundSyncRegistrationHandle::HandleId handle_id
,
53 const DuplicateRegistrationHandleCallback
& callback
) override
;
54 void ReleaseRegistration(
55 BackgroundSyncRegistrationHandle::HandleId handle_id
) override
;
56 void NotifyWhenDone(BackgroundSyncRegistrationHandle::HandleId handle_id
,
57 const NotifyWhenDoneCallback
& callback
) override
;
59 void OnRegisterResult(const RegisterCallback
& callback
,
60 BackgroundSyncStatus status
,
61 scoped_ptr
<BackgroundSyncRegistrationHandle
> result
);
62 void OnUnregisterResult(const UnregisterCallback
& callback
,
63 BackgroundSyncStatus status
);
64 void OnGetRegistrationsResult(
65 const GetRegistrationsCallback
& callback
,
66 BackgroundSyncStatus status
,
67 scoped_ptr
<ScopedVector
<BackgroundSyncRegistrationHandle
>> result
);
68 void OnNotifyWhenDoneResult(const NotifyWhenDoneCallback
& callback
,
69 BackgroundSyncStatus status
,
70 BackgroundSyncState sync_state
);
72 // Called when an error is detected on binding_.
73 void OnConnectionError();
75 // background_sync_context_ owns this.
76 BackgroundSyncContextImpl
* background_sync_context_
;
78 mojo::Binding
<BackgroundSyncService
> binding_
;
80 // The registrations that the client might reference.
81 IDMap
<BackgroundSyncRegistrationHandle
, IDMapOwnPointer
> active_handles_
;
83 base::WeakPtrFactory
<BackgroundSyncServiceImpl
> weak_ptr_factory_
;
85 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncServiceImpl
);
88 } // namespace content
90 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_SERVICE_IMPL_H_