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

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

Issue 2749283002: components/image_fetcher: Add a from_http_cache flag to RequestMetadata (Closed)
Patch Set: test Created 3 years, 9 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 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/image_data_fetcher.h" 5 #include "components/image_fetcher/image_data_fetcher.h"
6 6
7 #include "net/base/load_flags.h" 7 #include "net/base/load_flags.h"
8 #include "net/http/http_response_headers.h" 8 #include "net/http/http_response_headers.h"
9 #include "net/http/http_status_code.h" 9 #include "net/http/http_status_code.h"
10 #include "net/url_request/url_fetcher.h" 10 #include "net/url_request/url_fetcher.h"
11 #include "net/url_request/url_request.h"
12 #include "net/url_request/url_request_context_getter.h" 11 #include "net/url_request/url_request_context_getter.h"
13 #include "net/url_request/url_request_status.h" 12 #include "net/url_request/url_request_status.h"
14 #include "url/gurl.h" 13 #include "url/gurl.h"
15 14
16 using data_use_measurement::DataUseUserData; 15 using data_use_measurement::DataUseUserData;
17 16
18 namespace image_fetcher { 17 namespace image_fetcher {
19 18
20 // An active image URL fetcher request. The struct contains the related requests 19 // An active image URL fetcher request. The struct contains the related requests
21 // state. 20 // state.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 pending_requests_[request->url_fetcher.get()] = std::move(request); 74 pending_requests_[request->url_fetcher.get()] = std::move(request);
76 } 75 }
77 76
78 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { 77 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
79 auto request_iter = pending_requests_.find(source); 78 auto request_iter = pending_requests_.find(source);
80 DCHECK(request_iter != pending_requests_.end()); 79 DCHECK(request_iter != pending_requests_.end());
81 80
82 bool success = source->GetStatus().status() == net::URLRequestStatus::SUCCESS; 81 bool success = source->GetStatus().status() == net::URLRequestStatus::SUCCESS;
83 82
84 RequestMetadata metadata; 83 RequestMetadata metadata;
85 metadata.response_code = RESPONSE_CODE_INVALID;
86 if (success && source->GetResponseHeaders()) { 84 if (success && source->GetResponseHeaders()) {
87 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type); 85 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type);
88 metadata.response_code = source->GetResponseHeaders()->response_code(); 86 metadata.http_response_code = source->GetResponseHeaders()->response_code();
89 success &= (metadata.response_code == net::HTTP_OK); 87 success &= (metadata.http_response_code == net::HTTP_OK);
90 } 88 }
89 metadata.from_http_cache = source->WasCached();
91 90
92 std::string image_data; 91 std::string image_data;
93 if (success) { 92 if (success) {
94 source->GetResponseAsString(&image_data); 93 source->GetResponseAsString(&image_data);
95 } 94 }
96 request_iter->second->callback.Run(image_data, metadata); 95 request_iter->second->callback.Run(image_data, metadata);
97 96
98 // Remove the finished request. 97 // Remove the finished request.
99 pending_requests_.erase(request_iter); 98 pending_requests_.erase(request_iter);
100 } 99 }
101 100
102 } // namespace image_fetcher 101 } // namespace image_fetcher
OLDNEW
« no previous file with comments | « components/image_fetcher/image_data_fetcher.h ('k') | components/image_fetcher/image_data_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698