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