Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / background_sync / background_sync_context_impl.h
blobc5a91039ec4d615aff756345fc8ce2bc70a48653
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_
8 #include <set>
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"
16 namespace content {
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 {
27 public:
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.
35 void Shutdown();
37 // Create a BackgroundSyncServiceImpl that is owned by this. Call on the UI
38 // thread.
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;
48 protected:
49 ~BackgroundSyncContextImpl() override;
51 private:
52 friend class BackgroundSyncServiceImplTest;
54 void CreateBackgroundSyncManager(
55 const scoped_refptr<ServiceWorkerContextWrapper>& context);
57 void CreateServiceOnIOThread(
58 mojo::InterfaceRequest<BackgroundSyncService> request);
60 void ShutdownOnIO();
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_