OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_FETCH_BACKGROUND_FETCH_CONTEXT_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ |
6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "third_party/WebKit/public/platform/modules/background_fetch/background
_fetch.mojom.h" | 16 #include "third_party/WebKit/public/platform/modules/background_fetch/background
_fetch.mojom.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 class URLRequestContextGetter; | 19 class URLRequestContextGetter; |
20 } | 20 } |
21 | 21 |
22 namespace url { | 22 namespace url { |
23 class Origin; | 23 class Origin; |
24 } | 24 } |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 class BackgroundFetchDataManager; | 28 class BackgroundFetchDataManager; |
| 29 class BackgroundFetchEventDispatcher; |
29 class BackgroundFetchJobController; | 30 class BackgroundFetchJobController; |
30 struct BackgroundFetchOptions; | 31 struct BackgroundFetchOptions; |
31 class BackgroundFetchRegistrationId; | 32 class BackgroundFetchRegistrationId; |
32 class BackgroundFetchRequestInfo; | 33 class BackgroundFetchRequestInfo; |
| 34 class BlobHandle; |
33 class BrowserContext; | 35 class BrowserContext; |
34 class DownloadManager; | 36 class DownloadManager; |
35 class ServiceWorkerContextWrapper; | 37 class ServiceWorkerContextWrapper; |
36 struct ServiceWorkerFetchRequest; | 38 struct ServiceWorkerFetchRequest; |
37 class StoragePartitionImpl; | 39 class StoragePartitionImpl; |
38 | 40 |
39 // The BackgroundFetchContext is the central moderator of ongoing background | 41 // The BackgroundFetchContext is the central moderator of ongoing background |
40 // fetch requests from the Mojo service and from other callers. | 42 // fetch requests from the Mojo service and from other callers. |
41 // Background Fetch requests function similar to normal fetches except that | 43 // Background Fetch requests function similar to normal fetches except that |
42 // they are persistent across Chromium or service worker shutdown. | 44 // they are persistent across Chromium or service worker shutdown. |
43 class CONTENT_EXPORT BackgroundFetchContext | 45 class CONTENT_EXPORT BackgroundFetchContext |
44 : public base::RefCountedThreadSafe<BackgroundFetchContext, | 46 : public base::RefCountedThreadSafe<BackgroundFetchContext, |
45 BrowserThread::DeleteOnUIThread> { | 47 BrowserThread::DeleteOnUIThread> { |
46 public: | 48 public: |
47 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so | 49 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so |
48 // that it can respond to service worker events such as unregister. | 50 // that it can respond to service worker events such as unregister. |
49 BackgroundFetchContext( | 51 BackgroundFetchContext(BrowserContext* browser_context, |
50 BrowserContext* browser_context, | 52 StoragePartitionImpl* storage_partition, |
51 StoragePartitionImpl* storage_partition, | 53 scoped_refptr<ServiceWorkerContextWrapper> context); |
52 const scoped_refptr<ServiceWorkerContextWrapper>& context); | |
53 | 54 |
54 // Shutdown must be called before deleting this. Call on the UI thread. | 55 // Shutdown must be called before deleting this. Call on the UI thread. |
55 void Shutdown(); | 56 void Shutdown(); |
56 | 57 |
57 // Starts a Background Fetch for the |registration_id|. The |requests| will be | 58 // Starts a Background Fetch for the |registration_id|. The |requests| will be |
58 // asynchronously fetched. The |callback| will be invoked when the fetch has | 59 // asynchronously fetched. The |callback| will be invoked when the fetch has |
59 // been registered, or an error occurred that avoids it from doing so. | 60 // been registered, or an error occurred that avoids it from doing so. |
60 void StartFetch( | 61 void StartFetch( |
61 const BackgroundFetchRegistrationId& registration_id, | 62 const BackgroundFetchRegistrationId& registration_id, |
62 const std::vector<ServiceWorkerFetchRequest>& requests, | 63 const std::vector<ServiceWorkerFetchRequest>& requests, |
(...skipping 30 matching lines...) Expand all Loading... |
93 std::vector<BackgroundFetchRequestInfo> initial_requests); | 94 std::vector<BackgroundFetchRequestInfo> initial_requests); |
94 | 95 |
95 // Called when a new registration has been created by the data manager. | 96 // Called when a new registration has been created by the data manager. |
96 void DidCreateRegistration( | 97 void DidCreateRegistration( |
97 const BackgroundFetchRegistrationId& registration_id, | 98 const BackgroundFetchRegistrationId& registration_id, |
98 const BackgroundFetchOptions& options, | 99 const BackgroundFetchOptions& options, |
99 const blink::mojom::BackgroundFetchService::FetchCallback& callback, | 100 const blink::mojom::BackgroundFetchService::FetchCallback& callback, |
100 blink::mojom::BackgroundFetchError error, | 101 blink::mojom::BackgroundFetchError error, |
101 std::vector<BackgroundFetchRequestInfo> initial_requests); | 102 std::vector<BackgroundFetchRequestInfo> initial_requests); |
102 | 103 |
103 // Called when a the given |controller| has finished processing its job. | 104 // Called when the given |controller| has finished processing its job. |
104 void DidCompleteJob(BackgroundFetchJobController* controller); | 105 void DidCompleteJob(BackgroundFetchJobController* controller); |
105 | 106 |
| 107 // Called when the sequence of settled fetches for |registration_id| have been |
| 108 // retrieved from storage, and the Service Worker event can be invoked. |
| 109 void DidGetSettledFetches( |
| 110 const BackgroundFetchRegistrationId& registration_id, |
| 111 blink::mojom::BackgroundFetchError error, |
| 112 std::vector<BackgroundFetchSettledFetch> settled_fetches, |
| 113 std::vector<std::unique_ptr<BlobHandle>> blob_handles); |
| 114 |
| 115 // Called when all processing for the |registration_id| has been finished and |
| 116 // the job, including its associated data, is ready to be deleted. |
| 117 void DeleteRegistration(const BackgroundFetchRegistrationId& registration_id); |
| 118 |
106 // |this| is owned, indirectly, by the BrowserContext. | 119 // |this| is owned, indirectly, by the BrowserContext. |
107 BrowserContext* browser_context_; | 120 BrowserContext* browser_context_; |
108 DownloadManager* download_manager_; | 121 DownloadManager* download_manager_; |
109 | 122 |
110 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | |
111 scoped_refptr<net::URLRequestContextGetter> request_context_; | 123 scoped_refptr<net::URLRequestContextGetter> request_context_; |
112 | 124 |
113 std::unique_ptr<BackgroundFetchDataManager> background_fetch_data_manager_; | 125 std::unique_ptr<BackgroundFetchDataManager> data_manager_; |
| 126 std::unique_ptr<BackgroundFetchEventDispatcher> event_dispatcher_; |
114 | 127 |
115 // Map of the Background Fetch fetches that are currently in-progress. | 128 // Map of the Background Fetch fetches that are currently in-progress. |
116 std::map<BackgroundFetchRegistrationId, | 129 std::map<BackgroundFetchRegistrationId, |
117 std::unique_ptr<BackgroundFetchJobController>> | 130 std::unique_ptr<BackgroundFetchJobController>> |
118 active_fetches_; | 131 active_fetches_; |
119 | 132 |
120 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext); | 133 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext); |
121 }; | 134 }; |
122 | 135 |
123 } // namespace content | 136 } // namespace content |
124 | 137 |
125 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ | 138 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ |
OLD | NEW |