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()) | |
Marc Treib
2017/02/09 12:34:45
nit: braces please
gambard
2017/02/09 13:44:11
Done.
| |
83 source->GetResponseHeaders()->GetMimeType(&mime_type); | |
84 | |
80 std::string image_data; | 85 std::string image_data; |
81 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS) { | 86 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS) { |
82 source->GetResponseAsString(&image_data); | 87 source->GetResponseAsString(&image_data); |
83 } | 88 } |
84 request_iter->second->callback.Run(image_data); | 89 request_iter->second->callback.Run(image_data, mime_type); |
85 | 90 |
86 // Remove the finished request. | 91 // Remove the finished request. |
87 pending_requests_.erase(request_iter); | 92 pending_requests_.erase(request_iter); |
88 } | 93 } |
89 | 94 |
90 } // namespace image_fetcher | 95 } // namespace image_fetcher |
OLD | NEW |