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

Side by Side Diff: components/image_fetcher/core/image_data_fetcher.cc

Issue 2807143002: [Image fetcher] Add Content-Location header to image_fetcher::RequestMetadata (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
« no previous file with comments | « no previous file | components/image_fetcher/core/image_data_fetcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/image_fetcher/core/image_data_fetcher.h" 5 #include "components/image_fetcher/core/image_data_fetcher.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "net/base/load_flags.h" 9 #include "net/base/load_flags.h"
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
11 #include "net/http/http_status_code.h" 11 #include "net/http/http_status_code.h"
12 #include "net/url_request/url_fetcher.h" 12 #include "net/url_request/url_fetcher.h"
13 #include "net/url_request/url_request_context_getter.h" 13 #include "net/url_request/url_request_context_getter.h"
14 #include "net/url_request/url_request_status.h" 14 #include "net/url_request/url_request_status.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 using data_use_measurement::DataUseUserData; 17 using data_use_measurement::DataUseUserData;
18 18
19 namespace {
20
21 const char kContentLocationHeader[] = "Content-Location";
22
23 } // namespace
24
19 namespace image_fetcher { 25 namespace image_fetcher {
20 26
21 // An active image URL fetcher request. The struct contains the related requests 27 // An active image URL fetcher request. The struct contains the related requests
22 // state. 28 // state.
23 struct ImageDataFetcher::ImageDataFetcherRequest { 29 struct ImageDataFetcher::ImageDataFetcherRequest {
24 ImageDataFetcherRequest(const ImageDataFetcherCallback& callback, 30 ImageDataFetcherRequest(const ImageDataFetcherCallback& callback,
25 std::unique_ptr<net::URLFetcher> url_fetcher) 31 std::unique_ptr<net::URLFetcher> url_fetcher)
26 : callback(callback), url_fetcher(std::move(url_fetcher)) {} 32 : callback(callback), url_fetcher(std::move(url_fetcher)) {}
27 33
28 ~ImageDataFetcherRequest() {} 34 ~ImageDataFetcherRequest() {}
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 88
83 pending_requests_[request->url_fetcher.get()] = std::move(request); 89 pending_requests_[request->url_fetcher.get()] = std::move(request);
84 } 90 }
85 91
86 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { 92 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
87 DCHECK(pending_requests_.find(source) != pending_requests_.end()); 93 DCHECK(pending_requests_.find(source) != pending_requests_.end());
88 bool success = source->GetStatus().status() == net::URLRequestStatus::SUCCESS; 94 bool success = source->GetStatus().status() == net::URLRequestStatus::SUCCESS;
89 95
90 RequestMetadata metadata; 96 RequestMetadata metadata;
91 if (success && source->GetResponseHeaders()) { 97 if (success && source->GetResponseHeaders()) {
92 metadata.http_response_headers = source->GetResponseHeaders();
93 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type); 98 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type);
94 metadata.http_response_code = source->GetResponseHeaders()->response_code(); 99 metadata.http_response_code = source->GetResponseHeaders()->response_code();
100 // Just read the first value-pair for this header (not caring about |iter|).
101 source->GetResponseHeaders()->EnumerateHeader(
102 /*iter=*/nullptr, kContentLocationHeader,
103 &metadata.content_location_header);
95 success &= (metadata.http_response_code == net::HTTP_OK); 104 success &= (metadata.http_response_code == net::HTTP_OK);
96 } 105 }
97 metadata.from_http_cache = source->WasCached(); 106 metadata.from_http_cache = source->WasCached();
98 107
99 std::string image_data; 108 std::string image_data;
100 if (success) { 109 if (success) {
101 source->GetResponseAsString(&image_data); 110 source->GetResponseAsString(&image_data);
102 } 111 }
103 FinishRequest(source, metadata, image_data); 112 FinishRequest(source, metadata, image_data);
104 } 113 }
(...skipping 21 matching lines...) Expand all
126 void ImageDataFetcher::FinishRequest(const net::URLFetcher* source, 135 void ImageDataFetcher::FinishRequest(const net::URLFetcher* source,
127 const RequestMetadata& metadata, 136 const RequestMetadata& metadata,
128 const std::string& image_data) { 137 const std::string& image_data) {
129 auto request_iter = pending_requests_.find(source); 138 auto request_iter = pending_requests_.find(source);
130 DCHECK(request_iter != pending_requests_.end()); 139 DCHECK(request_iter != pending_requests_.end());
131 request_iter->second->callback.Run(image_data, metadata); 140 request_iter->second->callback.Run(image_data, metadata);
132 pending_requests_.erase(request_iter); 141 pending_requests_.erase(request_iter);
133 } 142 }
134 143
135 } // namespace image_fetcher 144 } // namespace image_fetcher
OLDNEW
« no previous file with comments | « no previous file | components/image_fetcher/core/image_data_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698