| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/search/suggestions/image_fetcher_impl.h" | 5 #include "chrome/browser/search/suggestions/image_fetcher_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 base::Callback<void(const GURL&, const SkBitmap*)> callback) { | 35 base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
| 36 // Before starting to fetch the image. Look for a request in progress for | 36 // Before starting to fetch the image. Look for a request in progress for |
| 37 // |image_url|, and queue if appropriate. | 37 // |image_url|, and queue if appropriate. |
| 38 ImageRequestMap::iterator it = pending_net_requests_.find(image_url); | 38 ImageRequestMap::iterator it = pending_net_requests_.find(image_url); |
| 39 if (it == pending_net_requests_.end()) { | 39 if (it == pending_net_requests_.end()) { |
| 40 // |image_url| is not being fetched, so create a request and initiate | 40 // |image_url| is not being fetched, so create a request and initiate |
| 41 // the fetch. | 41 // the fetch. |
| 42 ImageRequest request(new chrome::BitmapFetcher(image_url, this)); | 42 ImageRequest request(new chrome::BitmapFetcher(image_url, this)); |
| 43 request.url = url; | 43 request.url = url; |
| 44 request.callbacks.push_back(callback); | 44 request.callbacks.push_back(callback); |
| 45 request.fetcher->Start( | 45 request.fetcher->Init( |
| 46 url_request_context_, std::string(), | 46 url_request_context_, std::string(), |
| 47 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 47 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 48 net::LOAD_NORMAL); | 48 net::LOAD_NORMAL); |
| 49 request.fetcher->Start(); |
| 49 pending_net_requests_[image_url].swap(&request); | 50 pending_net_requests_[image_url].swap(&request); |
| 50 } else { | 51 } else { |
| 51 // Request in progress. Register as an interested callback. | 52 // Request in progress. Register as an interested callback. |
| 52 it->second.callbacks.push_back(callback); | 53 it->second.callbacks.push_back(callback); |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 | 56 |
| 56 void ImageFetcherImpl::OnFetchComplete(const GURL& image_url, | 57 void ImageFetcherImpl::OnFetchComplete(const GURL& image_url, |
| 57 const SkBitmap* bitmap) { | 58 const SkBitmap* bitmap) { |
| 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 // Inform the ImageFetcherDelegate. | 74 // Inform the ImageFetcherDelegate. |
| 74 if (delegate_) { | 75 if (delegate_) { |
| 75 delegate_->OnImageFetched(request->url, bitmap); | 76 delegate_->OnImageFetched(request->url, bitmap); |
| 76 } | 77 } |
| 77 | 78 |
| 78 // Erase the completed ImageRequest. | 79 // Erase the completed ImageRequest. |
| 79 pending_net_requests_.erase(image_iter); | 80 pending_net_requests_.erase(image_iter); |
| 80 } | 81 } |
| 81 | 82 |
| 82 } // namespace suggestions | 83 } // namespace suggestions |
| OLD | NEW |