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_CONTEXT_IMPL_H_
6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTEXT_IMPL_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/background_sync_service.mojom.h"
13 #include "content/common/content_export.h"
14 #include "content/public/browser/background_sync_context.h"
18 class BackgroundSyncManager
;
19 class BackgroundSyncServiceImpl
;
20 class ServiceWorkerContextWrapper
;
22 // Implements the BackgroundSyncContext. One instance of this exists per
23 // StoragePartition, and services multiple child processes/origins. Most logic
24 // is delegated to the owned BackgroundSyncManager instance, which is only
25 // accessed on the IO thread.
26 class CONTENT_EXPORT BackgroundSyncContextImpl
: public BackgroundSyncContext
{
28 BackgroundSyncContextImpl();
30 // Init and Shutdown are for use on the UI thread when the
31 // StoragePartition is being setup and torn down.
32 void Init(const scoped_refptr
<ServiceWorkerContextWrapper
>& context
);
34 // Shutdown must be called before deleting this. Call on the UI thread.
37 // Create a BackgroundSyncServiceImpl that is owned by this. Call on the UI
39 void CreateService(mojo::InterfaceRequest
<BackgroundSyncService
> request
);
41 // Called by BackgroundSyncServiceImpl objects so that they can
42 // be deleted. Call on the IO thread.
43 void ServiceHadConnectionError(BackgroundSyncServiceImpl
* service
);
45 // Call on the IO thread.
46 BackgroundSyncManager
* background_sync_manager() const override
;
49 ~BackgroundSyncContextImpl() override
;
52 friend class BackgroundSyncServiceImplTest
;
54 void CreateBackgroundSyncManager(
55 const scoped_refptr
<ServiceWorkerContextWrapper
>& context
);
57 void CreateServiceOnIOThread(
58 mojo::InterfaceRequest
<BackgroundSyncService
> request
);
62 // Only accessed on the IO thread.
63 scoped_ptr
<BackgroundSyncManager
> background_sync_manager_
;
65 // The services are owned by this. They're either deleted
66 // during ShutdownOnIO or when the channel is closed via
67 // ServiceHadConnectionError. Only accessed on the IO thread.
68 std::set
<BackgroundSyncServiceImpl
*> services_
;
70 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncContextImpl
);
73 } // namespace content
75 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTEXT_IMPL_H_