| 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> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 class BackgroundFetchRegistrationId; | 32 class BackgroundFetchRegistrationId; |
| 33 class BackgroundFetchRequestInfo; | 33 class BackgroundFetchRequestInfo; |
| 34 class BlobHandle; | 34 class BlobHandle; |
| 35 class BrowserContext; | 35 class BrowserContext; |
| 36 class ServiceWorkerContextWrapper; | 36 class ServiceWorkerContextWrapper; |
| 37 struct ServiceWorkerFetchRequest; | 37 struct ServiceWorkerFetchRequest; |
| 38 class StoragePartitionImpl; | 38 class StoragePartitionImpl; |
| 39 | 39 |
| 40 // The BackgroundFetchContext is the central moderator of ongoing background | 40 // The BackgroundFetchContext is the central moderator of ongoing background |
| 41 // fetch requests from the Mojo service and from other callers. | 41 // fetch requests from the Mojo service and from other callers. |
| 42 // Background Fetch requests function similar to normal fetches except that | 42 // Background Fetch requests function similarly to normal fetches except that |
| 43 // they are persistent across Chromium or service worker shutdown. | 43 // they are persistent across Chromium or service worker shutdown. |
| 44 class CONTENT_EXPORT BackgroundFetchContext | 44 class CONTENT_EXPORT BackgroundFetchContext |
| 45 : public base::RefCountedThreadSafe<BackgroundFetchContext, | 45 : public base::RefCountedThreadSafe<BackgroundFetchContext, |
| 46 BrowserThread::DeleteOnUIThread> { | 46 BrowserThread::DeleteOnIOThread> { |
| 47 public: | 47 public: |
| 48 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so | 48 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so |
| 49 // that it can respond to service worker events such as unregister. | 49 // that it can respond to service worker events such as unregister. |
| 50 BackgroundFetchContext(BrowserContext* browser_context, | 50 BackgroundFetchContext(BrowserContext* browser_context, |
| 51 StoragePartitionImpl* storage_partition, | 51 StoragePartitionImpl* storage_partition, |
| 52 scoped_refptr<ServiceWorkerContextWrapper> context); | 52 scoped_refptr<ServiceWorkerContextWrapper> context); |
| 53 | 53 |
| 54 // Finishes initializing the Background Fetch context on the IO thread by | 54 // Finishes initializing the Background Fetch context on the IO thread by |
| 55 // setting the |request_context_getter|. | 55 // setting the |request_context_getter|. |
| 56 void InitializeOnIOThread( | 56 void InitializeOnIOThread( |
| 57 scoped_refptr<net::URLRequestContextGetter> request_context_getter); | 57 scoped_refptr<net::URLRequestContextGetter> request_context_getter); |
| 58 | 58 |
| 59 // Shutdown must be called before deleting this. Call on the UI thread. | |
| 60 void Shutdown(); | |
| 61 | |
| 62 // Starts a Background Fetch for the |registration_id|. The |requests| will be | 59 // Starts a Background Fetch for the |registration_id|. The |requests| will be |
| 63 // asynchronously fetched. The |callback| will be invoked when the fetch has | 60 // asynchronously fetched. The |callback| will be invoked when the fetch has |
| 64 // been registered, or an error occurred that avoids it from doing so. | 61 // been registered, or an error occurred that avoids it from doing so. |
| 65 void StartFetch(const BackgroundFetchRegistrationId& registration_id, | 62 void StartFetch(const BackgroundFetchRegistrationId& registration_id, |
| 66 const std::vector<ServiceWorkerFetchRequest>& requests, | 63 const std::vector<ServiceWorkerFetchRequest>& requests, |
| 67 const BackgroundFetchOptions& options, | 64 const BackgroundFetchOptions& options, |
| 68 blink::mojom::BackgroundFetchService::FetchCallback callback); | 65 blink::mojom::BackgroundFetchService::FetchCallback callback); |
| 69 | 66 |
| 70 // Returns a vector with the tags of the active fetches for the given |origin| | 67 // Returns a vector with the tags of the active fetches for the given |origin| |
| 71 // and |service_worker_registration_id|. | 68 // and |service_worker_registration_id|. |
| 72 std::vector<std::string> GetActiveTagsForServiceWorkerRegistration( | 69 std::vector<std::string> GetActiveTagsForServiceWorkerRegistration( |
| 73 int64_t service_worker_registration_id, | 70 int64_t service_worker_registration_id, |
| 74 const url::Origin& origin) const; | 71 const url::Origin& origin) const; |
| 75 | 72 |
| 76 // Returns the JobController that is handling the |registration_id|, or a | 73 // Returns the JobController that is handling the |registration_id|, or a |
| 77 // nullptr if it does not exist. Must be immediately used by the caller. | 74 // nullptr if it does not exist. Must be immediately used by the caller. |
| 78 BackgroundFetchJobController* GetActiveFetch( | 75 BackgroundFetchJobController* GetActiveFetch( |
| 79 const BackgroundFetchRegistrationId& registration_id) const; | 76 const BackgroundFetchRegistrationId& registration_id) const; |
| 80 | 77 |
| 81 private: | 78 private: |
| 82 friend class base::DeleteHelper<BackgroundFetchContext>; | 79 friend class base::DeleteHelper<BackgroundFetchContext>; |
| 83 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 80 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
| 84 friend class base::RefCountedThreadSafe<BackgroundFetchContext, | 81 friend class base::RefCountedThreadSafe<BackgroundFetchContext, |
| 85 BrowserThread::DeleteOnUIThread>; | 82 BrowserThread::DeleteOnIOThread>; |
| 86 | 83 |
| 87 ~BackgroundFetchContext(); | 84 ~BackgroundFetchContext(); |
| 88 | 85 |
| 89 // Shuts down the active Job Controllers on the IO thread. | |
| 90 void ShutdownOnIO(); | |
| 91 | |
| 92 // Creates a new Job Controller for the given |registration_id| and |options|, | 86 // Creates a new Job Controller for the given |registration_id| and |options|, |
| 93 // which will start fetching the files that are part of the registration. | 87 // which will start fetching the files that are part of the registration. |
| 94 void CreateController( | 88 void CreateController( |
| 95 const BackgroundFetchRegistrationId& registration_id, | 89 const BackgroundFetchRegistrationId& registration_id, |
| 96 const BackgroundFetchOptions& options, | 90 const BackgroundFetchOptions& options, |
| 97 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests); | 91 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests); |
| 98 | 92 |
| 99 // Called when a new registration has been created by the data manager. | 93 // Called when a new registration has been created by the data manager. |
| 100 void DidCreateRegistration( | 94 void DidCreateRegistration( |
| 101 const BackgroundFetchRegistrationId& registration_id, | 95 const BackgroundFetchRegistrationId& registration_id, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 std::map<BackgroundFetchRegistrationId, | 128 std::map<BackgroundFetchRegistrationId, |
| 135 std::unique_ptr<BackgroundFetchJobController>> | 129 std::unique_ptr<BackgroundFetchJobController>> |
| 136 active_fetches_; | 130 active_fetches_; |
| 137 | 131 |
| 138 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext); | 132 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext); |
| 139 }; | 133 }; |
| 140 | 134 |
| 141 } // namespace content | 135 } // namespace content |
| 142 | 136 |
| 143 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ | 137 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ |
| OLD | NEW |