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 #include "content/browser/background_fetch/background_fetch_job_data.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "content/browser/background_fetch/background_fetch_job_info.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 BackgroundFetchJobData::BackgroundFetchJobData( |
| 13 BackgroundFetchRequestInfos request_infos) |
| 14 : request_infos_(std::move(request_infos)) {} |
| 15 |
| 16 BackgroundFetchJobData::~BackgroundFetchJobData() {} |
| 17 |
| 18 // TODO(harkness): Provide more detail about status and where the returned data |
| 19 // is now available. |
| 20 bool BackgroundFetchJobData::BackgroundFetchRequestInfoComplete( |
| 21 const std::string& fetch_guid) { |
| 22 // Make sure that the request was expected to be in-progress. |
| 23 auto index_iter = request_info_index_.find(fetch_guid); |
| 24 DCHECK(index_iter != request_info_index_.end()); |
| 25 DCHECK_EQ(fetch_guid, request_infos_[index_iter->second].guid()); |
| 26 |
| 27 // Set the request as complete and delete it from the in-progress index. |
| 28 request_infos_[index_iter->second].set_complete(true); |
| 29 request_info_index_.erase(index_iter); |
| 30 |
| 31 // Return a boolean indicating whether there are more requests to be |
| 32 // processed. |
| 33 return next_request_info_ != request_infos_.size(); |
| 34 } |
| 35 |
| 36 const BackgroundFetchRequestInfo& |
| 37 BackgroundFetchJobData::GetNextBackgroundFetchRequestInfo() { |
| 38 DCHECK(next_request_info_ != request_infos_.size()); |
| 39 |
| 40 const BackgroundFetchRequestInfo& next_request = |
| 41 request_infos_[next_request_info_]; |
| 42 DCHECK(!next_request.complete()); |
| 43 request_info_index_[next_request.guid()] = next_request_info_++; |
| 44 |
| 45 return next_request; |
| 46 } |
| 47 |
| 48 bool BackgroundFetchJobData::IsComplete() const { |
| 49 return ((next_request_info_ == request_infos_.size()) && |
| 50 request_info_index_.empty()); |
| 51 } |
| 52 |
| 53 bool BackgroundFetchJobData::HasRequestsRemaining() const { |
| 54 return next_request_info_ != request_infos_.size(); |
| 55 } |
| 56 |
| 57 } // namespace content |
OLD | NEW |