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_JOB_DATA_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_DATA_H_ |
6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_DATA_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_DATA_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "content/browser/background_fetch/background_fetch_request_info.h" | 12 #include "content/browser/background_fetch/background_fetch_request_info.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "url/origin.h" | 14 #include "url/origin.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 // The BackgroundFetchJobData class provides the interface from the | 18 // The BackgroundFetchJobData class provides the interface from the |
19 // JobController to the data storage in the DataManager. It has a reference | 19 // JobController to the data storage in the DataManager. It has a reference |
20 // to the DataManager and invokes calls given the stored batch_guid. | 20 // to the DataManager and invokes calls given the stored batch_guid. |
21 class CONTENT_EXPORT BackgroundFetchJobData { | 21 class CONTENT_EXPORT BackgroundFetchJobData { |
22 public: | 22 public: |
23 explicit BackgroundFetchJobData(BackgroundFetchRequestInfos request_infos); | 23 explicit BackgroundFetchJobData(BackgroundFetchRequestInfos& request_infos); |
24 ~BackgroundFetchJobData(); | 24 ~BackgroundFetchJobData(); |
25 | 25 |
26 // Called by the JobController to inform the JobData that the given fetch | 26 // Called by the JobController to inform the JobData that the given fetch |
27 // has completed. The JobData returns a boolean indicating whether there | 27 // has completed. The JobData returns a boolean indicating whether there |
28 // are more requests to process. | 28 // are more requests to process. |
29 bool BackgroundFetchRequestInfoComplete(const std::string& fetch_guid); | 29 bool BackgroundFetchRequestInfoComplete(const std::string& fetch_guid); |
30 | 30 |
31 // Called by the JobController to get a BackgroundFetchRequestInfo to | 31 // Called by the JobController to get a BackgroundFetchRequestInfo to |
32 // process. | 32 // process. |
33 const BackgroundFetchRequestInfo& GetNextBackgroundFetchRequestInfo(); | 33 const BackgroundFetchRequestInfo& GetNextBackgroundFetchRequestInfo(); |
34 | 34 |
35 // Indicates whether all requests have been handed to the JobController. | 35 // Indicates whether all requests have been handed to the JobController. |
36 bool HasRequestsRemaining() const; | 36 bool HasRequestsRemaining() const; |
37 | 37 |
38 // Indicates whether all requests have been handed out and completed. | 38 // Indicates whether all requests have been handed out and completed. |
39 bool IsComplete() const; | 39 bool IsComplete() const; |
40 | 40 |
41 private: | 41 private: |
42 BackgroundFetchRequestInfos request_infos_; | 42 BackgroundFetchRequestInfos& request_infos_; |
43 | 43 |
44 // Map from fetch_guid to index in request_infos_. Only currently | 44 // Map from fetch_guid to index in request_infos_. Only currently |
45 // outstanding requests should be in this map. | 45 // outstanding requests should be in this map. |
46 std::unordered_map<std::string, int> request_info_index_; | 46 std::unordered_map<std::string, int> request_info_index_; |
47 size_t next_request_info_ = 0; | 47 size_t next_request_info_ = 0; |
48 | 48 |
49 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobData); | 49 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobData); |
50 }; | 50 }; |
51 | 51 |
52 } // namespace content | 52 } // namespace content |
53 | 53 |
54 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_DATA_H_ | 54 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_DATA_H_ |
OLD | NEW |