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_INFO_H | 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_INFO_H |
6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_INFO_H | 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_INFO_H |
7 | 7 |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
| 12 #include "base/containers/flat_set.h" |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
13 #include "content/common/service_worker/service_worker_types.h" | 15 #include "content/common/service_worker/service_worker_types.h" |
14 #include "url/origin.h" | 16 #include "url/origin.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 | 19 |
| 20 class BackgroundFetchJobResponseData; |
| 21 class BackgroundFetchRequestInfo; |
| 22 |
18 // Class to encapsulate a batch of FetchRequests into a single grouping which is | 23 // Class to encapsulate a batch of FetchRequests into a single grouping which is |
19 // what the developer requested. | 24 // what the developer requested. |
20 class CONTENT_EXPORT BackgroundFetchJobInfo { | 25 class CONTENT_EXPORT BackgroundFetchJobInfo { |
21 public: | 26 public: |
22 BackgroundFetchJobInfo(const std::string& tag, | 27 BackgroundFetchJobInfo(const std::string& tag, |
23 const url::Origin& origin, | 28 const url::Origin& origin, |
24 int64_t service_worker_registration_id); | 29 int64_t service_worker_registration_id); |
25 ~BackgroundFetchJobInfo(); | 30 ~BackgroundFetchJobInfo(); |
26 | 31 |
27 const std::string& guid() const { return guid_; } | 32 const std::string& guid() const { return guid_; } |
28 const std::string& tag() const { return tag_; } | 33 const std::string& tag() const { return tag_; } |
29 const url::Origin& origin() const { return origin_; } | 34 const url::Origin& origin() const { return origin_; } |
30 int64_t service_worker_registration_id() const { | 35 int64_t service_worker_registration_id() const { |
31 return service_worker_registration_id_; | 36 return service_worker_registration_id_; |
32 } | 37 } |
33 | 38 |
34 const std::vector<std::string>& request_guids() const { | 39 const std::vector<std::string>& request_guids() const { |
35 return request_guids_; | 40 return request_guids_; |
36 } | 41 } |
37 | 42 |
| 43 // The |job_response_data| holds information to build a response object to |
| 44 // return to the Mojo service. |
| 45 void set_job_response_data( |
| 46 std::unique_ptr<BackgroundFetchJobResponseData> job_response_data); |
| 47 BackgroundFetchJobResponseData* job_response_data() const { |
| 48 return job_response_data_.get(); |
| 49 } |
| 50 |
| 51 // The following methods are used to track currently in progress requests. |
| 52 void set_num_requests(size_t num_requests) { num_requests_ = num_requests; } |
| 53 size_t num_requests() const { return num_requests_; } |
| 54 bool IsComplete() const; |
| 55 bool HasRequestsRemaining() const; |
| 56 size_t next_request_index() const { return next_request_index_; } |
| 57 |
| 58 void AddActiveRequest(std::unique_ptr<BackgroundFetchRequestInfo> request); |
| 59 BackgroundFetchRequestInfo* GetActiveRequest( |
| 60 const std::string& request_guid) const; |
| 61 void RemoveActiveRequest(const std::string& request_guid); |
| 62 |
38 private: | 63 private: |
39 std::string guid_; | 64 std::string guid_; |
40 std::string tag_; | 65 std::string tag_; |
41 url::Origin origin_; | 66 url::Origin origin_; |
42 int64_t service_worker_registration_id_ = kInvalidServiceWorkerRegistrationId; | 67 int64_t service_worker_registration_id_ = kInvalidServiceWorkerRegistrationId; |
43 std::vector<std::string> request_guids_; | 68 std::vector<std::string> request_guids_; |
44 | 69 |
| 70 // Tracking information for currently executing requests. |
| 71 base::flat_set<std::unique_ptr<BackgroundFetchRequestInfo>> active_requests_; |
| 72 size_t num_requests_ = INT_MAX; |
| 73 size_t next_request_index_ = 0; |
| 74 |
45 // TODO(harkness): Other things this class should track: estimated download | 75 // TODO(harkness): Other things this class should track: estimated download |
46 // size, current download size, total number of files, number of complete | 76 // size, current download size, total number of files, number of complete |
47 // files, (possibly) data to show the notification, (possibly) list of in | 77 // files, (possibly) data to show the notification, (possibly) list of in |
48 // progress FetchRequests. | 78 // progress FetchRequests. |
49 | 79 |
| 80 // This value will be non-null only when the job is complete and the response |
| 81 // to the caller is being assembled. |
| 82 std::unique_ptr<BackgroundFetchJobResponseData> job_response_data_; |
| 83 |
50 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobInfo); | 84 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobInfo); |
51 }; | 85 }; |
52 | 86 |
53 } // namespace content | 87 } // namespace content |
54 | 88 |
55 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_INFO_H | 89 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_INFO_H |
OLD | NEW |