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_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/callback_forward.h" | 17 #include "base/callback_forward.h" |
18 #include "base/cancelable_callback.h" | 18 #include "base/cancelable_callback.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
21 #include "base/time/clock.h" | 21 #include "base/time/clock.h" |
22 #include "content/browser/background_sync/background_sync.pb.h" | 22 #include "content/browser/background_sync/background_sync.pb.h" |
23 #include "content/browser/background_sync/background_sync_registration.h" | 23 #include "content/browser/background_sync/background_sync_registration.h" |
24 #include "content/browser/background_sync/background_sync_status.h" | 24 #include "content/browser/background_sync/background_sync_status.h" |
25 #include "content/browser/cache_storage/cache_storage_scheduler.h" | 25 #include "content/browser/cache_storage/cache_storage_scheduler.h" |
26 #include "content/browser/service_worker/service_worker_context_observer.h" | 26 #include "content/browser/service_worker/service_worker_context_core_observer.h" |
27 #include "content/browser/service_worker/service_worker_storage.h" | 27 #include "content/browser/service_worker/service_worker_storage.h" |
28 #include "content/common/content_export.h" | 28 #include "content/common/content_export.h" |
29 #include "content/common/service_worker/service_worker_status_code.h" | 29 #include "content/common/service_worker/service_worker_status_code.h" |
30 #include "content/public/browser/background_sync_parameters.h" | 30 #include "content/public/browser/background_sync_parameters.h" |
31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
32 #include "third_party/WebKit/public/platform/modules/background_sync/background_
sync.mojom.h" | 32 #include "third_party/WebKit/public/platform/modules/background_sync/background_
sync.mojom.h" |
33 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 33 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
34 #include "url/gurl.h" | 34 #include "url/gurl.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 namespace mojom { | 37 namespace mojom { |
38 enum class PermissionStatus; | 38 enum class PermissionStatus; |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 namespace content { | 42 namespace content { |
43 | 43 |
44 class BackgroundSyncNetworkObserver; | 44 class BackgroundSyncNetworkObserver; |
45 class ServiceWorkerContextWrapper; | 45 class ServiceWorkerContextWrapper; |
46 | 46 |
47 // BackgroundSyncManager manages and stores the set of background sync | 47 // BackgroundSyncManager manages and stores the set of background sync |
48 // registrations across all registered service workers for a profile. | 48 // registrations across all registered service workers for a profile. |
49 // Registrations are stored along with their associated Service Worker | 49 // Registrations are stored along with their associated Service Worker |
50 // registration in ServiceWorkerStorage. If the ServiceWorker is unregistered, | 50 // registration in ServiceWorkerStorage. If the ServiceWorker is unregistered, |
51 // the sync registrations are removed. This class must be run on the IO | 51 // the sync registrations are removed. This class must be run on the IO |
52 // thread. The asynchronous methods are executed sequentially. | 52 // thread. The asynchronous methods are executed sequentially. |
53 class CONTENT_EXPORT BackgroundSyncManager | 53 class CONTENT_EXPORT BackgroundSyncManager |
54 : NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { | 54 : NON_EXPORTED_BASE(public ServiceWorkerContextCoreObserver) { |
55 public: | 55 public: |
56 using BoolCallback = base::Callback<void(bool)>; | 56 using BoolCallback = base::Callback<void(bool)>; |
57 using StatusCallback = base::Callback<void(BackgroundSyncStatus)>; | 57 using StatusCallback = base::Callback<void(BackgroundSyncStatus)>; |
58 using StatusAndRegistrationCallback = | 58 using StatusAndRegistrationCallback = |
59 base::Callback<void(BackgroundSyncStatus, | 59 base::Callback<void(BackgroundSyncStatus, |
60 std::unique_ptr<BackgroundSyncRegistration>)>; | 60 std::unique_ptr<BackgroundSyncRegistration>)>; |
61 using StatusAndRegistrationsCallback = base::Callback<void( | 61 using StatusAndRegistrationsCallback = base::Callback<void( |
62 BackgroundSyncStatus, | 62 BackgroundSyncStatus, |
63 std::vector<std::unique_ptr<BackgroundSyncRegistration>>)>; | 63 std::vector<std::unique_ptr<BackgroundSyncRegistration>>)>; |
64 | 64 |
(...skipping 11 matching lines...) Expand all Loading... |
76 void Register(int64_t sw_registration_id, | 76 void Register(int64_t sw_registration_id, |
77 const BackgroundSyncRegistrationOptions& options, | 77 const BackgroundSyncRegistrationOptions& options, |
78 const StatusAndRegistrationCallback& callback); | 78 const StatusAndRegistrationCallback& callback); |
79 | 79 |
80 // Finds the background sync registrations associated with | 80 // Finds the background sync registrations associated with |
81 // |sw_registration_id|. Calls |callback| with BACKGROUND_SYNC_STATUS_OK on | 81 // |sw_registration_id|. Calls |callback| with BACKGROUND_SYNC_STATUS_OK on |
82 // success. | 82 // success. |
83 void GetRegistrations(int64_t sw_registration_id, | 83 void GetRegistrations(int64_t sw_registration_id, |
84 const StatusAndRegistrationsCallback& callback); | 84 const StatusAndRegistrationsCallback& callback); |
85 | 85 |
86 // ServiceWorkerContextObserver overrides. | 86 // ServiceWorkerContextCoreObserver overrides. |
87 void OnRegistrationDeleted(int64_t sw_registration_id, | 87 void OnRegistrationDeleted(int64_t sw_registration_id, |
88 const GURL& pattern) override; | 88 const GURL& pattern) override; |
89 void OnStorageWiped() override; | 89 void OnStorageWiped() override; |
90 | 90 |
91 // Sets the max number of sync attempts after any pending operations have | 91 // Sets the max number of sync attempts after any pending operations have |
92 // completed. | 92 // completed. |
93 void SetMaxSyncAttemptsForTesting(int max_attempts); | 93 void SetMaxSyncAttemptsForTesting(int max_attempts); |
94 | 94 |
95 BackgroundSyncNetworkObserver* GetNetworkObserverForTesting() { | 95 BackgroundSyncNetworkObserver* GetNetworkObserverForTesting() { |
96 return network_observer_.get(); | 96 return network_observer_.get(); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 std::unique_ptr<base::Clock> clock_; | 304 std::unique_ptr<base::Clock> clock_; |
305 | 305 |
306 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; | 306 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; |
307 | 307 |
308 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); | 308 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); |
309 }; | 309 }; |
310 | 310 |
311 } // namespace content | 311 } // namespace content |
312 | 312 |
313 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ | 313 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
OLD | NEW |