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. The caller takes |
34 // the returned pointer is tied to the lifetime of the | 34 // ownership of the JobData created. |
Peter Beverloo
2017/03/08 14:27:04
Then we should return an std::unique_ptr<>.
harkness
2017/03/09 13:33:25
Done.
| |
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( | 35 BackgroundFetchJobData* CreateRequest( |
39 const BackgroundFetchJobInfo& job_info, | 36 const BackgroundFetchJobInfo& job_info, |
40 BackgroundFetchRequestInfos request_infos); | 37 BackgroundFetchRequestInfos& request_infos); |
41 | 38 |
42 private: | 39 private: |
40 void WriteJobToStorage(const BackgroundFetchJobInfo& job_info, | |
41 BackgroundFetchRequestInfos& request_infos); | |
42 | |
43 BackgroundFetchRequestInfos ReadRequestsFromStorage( | |
44 const std::string& job_guid); | |
45 | |
43 // BackgroundFetchContext owns this BackgroundFetchDataManager, so the | 46 // BackgroundFetchContext owns this BackgroundFetchDataManager, so the |
44 // DataManager is guaranteed to be destructed before the Context. | 47 // DataManager is guaranteed to be destructed before the Context. |
45 BackgroundFetchContext* background_fetch_context_; | 48 BackgroundFetchContext* background_fetch_context_; |
46 | 49 |
47 // Map from <sw_registration_id, tag> to the JobData for that tag. | 50 // Map from <sw_registration_id, tag> to the job_guid for that tag. |
48 using JobIdentifier = std::pair<int64_t, std::string>; | 51 using JobIdentifier = std::pair<int64_t, std::string>; |
49 std::map<JobIdentifier, std::string> service_worker_tag_map_; | 52 std::map<JobIdentifier, std::string> service_worker_tag_map_; |
50 | 53 |
51 // Map of batch guid to the associated BackgroundFetchJobData object. | 54 // Temporary map to hold data which will be written to storage. |
52 std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobData>> | 55 // Map from job_guid to JobInfo. |
53 batch_map_; | 56 std::unordered_map<std::string, BackgroundFetchJobInfo> job_map_; |
57 // Map from job_guid to RequestInfos. | |
58 std::unordered_map<std::string, BackgroundFetchRequestInfos> request_map_; | |
54 | 59 |
55 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); | 60 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); |
56 }; | 61 }; |
57 | 62 |
58 } // namespace content | 63 } // namespace content |
59 | 64 |
60 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ | 65 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ |
OLD | NEW |