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 #include "content/browser/background_fetch/background_fetch_job_info.h" | 5 #include "content/browser/background_fetch/background_fetch_job_info.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 | 8 |
| 9 #include "content/browser/background_fetch/background_fetch_job_response_data.h" |
| 10 #include "content/browser/background_fetch/background_fetch_request_info.h" |
| 11 |
9 namespace content { | 12 namespace content { |
10 | 13 |
11 BackgroundFetchJobInfo::BackgroundFetchJobInfo( | 14 BackgroundFetchJobInfo::BackgroundFetchJobInfo( |
12 const std::string& tag, | 15 const std::string& tag, |
13 const url::Origin& origin, | 16 const url::Origin& origin, |
14 int64_t service_worker_registration_id) | 17 int64_t service_worker_registration_id) |
15 : guid_(base::GenerateGUID()), | 18 : guid_(base::GenerateGUID()), |
16 tag_(tag), | 19 tag_(tag), |
17 origin_(origin), | 20 origin_(origin), |
18 service_worker_registration_id_(service_worker_registration_id) {} | 21 service_worker_registration_id_(service_worker_registration_id) {} |
19 | 22 |
20 BackgroundFetchJobInfo::~BackgroundFetchJobInfo() = default; | 23 BackgroundFetchJobInfo::~BackgroundFetchJobInfo() = default; |
21 | 24 |
| 25 void BackgroundFetchJobInfo::set_job_response_data( |
| 26 std::unique_ptr<BackgroundFetchJobResponseData> job_response_data) { |
| 27 job_response_data_ = std::move(job_response_data); |
| 28 } |
| 29 |
| 30 bool BackgroundFetchJobInfo::IsComplete() const { |
| 31 return !HasRequestsRemaining() && active_requests_.empty(); |
| 32 } |
| 33 |
| 34 bool BackgroundFetchJobInfo::HasRequestsRemaining() const { |
| 35 return next_request_index_ != num_requests_; |
| 36 } |
| 37 |
| 38 void BackgroundFetchJobInfo::AddActiveRequest( |
| 39 std::unique_ptr<BackgroundFetchRequestInfo> request) { |
| 40 active_requests_.insert(std::move(request)); |
| 41 next_request_index_++; |
| 42 } |
| 43 |
| 44 BackgroundFetchRequestInfo* BackgroundFetchJobInfo::GetActiveRequest( |
| 45 const std::string& request_guid) const { |
| 46 for (auto& request : active_requests_) { |
| 47 if (request->guid() == request_guid) |
| 48 return request.get(); |
| 49 } |
| 50 return nullptr; |
| 51 } |
| 52 |
| 53 void BackgroundFetchJobInfo::RemoveActiveRequest( |
| 54 const std::string& request_guid) { |
| 55 // active_requests_.erase(request_guid); |
| 56 for (const auto& request : active_requests_) { |
| 57 if (request->guid() == request_guid) { |
| 58 active_requests_.erase(request); |
| 59 return; |
| 60 } |
| 61 } |
| 62 } |
| 63 |
22 } // namespace content | 64 } // namespace content |
OLD | NEW |