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 "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/threading/sequenced_task_runner_handle.h" | |
11 #include "content/public/browser/browser_thread.h" | |
10 #include "content/public/browser/download_item.h" | 12 #include "content/public/browser/download_item.h" |
11 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
12 | 14 |
13 namespace content { | 15 namespace content { |
14 | 16 |
15 BackgroundFetchRequestInfo::BackgroundFetchRequestInfo( | 17 BackgroundFetchRequestInfo::BackgroundFetchRequestInfo( |
16 int request_index, | 18 int request_index, |
17 const ServiceWorkerFetchRequest& fetch_request) | 19 const ServiceWorkerFetchRequest& fetch_request) |
18 : request_index_(request_index), fetch_request_(fetch_request) {} | 20 : RefCountedDeleteOnSequence<BackgroundFetchRequestInfo>( |
21 base::SequencedTaskRunnerHandle::Get()), | |
Peter Beverloo
2017/07/10 13:13:21
Should we be more explicit and bind to BrowserThre
johnme
2017/07/10 13:41:07
No, we don't actually care what thread we're delet
| |
22 request_index_(request_index), | |
23 fetch_request_(fetch_request) {} | |
19 | 24 |
20 BackgroundFetchRequestInfo::~BackgroundFetchRequestInfo() {} | 25 BackgroundFetchRequestInfo::~BackgroundFetchRequestInfo() { |
26 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
27 } | |
21 | 28 |
22 void BackgroundFetchRequestInfo::PopulateDownloadState( | 29 void BackgroundFetchRequestInfo::PopulateDownloadStateOnUI( |
23 DownloadItem* download_item, | 30 DownloadItem* download_item, |
24 DownloadInterruptReason download_interrupt_reason) { | 31 DownloadInterruptReason download_interrupt_reason) { |
32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
25 DCHECK(!download_state_populated_); | 33 DCHECK(!download_state_populated_); |
26 | 34 |
27 download_guid_ = download_item->GetGuid(); | 35 download_guid_ = download_item->GetGuid(); |
28 download_state_ = download_item->GetState(); | 36 download_state_ = download_item->GetState(); |
29 | 37 |
30 // The response code, text and headers all are stored in the | 38 // The response code, text and headers all are stored in the |
31 // net::HttpResponseHeaders object, shared by the |download_item|. | 39 // net::HttpResponseHeaders object, shared by the |download_item|. |
32 if (download_item->GetResponseHeaders()) { | 40 if (download_item->GetResponseHeaders()) { |
33 const auto& headers = download_item->GetResponseHeaders(); | 41 const auto& headers = download_item->GetResponseHeaders(); |
34 | 42 |
35 response_code_ = headers->response_code(); | 43 response_code_ = headers->response_code(); |
36 response_text_ = headers->GetStatusText(); | 44 response_text_ = headers->GetStatusText(); |
37 | 45 |
38 size_t iter = 0; | 46 size_t iter = 0; |
39 std::string name, value; | 47 std::string name, value; |
40 | 48 |
41 while (headers->EnumerateHeaderLines(&iter, &name, &value)) | 49 while (headers->EnumerateHeaderLines(&iter, &name, &value)) |
42 response_headers_[base::ToLowerASCII(name)] = value; | 50 response_headers_[base::ToLowerASCII(name)] = value; |
43 } | 51 } |
52 } | |
44 | 53 |
54 void BackgroundFetchRequestInfo::SetDownloadStatePopulated() { | |
55 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
Peter Beverloo
2017/07/10 13:13:21
ugh. noise. so glad that we'll be able to get rid
johnme
2017/07/10 13:41:07
Acknowledged.
| |
45 download_state_populated_ = true; | 56 download_state_populated_ = true; |
46 } | 57 } |
47 | 58 |
48 void BackgroundFetchRequestInfo::PopulateResponseFromDownloadItem( | 59 void BackgroundFetchRequestInfo::PopulateResponseFromDownloadItemOnUI( |
49 DownloadItem* download_item) { | 60 DownloadItem* download_item) { |
61 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
50 DCHECK(!response_data_populated_); | 62 DCHECK(!response_data_populated_); |
51 | 63 |
52 url_chain_ = download_item->GetUrlChain(); | 64 url_chain_ = download_item->GetUrlChain(); |
53 file_path_ = download_item->GetTargetFilePath(); | 65 file_path_ = download_item->GetTargetFilePath(); |
54 file_size_ = download_item->GetReceivedBytes(); | 66 file_size_ = download_item->GetReceivedBytes(); |
55 response_time_ = download_item->GetEndTime(); | 67 response_time_ = download_item->GetEndTime(); |
68 } | |
56 | 69 |
70 void BackgroundFetchRequestInfo::SetResponseDataPopulated() { | |
71 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
57 response_data_populated_ = true; | 72 response_data_populated_ = true; |
58 } | 73 } |
59 | 74 |
60 int BackgroundFetchRequestInfo::GetResponseCode() const { | 75 int BackgroundFetchRequestInfo::GetResponseCode() const { |
76 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
61 DCHECK(download_state_populated_); | 77 DCHECK(download_state_populated_); |
62 return response_code_; | 78 return response_code_; |
63 } | 79 } |
64 | 80 |
65 const std::string& BackgroundFetchRequestInfo::GetResponseText() const { | 81 const std::string& BackgroundFetchRequestInfo::GetResponseText() const { |
82 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
66 DCHECK(download_state_populated_); | 83 DCHECK(download_state_populated_); |
67 return response_text_; | 84 return response_text_; |
68 } | 85 } |
69 | 86 |
70 const std::map<std::string, std::string>& | 87 const std::map<std::string, std::string>& |
71 BackgroundFetchRequestInfo::GetResponseHeaders() const { | 88 BackgroundFetchRequestInfo::GetResponseHeaders() const { |
89 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
72 DCHECK(download_state_populated_); | 90 DCHECK(download_state_populated_); |
73 return response_headers_; | 91 return response_headers_; |
74 } | 92 } |
75 | 93 |
76 const std::vector<GURL>& BackgroundFetchRequestInfo::GetURLChain() const { | 94 const std::vector<GURL>& BackgroundFetchRequestInfo::GetURLChain() const { |
95 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
77 DCHECK(response_data_populated_); | 96 DCHECK(response_data_populated_); |
78 return url_chain_; | 97 return url_chain_; |
79 } | 98 } |
80 | 99 |
81 const base::FilePath& BackgroundFetchRequestInfo::GetFilePath() const { | 100 const base::FilePath& BackgroundFetchRequestInfo::GetFilePath() const { |
101 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
82 DCHECK(response_data_populated_); | 102 DCHECK(response_data_populated_); |
83 return file_path_; | 103 return file_path_; |
84 } | 104 } |
85 | 105 |
86 int64_t BackgroundFetchRequestInfo::GetFileSize() const { | 106 int64_t BackgroundFetchRequestInfo::GetFileSize() const { |
107 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
87 DCHECK(response_data_populated_); | 108 DCHECK(response_data_populated_); |
88 return file_size_; | 109 return file_size_; |
89 } | 110 } |
90 | 111 |
91 const base::Time& BackgroundFetchRequestInfo::GetResponseTime() const { | 112 const base::Time& BackgroundFetchRequestInfo::GetResponseTime() const { |
113 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | |
92 DCHECK(response_data_populated_); | 114 DCHECK(response_data_populated_); |
93 return response_time_; | 115 return response_time_; |
94 } | 116 } |
95 | 117 |
96 } // namespace content | 118 } // namespace content |
OLD | NEW |