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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/background_fetch/background_fetch_request_info.cc
diff --git a/content/browser/background_fetch/background_fetch_request_info.cc b/content/browser/background_fetch/background_fetch_request_info.cc
index 0beb3c9fac044b63215ffb973912782b9bbe335a..e3f96083831dbd5b06a6323179c25d416028b65d 100644
--- a/content/browser/background_fetch/background_fetch_request_info.cc
+++ b/content/browser/background_fetch/background_fetch_request_info.cc
@@ -7,6 +7,7 @@
#include <string>
#include "content/public/browser/download_item.h"
+#include "net/http/http_response_headers.h"
namespace content {
@@ -25,6 +26,21 @@ void BackgroundFetchRequestInfo::PopulateDownloadState(
download_guid_ = download_item->GetGuid();
download_state_ = download_item->GetState();
+ // The response code, text and headers all are stored in the
+ // net::HttpResponseHeaders object, shared by the |download_item|.
+ if (download_item->GetResponseHeaders()) {
+ const auto& headers = download_item->GetResponseHeaders();
+
+ response_code_ = headers->response_code();
+ response_text_ = headers->GetStatusText();
+
+ size_t iter = 0;
+ std::string name, value;
+
+ while (headers->EnumerateHeaderLines(&iter, &name, &value))
+ response_headers_[name] = value;
+ }
+
download_state_populated_ = true;
}
@@ -36,11 +52,26 @@ void BackgroundFetchRequestInfo::PopulateResponseFromDownloadItem(
file_path_ = download_item->GetTargetFilePath();
file_size_ = download_item->GetReceivedBytes();
response_time_ = download_item->GetEndTime();
- response_type_ = download_item->GetMimeType();
response_data_populated_ = true;
}
+int BackgroundFetchRequestInfo::GetResponseCode() const {
+ DCHECK(download_state_populated_);
+ return response_code_;
+}
+
+const std::string& BackgroundFetchRequestInfo::GetResponseText() const {
+ DCHECK(download_state_populated_);
+ return response_text_;
+}
+
+const std::map<std::string, std::string>&
+BackgroundFetchRequestInfo::GetResponseHeaders() const {
+ DCHECK(download_state_populated_);
+ return response_headers_;
+}
+
const std::vector<GURL>& BackgroundFetchRequestInfo::GetURLChain() const {
DCHECK(response_data_populated_);
return url_chain_;
@@ -61,9 +92,4 @@ const base::Time& BackgroundFetchRequestInfo::GetResponseTime() const {
return response_time_;
}
-const std::string& BackgroundFetchRequestInfo::GetResponseType() const {
- DCHECK(response_data_populated_);
- return response_type_;
-}
-
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698