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 <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <vector> |
11 #include <unordered_map> | |
12 | 11 |
| 12 #include "base/callback_forward.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "content/browser/background_fetch/background_fetch_job_data.h" | |
15 #include "content/browser/background_fetch/background_fetch_job_info.h" | |
16 #include "content/browser/background_fetch/background_fetch_registration_id.h" | 14 #include "content/browser/background_fetch/background_fetch_registration_id.h" |
17 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
18 #include "url/origin.h" | 16 #include "third_party/WebKit/public/platform/modules/background_fetch/background
_fetch.mojom.h" |
19 | 17 |
20 namespace content { | 18 namespace content { |
21 | 19 |
22 class BackgroundFetchContext; | 20 class BackgroundFetchJobData; |
| 21 struct ServiceWorkerFetchRequest; |
23 | 22 |
24 // The BackgroundFetchDataManager keeps track of all of the outstanding requests | 23 // The BackgroundFetchDataManager keeps track of all of the outstanding requests |
25 // which are in process in the DownloadManager. When Chromium restarts, it is | 24 // which are in process in the DownloadManager. When Chromium restarts, it is |
26 // responsibile for reconnecting all the in progress downloads with an observer | 25 // responsibile for reconnecting all the in progress downloads with an observer |
27 // which will keep the metadata up to date. | 26 // which will keep the metadata up to date. |
28 class CONTENT_EXPORT BackgroundFetchDataManager { | 27 class CONTENT_EXPORT BackgroundFetchDataManager { |
29 public: | 28 public: |
30 explicit BackgroundFetchDataManager( | 29 using CreateRegistrationCallback = |
31 BackgroundFetchContext* background_fetch_context); | 30 base::OnceCallback<void(blink::mojom::BackgroundFetchError, |
| 31 std::unique_ptr<BackgroundFetchJobData>)>; |
| 32 using DeleteRegistrationCallback = |
| 33 base::OnceCallback<void(blink::mojom::BackgroundFetchError)>; |
| 34 |
| 35 BackgroundFetchDataManager(); |
32 ~BackgroundFetchDataManager(); | 36 ~BackgroundFetchDataManager(); |
33 | 37 |
34 // Called by BackgroundFetchContext when a new request is started, this will | 38 // Creates and stores a new registration with the given properties. Will |
35 // store all of the necessary metadata to track the request. | 39 // invoke the |callback| when the registration has been created, which may |
36 std::unique_ptr<BackgroundFetchJobData> CreateRequest( | 40 // fail due to invalid input or storage errors. |
37 std::unique_ptr<BackgroundFetchJobInfo> job_info, | 41 void CreateRegistration( |
38 BackgroundFetchRequestInfos request_infos); | 42 const BackgroundFetchRegistrationId& registration_id, |
| 43 const std::vector<ServiceWorkerFetchRequest>& requests, |
| 44 const BackgroundFetchOptions& options, |
| 45 CreateRegistrationCallback callback); |
| 46 |
| 47 // Deletes the registration identified by |registration_id|. Will invoke the |
| 48 // |callback| when the registration has been deleted from storage. |
| 49 void DeleteRegistration(const BackgroundFetchRegistrationId& registration_id, |
| 50 DeleteRegistrationCallback callback); |
39 | 51 |
40 private: | 52 private: |
41 void WriteJobToStorage(std::unique_ptr<BackgroundFetchJobInfo> job_info, | 53 // TODO(peter): Created registrations should write to storage as opposed to |
42 BackgroundFetchRequestInfos request_infos); | 54 // a map scoped to the lifetime of this instance. |
43 | 55 std::set<BackgroundFetchRegistrationId> registrations_; |
44 BackgroundFetchRequestInfos& ReadRequestsFromStorage( | |
45 const std::string& job_guid); | |
46 | |
47 // BackgroundFetchContext owns this BackgroundFetchDataManager, so the | |
48 // DataManager is guaranteed to be destructed before the Context. | |
49 BackgroundFetchContext* background_fetch_context_; | |
50 | |
51 // Set of known background fetch registration ids. | |
52 std::set<BackgroundFetchRegistrationId> known_registrations_; | |
53 | |
54 // Temporary map to hold data which will be written to storage. | |
55 // Map from job_guid to JobInfo. | |
56 std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobInfo>> | |
57 job_map_; | |
58 // Map from job_guid to RequestInfos. | |
59 std::unordered_map<std::string, BackgroundFetchRequestInfos> request_map_; | |
60 | 56 |
61 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); | 57 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); |
62 }; | 58 }; |
63 | 59 |
64 } // namespace content | 60 } // namespace content |
65 | 61 |
66 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ | 62 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ |
OLD | NEW |