OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_INFO_H | |
6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_INFO_H | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/containers/flat_set.h" | |
13 #include "base/macros.h" | |
14 #include "content/common/content_export.h" | |
15 #include "content/common/service_worker/service_worker_types.h" | |
16 #include "url/origin.h" | |
17 | |
18 namespace content { | |
19 | |
20 class BackgroundFetchJobResponseData; | |
21 class BackgroundFetchRequestInfo; | |
22 | |
23 // Class to encapsulate a batch of FetchRequests into a single grouping which is | |
24 // what the developer requested. | |
25 class CONTENT_EXPORT BackgroundFetchJobInfo { | |
26 public: | |
27 BackgroundFetchJobInfo(const std::string& tag, | |
28 const url::Origin& origin, | |
29 int64_t service_worker_registration_id); | |
30 ~BackgroundFetchJobInfo(); | |
31 | |
32 const std::string& guid() const { return guid_; } | |
33 const std::string& tag() const { return tag_; } | |
34 const url::Origin& origin() const { return origin_; } | |
35 int64_t service_worker_registration_id() const { | |
36 return service_worker_registration_id_; | |
37 } | |
38 | |
39 const std::vector<std::string>& request_guids() const { | |
40 return request_guids_; | |
41 } | |
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 | |
63 private: | |
64 std::string guid_; | |
65 std::string tag_; | |
66 url::Origin origin_; | |
67 int64_t service_worker_registration_id_ = kInvalidServiceWorkerRegistrationId; | |
68 std::vector<std::string> request_guids_; | |
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 | |
75 // TODO(harkness): Other things this class should track: estimated download | |
76 // size, current download size, total number of files, number of complete | |
77 // files, (possibly) data to show the notification, (possibly) list of in | |
78 // progress FetchRequests. | |
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 | |
84 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobInfo); | |
85 }; | |
86 | |
87 } // namespace content | |
88 | |
89 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_JOB_INFO_H | |
OLD | NEW |