Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/url_request/url_fetcher.h" | 9 #include "net/url_request/url_fetcher.h" |
| 9 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
| 10 #include "net/url_request/url_request_context_getter.h" | 11 #include "net/url_request/url_request_context_getter.h" |
| 11 #include "net/url_request/url_request_status.h" | 12 #include "net/url_request/url_request_status.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 using data_use_measurement::DataUseUserData; | 15 using data_use_measurement::DataUseUserData; |
| 15 | 16 |
| 16 namespace image_fetcher { | 17 namespace image_fetcher { |
| 17 | 18 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 request->url_fetcher->SetReferrerPolicy(referrer_policy); | 71 request->url_fetcher->SetReferrerPolicy(referrer_policy); |
| 71 request->url_fetcher->Start(); | 72 request->url_fetcher->Start(); |
| 72 | 73 |
| 73 pending_requests_[request->url_fetcher.get()] = std::move(request); | 74 pending_requests_[request->url_fetcher.get()] = std::move(request); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 77 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| 77 auto request_iter = pending_requests_.find(source); | 78 auto request_iter = pending_requests_.find(source); |
| 78 DCHECK(request_iter != pending_requests_.end()); | 79 DCHECK(request_iter != pending_requests_.end()); |
| 79 | 80 |
| 81 std::string mime_type; | |
| 82 if (source->GetResponseHeaders()) { | |
| 83 source->GetResponseHeaders()->GetMimeType(&mime_type); | |
|
Marc Treib
2017/02/09 13:49:47
You could read directly into &metadata.mime_type
gambard
2017/02/09 15:10:32
Done.
| |
| 84 } | |
| 85 | |
| 86 RequestMetadata metadata; | |
| 87 metadata.mime_type = mime_type; | |
| 88 | |
| 80 std::string image_data; | 89 std::string image_data; |
| 81 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS) { | 90 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS) { |
| 82 source->GetResponseAsString(&image_data); | 91 source->GetResponseAsString(&image_data); |
| 83 } | 92 } |
| 84 request_iter->second->callback.Run(image_data); | 93 request_iter->second->callback.Run(image_data, metadata); |
| 85 | 94 |
| 86 // Remove the finished request. | 95 // Remove the finished request. |
| 87 pending_requests_.erase(request_iter); | 96 pending_requests_.erase(request_iter); |
| 88 } | 97 } |
| 89 | 98 |
| 90 } // namespace image_fetcher | 99 } // namespace image_fetcher |
| OLD | NEW |