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 <string> | 9 #include <string> |
10 #include <unordered_map> | 10 #include <unordered_map> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "content/browser/background_fetch/background_fetch_job_data.h" | 13 #include "content/browser/background_fetch/background_fetch_job_data.h" |
| 14 #include "content/browser/background_fetch/background_fetch_job_info.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 #include "url/origin.h" | 16 #include "url/origin.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 class BackgroundFetchContext; | 20 class BackgroundFetchContext; |
20 class BackgroundFetchJobInfo; | |
21 | 21 |
22 // The BackgroundFetchDataManager keeps track of all of the outstanding requests | 22 // The BackgroundFetchDataManager keeps track of all of the outstanding requests |
23 // which are in process in the DownloadManager. When Chromium restarts, it is | 23 // which are in process in the DownloadManager. When Chromium restarts, it is |
24 // responsibile for reconnecting all the in progress downloads with an observer | 24 // responsibile for reconnecting all the in progress downloads with an observer |
25 // which will keep the metadata up to date. | 25 // which will keep the metadata up to date. |
26 class CONTENT_EXPORT BackgroundFetchDataManager { | 26 class CONTENT_EXPORT BackgroundFetchDataManager { |
27 public: | 27 public: |
28 explicit BackgroundFetchDataManager( | 28 explicit BackgroundFetchDataManager( |
29 BackgroundFetchContext* background_fetch_context); | 29 BackgroundFetchContext* background_fetch_context); |
30 ~BackgroundFetchDataManager(); | 30 ~BackgroundFetchDataManager(); |
31 | 31 |
32 // Called by BackgroundFetchContext when a new request is started, this will | 32 // Called by BackgroundFetchContext when a new request is started, this will |
33 // store all of the necessary metadata to track the request. The lifetime of | 33 // store all of the necessary metadata to track the request. |
34 // the returned pointer is tied to the lifetime of the | 34 std::unique_ptr<BackgroundFetchJobData> CreateRequest( |
35 // BackgroundFetchDataManager. | |
36 // TODO(harkness): Lifetime should be tied to the lifetime of the associated | |
37 // JobController once there is a JobController per request. | |
38 BackgroundFetchJobData* CreateRequest( | |
39 const BackgroundFetchJobInfo& job_info, | 35 const BackgroundFetchJobInfo& job_info, |
40 BackgroundFetchRequestInfos request_infos); | 36 BackgroundFetchRequestInfos request_infos); |
41 | 37 |
42 private: | 38 private: |
| 39 void WriteJobToStorage(const BackgroundFetchJobInfo& job_info, |
| 40 BackgroundFetchRequestInfos request_infos); |
| 41 |
| 42 BackgroundFetchRequestInfos& ReadRequestsFromStorage( |
| 43 const std::string& job_guid); |
| 44 |
43 // BackgroundFetchContext owns this BackgroundFetchDataManager, so the | 45 // BackgroundFetchContext owns this BackgroundFetchDataManager, so the |
44 // DataManager is guaranteed to be destructed before the Context. | 46 // DataManager is guaranteed to be destructed before the Context. |
45 BackgroundFetchContext* background_fetch_context_; | 47 BackgroundFetchContext* background_fetch_context_; |
46 | 48 |
47 // Map from <sw_registration_id, tag> to the JobData for that tag. | 49 // Map from <sw_registration_id, tag> to the job_guid for that tag. |
48 using JobIdentifier = std::pair<int64_t, std::string>; | 50 using JobIdentifier = std::pair<int64_t, std::string>; |
49 std::map<JobIdentifier, std::string> service_worker_tag_map_; | 51 std::map<JobIdentifier, std::string> service_worker_tag_map_; |
50 | 52 |
51 // Map of batch guid to the associated BackgroundFetchJobData object. | 53 // Temporary map to hold data which will be written to storage. |
52 std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobData>> | 54 // Map from job_guid to JobInfo. |
53 batch_map_; | 55 std::unordered_map<std::string, BackgroundFetchJobInfo> job_map_; |
| 56 // Map from job_guid to RequestInfos. |
| 57 std::unordered_map<std::string, BackgroundFetchRequestInfos> request_map_; |
54 | 58 |
55 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); | 59 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); |
56 }; | 60 }; |
57 | 61 |
58 } // namespace content | 62 } // namespace content |
59 | 63 |
60 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ | 64 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ |
OLD | NEW |