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_request_info.h" | 5 #include "content/browser/background_fetch/background_fetch_request_info.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "content/public/browser/download_item.h" | 9 #include "content/public/browser/download_item.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 BackgroundFetchRequestInfo::BackgroundFetchRequestInfo( | 13 BackgroundFetchRequestInfo::BackgroundFetchRequestInfo( |
14 int request_index, | 14 int request_index, |
15 const ServiceWorkerFetchRequest& fetch_request) | 15 const ServiceWorkerFetchRequest& fetch_request) |
16 : request_index_(request_index), fetch_request_(fetch_request) {} | 16 : request_index_(request_index), fetch_request_(fetch_request) {} |
17 | 17 |
18 BackgroundFetchRequestInfo::~BackgroundFetchRequestInfo() {} | 18 BackgroundFetchRequestInfo::~BackgroundFetchRequestInfo() {} |
19 | 19 |
20 bool BackgroundFetchRequestInfo::IsComplete() const { | 20 void BackgroundFetchRequestInfo::PopulateDownloadState( |
21 return (state_ == DownloadItem::DownloadState::COMPLETE || | 21 DownloadItem* download_item, |
22 state_ == DownloadItem::DownloadState::CANCELLED); | 22 DownloadInterruptReason download_interrupt_reason) { |
| 23 DCHECK(!download_state_populated_); |
| 24 |
| 25 download_guid_ = download_item->GetGuid(); |
| 26 download_state_ = download_item->GetState(); |
| 27 |
| 28 download_state_populated_ = true; |
23 } | 29 } |
24 | 30 |
25 const GURL& BackgroundFetchRequestInfo::GetURL() const { | 31 void BackgroundFetchRequestInfo::PopulateResponseFromDownloadItem( |
26 return fetch_request_.url; | 32 DownloadItem* download_item) { |
| 33 DCHECK(!response_data_populated_); |
| 34 |
| 35 url_chain_ = download_item->GetUrlChain(); |
| 36 file_path_ = download_item->GetTargetFilePath(); |
| 37 file_size_ = download_item->GetReceivedBytes(); |
| 38 response_time_ = download_item->GetEndTime(); |
| 39 |
| 40 response_data_populated_ = true; |
| 41 } |
| 42 |
| 43 const std::vector<GURL>& BackgroundFetchRequestInfo::GetURLChain() const { |
| 44 DCHECK(response_data_populated_); |
| 45 return url_chain_; |
| 46 } |
| 47 |
| 48 const base::FilePath& BackgroundFetchRequestInfo::GetFilePath() const { |
| 49 DCHECK(response_data_populated_); |
| 50 return file_path_; |
| 51 } |
| 52 |
| 53 int64_t BackgroundFetchRequestInfo::GetFileSize() const { |
| 54 DCHECK(response_data_populated_); |
| 55 return file_size_; |
| 56 } |
| 57 |
| 58 const base::Time& BackgroundFetchRequestInfo::GetResponseTime() const { |
| 59 DCHECK(response_data_populated_); |
| 60 return response_time_; |
27 } | 61 } |
28 | 62 |
29 } // namespace content | 63 } // namespace content |
OLD | NEW |