OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTEXT_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTEXT_IMPL_H_ |
6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTEXT_IMPL_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTEXT_IMPL_H_ |
7 | 7 |
8 #include <set> | 8 #include "base/macros.h" |
9 | |
10 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/browser/background_sync/background_sync_service_impl.h" |
12 #include "content/common/background_sync_service.mojom.h" | 12 #include "content/common/background_sync_service.mojom.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "content/public/browser/background_sync_context.h" | 14 #include "content/public/browser/background_sync_context.h" |
| 15 #include "mojo/common/strong_binding_set.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 class BackgroundSyncManager; | 19 class BackgroundSyncManager; |
19 class BackgroundSyncServiceImpl; | |
20 class ServiceWorkerContextWrapper; | 20 class ServiceWorkerContextWrapper; |
21 | 21 |
22 // Implements the BackgroundSyncContext. One instance of this exists per | 22 // Implements the BackgroundSyncContext. One instance of this exists per |
23 // StoragePartition, and services multiple child processes/origins. Most logic | 23 // StoragePartition, and services multiple child processes/origins. Most logic |
24 // is delegated to the owned BackgroundSyncManager instance, which is only | 24 // is delegated to the owned BackgroundSyncManager instance, which is only |
25 // accessed on the IO thread. | 25 // accessed on the IO thread. |
26 class CONTENT_EXPORT BackgroundSyncContextImpl : public BackgroundSyncContext { | 26 class CONTENT_EXPORT BackgroundSyncContextImpl : public BackgroundSyncContext { |
27 public: | 27 public: |
28 BackgroundSyncContextImpl(); | 28 BackgroundSyncContextImpl(); |
29 | 29 |
30 // Init and Shutdown are for use on the UI thread when the | 30 // Init and Shutdown are for use on the UI thread when the |
31 // StoragePartition is being setup and torn down. | 31 // StoragePartition is being setup and torn down. |
32 void Init(const scoped_refptr<ServiceWorkerContextWrapper>& context); | 32 void Init(const scoped_refptr<ServiceWorkerContextWrapper>& context); |
33 | 33 |
34 // Shutdown must be called before deleting this. Call on the UI thread. | 34 // Shutdown must be called before deleting this. Call on the UI thread. |
35 void Shutdown(); | 35 void Shutdown(); |
36 | 36 |
37 // Create a BackgroundSyncServiceImpl that is owned by this. Call on the UI | 37 // Create a BackgroundSyncServiceImpl that is owned by this. Call on the UI |
38 // thread. | 38 // thread. |
39 void CreateService(mojo::InterfaceRequest<BackgroundSyncService> request); | 39 void CreateService(mojo::InterfaceRequest<BackgroundSyncService> request); |
40 | 40 |
41 // Called by BackgroundSyncServiceImpl objects so that they can | |
42 // be deleted. Call on the IO thread. | |
43 void ServiceHadConnectionError(BackgroundSyncServiceImpl* service); | |
44 | |
45 // Call on the IO thread. | 41 // Call on the IO thread. |
46 BackgroundSyncManager* background_sync_manager() const override; | 42 BackgroundSyncManager* background_sync_manager() const override; |
47 | 43 |
48 protected: | 44 protected: |
49 ~BackgroundSyncContextImpl() override; | 45 ~BackgroundSyncContextImpl() override; |
50 | 46 |
51 private: | 47 private: |
52 friend class BackgroundSyncServiceImplTest; | 48 friend class BackgroundSyncServiceImplTest; |
53 | 49 |
54 void CreateBackgroundSyncManager( | 50 void CreateBackgroundSyncManager( |
55 const scoped_refptr<ServiceWorkerContextWrapper>& context); | 51 const scoped_refptr<ServiceWorkerContextWrapper>& context); |
56 | 52 |
57 void CreateServiceOnIOThread( | 53 void CreateServiceOnIOThread( |
58 mojo::InterfaceRequest<BackgroundSyncService> request); | 54 mojo::InterfaceRequest<BackgroundSyncService> request); |
59 | 55 |
60 void ShutdownOnIO(); | 56 void ShutdownOnIO(); |
61 | 57 |
62 // Only accessed on the IO thread. | 58 // Only accessed on the IO thread. |
63 scoped_ptr<BackgroundSyncManager> background_sync_manager_; | 59 scoped_ptr<BackgroundSyncManager> background_sync_manager_; |
64 | 60 |
65 // The services are owned by this. They're either deleted | 61 // The services are owned by this. They're either deleted |
66 // during ShutdownOnIO or when the channel is closed via | 62 // during ShutdownOnIO or when the channel is closed via |
67 // ServiceHadConnectionError. Only accessed on the IO thread. | 63 // ServiceHadConnectionError. Only accessed on the IO thread. |
68 std::set<BackgroundSyncServiceImpl*> services_; | 64 mojo::StrongBindingSet<BackgroundSyncServiceImpl> services_; |
69 | 65 |
70 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncContextImpl); | 66 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncContextImpl); |
71 }; | 67 }; |
72 | 68 |
73 } // namespace content | 69 } // namespace content |
74 | 70 |
75 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTEXT_IMPL_H_ | 71 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTEXT_IMPL_H_ |
OLD | NEW |