| 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_DATA_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <unordered_map> | 11 #include <unordered_map> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/optional.h" | 15 #include "base/optional.h" |
| 16 #include "content/browser/background_fetch/background_fetch_registration_id.h" | 16 #include "content/browser/background_fetch/background_fetch_registration_id.h" |
| 17 #include "content/browser/background_fetch/background_fetch_request_info.h" | |
| 18 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 19 #include "third_party/WebKit/public/platform/modules/background_fetch/background
_fetch.mojom.h" | 18 #include "third_party/WebKit/public/platform/modules/background_fetch/background
_fetch.mojom.h" |
| 20 #include "url/origin.h" | 19 #include "url/origin.h" |
| 21 | 20 |
| 22 namespace content { | 21 namespace content { |
| 23 | 22 |
| 23 class BackgroundFetchRequestInfo; |
| 24 struct BackgroundFetchSettledFetch; | 24 struct BackgroundFetchSettledFetch; |
| 25 class BlobHandle; | 25 class BlobHandle; |
| 26 class BrowserContext; | 26 class BrowserContext; |
| 27 class ChromeBlobStorageContext; | 27 class ChromeBlobStorageContext; |
| 28 | 28 |
| 29 // The BackgroundFetchDataManager keeps track of all of the outstanding requests | 29 // The BackgroundFetchDataManager keeps track of all of the outstanding requests |
| 30 // which are in process in the DownloadManager. When Chromium restarts, it is | 30 // which are in process in the DownloadManager. When Chromium restarts, it is |
| 31 // responsibile for reconnecting all the in progress downloads with an observer | 31 // responsibile for reconnecting all the in progress downloads with an observer |
| 32 // which will keep the metadata up to date. | 32 // which will keep the metadata up to date. |
| 33 class CONTENT_EXPORT BackgroundFetchDataManager { | 33 class CONTENT_EXPORT BackgroundFetchDataManager { |
| 34 public: | 34 public: |
| 35 using CreateRegistrationCallback = | 35 using CreateRegistrationCallback = base::OnceCallback<void( |
| 36 base::OnceCallback<void(blink::mojom::BackgroundFetchError, | 36 blink::mojom::BackgroundFetchError, |
| 37 std::vector<BackgroundFetchRequestInfo>)>; | 37 std::vector<scoped_refptr<BackgroundFetchRequestInfo>>)>; |
| 38 using DeleteRegistrationCallback = | 38 using DeleteRegistrationCallback = |
| 39 base::OnceCallback<void(blink::mojom::BackgroundFetchError)>; | 39 base::OnceCallback<void(blink::mojom::BackgroundFetchError)>; |
| 40 using NextRequestCallback = base::OnceCallback<void( | 40 using NextRequestCallback = |
| 41 const base::Optional<BackgroundFetchRequestInfo>&)>; | 41 base::OnceCallback<void(scoped_refptr<BackgroundFetchRequestInfo>)>; |
| 42 using SettledFetchesCallback = | 42 using SettledFetchesCallback = |
| 43 base::OnceCallback<void(blink::mojom::BackgroundFetchError, | 43 base::OnceCallback<void(blink::mojom::BackgroundFetchError, |
| 44 std::vector<BackgroundFetchSettledFetch>, | 44 std::vector<BackgroundFetchSettledFetch>, |
| 45 std::vector<std::unique_ptr<BlobHandle>>)>; | 45 std::vector<std::unique_ptr<BlobHandle>>)>; |
| 46 | 46 |
| 47 explicit BackgroundFetchDataManager(BrowserContext* browser_context); | 47 explicit BackgroundFetchDataManager(BrowserContext* browser_context); |
| 48 ~BackgroundFetchDataManager(); | 48 ~BackgroundFetchDataManager(); |
| 49 | 49 |
| 50 // Creates and stores a new registration with the given properties. Will | 50 // Creates and stores a new registration with the given properties. Will |
| 51 // invoke the |callback| when the registration has been created, which may | 51 // invoke the |callback| when the registration has been created, which may |
| 52 // fail due to invalid input or storage errors. | 52 // fail due to invalid input or storage errors. |
| 53 void CreateRegistration( | 53 void CreateRegistration( |
| 54 const BackgroundFetchRegistrationId& registration_id, | 54 const BackgroundFetchRegistrationId& registration_id, |
| 55 const std::vector<ServiceWorkerFetchRequest>& requests, | 55 const std::vector<ServiceWorkerFetchRequest>& requests, |
| 56 const BackgroundFetchOptions& options, | 56 const BackgroundFetchOptions& options, |
| 57 CreateRegistrationCallback callback); | 57 CreateRegistrationCallback callback); |
| 58 | 58 |
| 59 // Marks that the |request|, part of the Background Fetch identified by | 59 // Marks that the |request|, part of the Background Fetch identified by |
| 60 // |registration_id|, has been started as |download_guid|. | 60 // |registration_id|, has been started as |download_guid|. |
| 61 void MarkRequestAsStarted( | 61 void MarkRequestAsStarted( |
| 62 const BackgroundFetchRegistrationId& registration_id, | 62 const BackgroundFetchRegistrationId& registration_id, |
| 63 const BackgroundFetchRequestInfo& request, | 63 BackgroundFetchRequestInfo* request, |
| 64 const std::string& download_guid); | 64 const std::string& download_guid); |
| 65 | 65 |
| 66 // Marks that the |request|, part of the Background Fetch identified by | 66 // Marks that the |request|, part of the Background Fetch identified by |
| 67 // |registration_id|, has completed. Will invoke the |callback| with the | 67 // |registration_id|, has completed. Will invoke the |callback| with the |
| 68 // next request, if any, when the operation has completed. | 68 // next request, if any, when the operation has completed. |
| 69 void MarkRequestAsCompleteAndGetNextRequest( | 69 void MarkRequestAsCompleteAndGetNextRequest( |
| 70 const BackgroundFetchRegistrationId& registration_id, | 70 const BackgroundFetchRegistrationId& registration_id, |
| 71 const BackgroundFetchRequestInfo& request, | 71 BackgroundFetchRequestInfo* request, |
| 72 NextRequestCallback callback); | 72 NextRequestCallback callback); |
| 73 | 73 |
| 74 // Reads all settled fetches for the given |registration_id|. Both the Request | 74 // Reads all settled fetches for the given |registration_id|. Both the Request |
| 75 // and Response objects will be initialised based on the stored data. Will | 75 // and Response objects will be initialised based on the stored data. Will |
| 76 // invoke the |callback| when the list of fetches has been compiled. | 76 // invoke the |callback| when the list of fetches has been compiled. |
| 77 void GetSettledFetchesForRegistration( | 77 void GetSettledFetchesForRegistration( |
| 78 const BackgroundFetchRegistrationId& registration_id, | 78 const BackgroundFetchRegistrationId& registration_id, |
| 79 SettledFetchesCallback callback); | 79 SettledFetchesCallback callback); |
| 80 | 80 |
| 81 // Deletes the registration identified by |registration_id|. Will invoke the | 81 // Deletes the registration identified by |registration_id|. Will invoke the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 96 registrations_; | 96 registrations_; |
| 97 | 97 |
| 98 base::WeakPtrFactory<BackgroundFetchDataManager> weak_ptr_factory_; | 98 base::WeakPtrFactory<BackgroundFetchDataManager> weak_ptr_factory_; |
| 99 | 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); | 100 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 } // namespace content | 103 } // namespace content |
| 104 | 104 |
| 105 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ | 105 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ |
| OLD | NEW |