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

Side by Side Diff: chrome/browser/search/suggestions/image_fetcher_impl.cc

Issue 1974013002: Replace SkBitmap with gfx::Image in the ImageFetcher API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix iOS build errors. Created 4 years, 7 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 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"
11 #include "net/url_request/url_request_context_getter.h" 11 #include "net/url_request/url_request_context_getter.h"
12 #include "ui/gfx/image/image.h"
12 13
13 namespace suggestions { 14 namespace suggestions {
14 15
15 ImageFetcherImpl::ImageFetcherImpl( 16 ImageFetcherImpl::ImageFetcherImpl(
16 net::URLRequestContextGetter* url_request_context) 17 net::URLRequestContextGetter* url_request_context)
17 : delegate_(NULL), url_request_context_(url_request_context) {} 18 : delegate_(NULL), url_request_context_(url_request_context) {}
18 19
19 ImageFetcherImpl::~ImageFetcherImpl() {} 20 ImageFetcherImpl::~ImageFetcherImpl() {}
20 21
21 ImageFetcherImpl::ImageRequest::ImageRequest() : fetcher(NULL) {} 22 ImageFetcherImpl::ImageRequest::ImageRequest() : fetcher(NULL) {}
22 23
23 ImageFetcherImpl::ImageRequest::ImageRequest(chrome::BitmapFetcher* f) 24 ImageFetcherImpl::ImageRequest::ImageRequest(chrome::BitmapFetcher* f)
24 : fetcher(f) {} 25 : fetcher(f) {}
25 26
26 ImageFetcherImpl::ImageRequest::ImageRequest(const ImageRequest& other) = 27 ImageFetcherImpl::ImageRequest::ImageRequest(const ImageRequest& other) =
27 default; 28 default;
28 29
29 ImageFetcherImpl::ImageRequest::~ImageRequest() { delete fetcher; } 30 ImageFetcherImpl::ImageRequest::~ImageRequest() { delete fetcher; }
30 31
31 void ImageFetcherImpl::SetImageFetcherDelegate( 32 void ImageFetcherImpl::SetImageFetcherDelegate(
32 image_fetcher::ImageFetcherDelegate* delegate) { 33 image_fetcher::ImageFetcherDelegate* delegate) {
33 DCHECK(delegate); 34 DCHECK(delegate);
34 delegate_ = delegate; 35 delegate_ = delegate;
35 } 36 }
36 37
37 void ImageFetcherImpl::StartOrQueueNetworkRequest( 38 void ImageFetcherImpl::StartOrQueueNetworkRequest(
38 const GURL& url, const GURL& image_url, 39 const GURL& url, const GURL& image_url,
39 base::Callback<void(const GURL&, const SkBitmap*)> callback) { 40 base::Callback<void(const GURL&, const gfx::Image&)> callback) {
40 // Before starting to fetch the image. Look for a request in progress for 41 // Before starting to fetch the image. Look for a request in progress for
41 // |image_url|, and queue if appropriate. 42 // |image_url|, and queue if appropriate.
42 ImageRequestMap::iterator it = pending_net_requests_.find(image_url); 43 ImageRequestMap::iterator it = pending_net_requests_.find(image_url);
43 if (it == pending_net_requests_.end()) { 44 if (it == pending_net_requests_.end()) {
44 // |image_url| is not being fetched, so create a request and initiate 45 // |image_url| is not being fetched, so create a request and initiate
45 // the fetch. 46 // the fetch.
46 ImageRequest request(new chrome::BitmapFetcher(image_url, this)); 47 ImageRequest request(new chrome::BitmapFetcher(image_url, this));
47 request.url = url; 48 request.url = url;
48 request.callbacks.push_back(callback); 49 request.callbacks.push_back(callback);
49 request.fetcher->Init( 50 request.fetcher->Init(
(...skipping 13 matching lines...) Expand all
63 ImageRequestMap::iterator image_iter = pending_net_requests_.find(image_url); 64 ImageRequestMap::iterator image_iter = pending_net_requests_.find(image_url);
64 DCHECK(image_iter != pending_net_requests_.end()); 65 DCHECK(image_iter != pending_net_requests_.end());
65 66
66 ImageRequest* request = &image_iter->second; 67 ImageRequest* request = &image_iter->second;
67 68
68 // Here |bitmap| could be NULL or a pointer to a bitmap which is owned by the 69 // Here |bitmap| could be NULL or a pointer to a bitmap which is owned by the
69 // BitmapFetcher and which ceases to exist after this function. Pass the 70 // BitmapFetcher and which ceases to exist after this function. Pass the
70 // un-owned pointer to the registered callbacks. 71 // un-owned pointer to the registered callbacks.
71 for (CallbackVector::iterator callback_iter = request->callbacks.begin(); 72 for (CallbackVector::iterator callback_iter = request->callbacks.begin();
72 callback_iter != request->callbacks.end(); ++callback_iter) { 73 callback_iter != request->callbacks.end(); ++callback_iter) {
73 callback_iter->Run(request->url, bitmap); 74 gfx::Image image;
75 if (bitmap != NULL)
Marc Treib 2016/05/13 15:53:59 nit: s/NULL/nullptr
markusheintz_ 2016/05/17 13:08:22 Done.
76 image = gfx::Image::CreateFrom1xBitmap(*bitmap);
77 callback_iter->Run(request->url, image);
74 } 78 }
75 79
76 // Inform the ImageFetcherDelegate. 80 // Inform the ImageFetcherDelegate.
77 if (delegate_) { 81 if (delegate_) {
78 delegate_->OnImageFetched(request->url, bitmap); 82 gfx::Image image;
83 if (bitmap != NULL)
84 image = gfx::Image::CreateFrom1xBitmap(*bitmap);
85 delegate_->OnImageFetched(request->url, image);
79 } 86 }
80 87
81 // Erase the completed ImageRequest. 88 // Erase the completed ImageRequest.
82 pending_net_requests_.erase(image_iter); 89 pending_net_requests_.erase(image_iter);
83 } 90 }
84 91
85 } // namespace suggestions 92 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698