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