| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 net::LOAD_NORMAL); | 48 net::LOAD_NORMAL); |
| 49 pending_net_requests_[image_url].swap(&request); | 49 pending_net_requests_[image_url].swap(&request); |
| 50 } else { | 50 } else { |
| 51 // Request in progress. Register as an interested callback. | 51 // Request in progress. Register as an interested callback. |
| 52 it->second.callbacks.push_back(callback); | 52 it->second.callbacks.push_back(callback); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ImageFetcherImpl::OnFetchComplete(const GURL& image_url, | 56 void ImageFetcherImpl::OnFetchComplete(const GURL& image_url, |
| 57 const SkBitmap* bitmap) { | 57 const SkBitmap* bitmap) { |
| 58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 59 | 59 |
| 60 ImageRequestMap::iterator image_iter = pending_net_requests_.find(image_url); | 60 ImageRequestMap::iterator image_iter = pending_net_requests_.find(image_url); |
| 61 DCHECK(image_iter != pending_net_requests_.end()); | 61 DCHECK(image_iter != pending_net_requests_.end()); |
| 62 | 62 |
| 63 ImageRequest* request = &image_iter->second; | 63 ImageRequest* request = &image_iter->second; |
| 64 | 64 |
| 65 // Here |bitmap| could be NULL or a pointer to a bitmap which is owned by the | 65 // Here |bitmap| could be NULL or a pointer to a bitmap which is owned by the |
| 66 // BitmapFetcher and which ceases to exist after this function. Pass the | 66 // BitmapFetcher and which ceases to exist after this function. Pass the |
| 67 // un-owned pointer to the registered callbacks. | 67 // un-owned pointer to the registered callbacks. |
| 68 for (CallbackVector::iterator callback_iter = request->callbacks.begin(); | 68 for (CallbackVector::iterator callback_iter = request->callbacks.begin(); |
| 69 callback_iter != request->callbacks.end(); ++callback_iter) { | 69 callback_iter != request->callbacks.end(); ++callback_iter) { |
| 70 callback_iter->Run(request->url, bitmap); | 70 callback_iter->Run(request->url, bitmap); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Inform the ImageFetcherDelegate. | 73 // Inform the ImageFetcherDelegate. |
| 74 if (delegate_) { | 74 if (delegate_) { |
| 75 delegate_->OnImageFetched(request->url, bitmap); | 75 delegate_->OnImageFetched(request->url, bitmap); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Erase the completed ImageRequest. | 78 // Erase the completed ImageRequest. |
| 79 pending_net_requests_.erase(image_iter); | 79 pending_net_requests_.erase(image_iter); |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace suggestions | 82 } // namespace suggestions |
| OLD | NEW |