Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: content/browser/background_fetch/background_fetch_request_info.cc

Issue 2814683003: Pass through the response code and headers in Background Fetch (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "net/http/http_response_headers.h"
10 11
11 namespace content { 12 namespace content {
12 13
13 BackgroundFetchRequestInfo::BackgroundFetchRequestInfo( 14 BackgroundFetchRequestInfo::BackgroundFetchRequestInfo(
14 int request_index, 15 int request_index,
15 const ServiceWorkerFetchRequest& fetch_request) 16 const ServiceWorkerFetchRequest& fetch_request)
16 : request_index_(request_index), fetch_request_(fetch_request) {} 17 : request_index_(request_index), fetch_request_(fetch_request) {}
17 18
18 BackgroundFetchRequestInfo::~BackgroundFetchRequestInfo() {} 19 BackgroundFetchRequestInfo::~BackgroundFetchRequestInfo() {}
19 20
20 void BackgroundFetchRequestInfo::PopulateDownloadState( 21 void BackgroundFetchRequestInfo::PopulateDownloadState(
21 DownloadItem* download_item, 22 DownloadItem* download_item,
22 DownloadInterruptReason download_interrupt_reason) { 23 DownloadInterruptReason download_interrupt_reason) {
23 DCHECK(!download_state_populated_); 24 DCHECK(!download_state_populated_);
24 25
25 download_guid_ = download_item->GetGuid(); 26 download_guid_ = download_item->GetGuid();
26 download_state_ = download_item->GetState(); 27 download_state_ = download_item->GetState();
27 28
29 // The response code, text and headers all are stored in the
30 // net::HttpResponseHeaders object, shared by the |download_item|.
31 if (download_item->GetResponseHeaders()) {
32 const auto& headers = download_item->GetResponseHeaders();
33
34 response_code_ = headers->response_code();
35 response_text_ = headers->GetStatusText();
36
37 size_t iter = 0;
38 std::string name, value;
39
40 while (headers->EnumerateHeaderLines(&iter, &name, &value))
41 response_headers_[name] = value;
42 }
43
28 download_state_populated_ = true; 44 download_state_populated_ = true;
29 } 45 }
30 46
31 void BackgroundFetchRequestInfo::PopulateResponseFromDownloadItem( 47 void BackgroundFetchRequestInfo::PopulateResponseFromDownloadItem(
32 DownloadItem* download_item) { 48 DownloadItem* download_item) {
33 DCHECK(!response_data_populated_); 49 DCHECK(!response_data_populated_);
34 50
35 url_chain_ = download_item->GetUrlChain(); 51 url_chain_ = download_item->GetUrlChain();
36 file_path_ = download_item->GetTargetFilePath(); 52 file_path_ = download_item->GetTargetFilePath();
37 file_size_ = download_item->GetReceivedBytes(); 53 file_size_ = download_item->GetReceivedBytes();
38 response_time_ = download_item->GetEndTime(); 54 response_time_ = download_item->GetEndTime();
39 response_type_ = download_item->GetMimeType();
40 55
41 response_data_populated_ = true; 56 response_data_populated_ = true;
42 } 57 }
43 58
59 int BackgroundFetchRequestInfo::GetResponseCode() const {
60 DCHECK(download_state_populated_);
61 return response_code_;
62 }
63
64 const std::string& BackgroundFetchRequestInfo::GetResponseText() const {
65 DCHECK(download_state_populated_);
66 return response_text_;
67 }
68
69 const std::map<std::string, std::string>&
70 BackgroundFetchRequestInfo::GetResponseHeaders() const {
71 DCHECK(download_state_populated_);
72 return response_headers_;
73 }
74
44 const std::vector<GURL>& BackgroundFetchRequestInfo::GetURLChain() const { 75 const std::vector<GURL>& BackgroundFetchRequestInfo::GetURLChain() const {
45 DCHECK(response_data_populated_); 76 DCHECK(response_data_populated_);
46 return url_chain_; 77 return url_chain_;
47 } 78 }
48 79
49 const base::FilePath& BackgroundFetchRequestInfo::GetFilePath() const { 80 const base::FilePath& BackgroundFetchRequestInfo::GetFilePath() const {
50 DCHECK(response_data_populated_); 81 DCHECK(response_data_populated_);
51 return file_path_; 82 return file_path_;
52 } 83 }
53 84
54 int64_t BackgroundFetchRequestInfo::GetFileSize() const { 85 int64_t BackgroundFetchRequestInfo::GetFileSize() const {
55 DCHECK(response_data_populated_); 86 DCHECK(response_data_populated_);
56 return file_size_; 87 return file_size_;
57 } 88 }
58 89
59 const base::Time& BackgroundFetchRequestInfo::GetResponseTime() const { 90 const base::Time& BackgroundFetchRequestInfo::GetResponseTime() const {
60 DCHECK(response_data_populated_); 91 DCHECK(response_data_populated_);
61 return response_time_; 92 return response_time_;
62 } 93 }
63 94
64 const std::string& BackgroundFetchRequestInfo::GetResponseType() const {
65 DCHECK(response_data_populated_);
66 return response_type_;
67 }
68
69 } // namespace content 95 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698