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

Side by Side Diff: chrome/browser/search/thumbnail_source.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: Sync again 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
« no previous file with comments | « chrome/browser/search/thumbnail_source.h ('k') | components/image_fetcher/image_fetcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/thumbnail_source.h" 5 #include "chrome/browser/search/thumbnail_source.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search/instant_io_context.h" 13 #include "chrome/browser/search/instant_io_context.h"
14 #include "chrome/browser/search/suggestions/image_fetcher_impl.h" 14 #include "chrome/browser/search/suggestions/image_fetcher_impl.h"
15 #include "chrome/browser/thumbnails/thumbnail_service.h" 15 #include "chrome/browser/thumbnails/thumbnail_service.h"
16 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" 16 #include "chrome/browser/thumbnails/thumbnail_service_factory.h"
17 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
18 #include "components/suggestions/image_encoder.h" 18 #include "components/suggestions/image_encoder.h"
19 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
20 #include "ui/gfx/image/image.h"
20 #include "ui/gfx/image/image_skia.h" 21 #include "ui/gfx/image/image_skia.h"
21 22
22 // The delimiter between the first url and the fallback url passed to 23 // The delimiter between the first url and the fallback url passed to
23 // StartDataRequest. 24 // StartDataRequest.
24 const char kUrlDelimiter[] = "?fb="; 25 const char kUrlDelimiter[] = "?fb=";
25 26
26 // Set ThumbnailService now as Profile isn't thread safe. 27 // Set ThumbnailService now as Profile isn't thread safe.
27 ThumbnailSource::ThumbnailSource(Profile* profile, bool capture_thumbnails) 28 ThumbnailSource::ThumbnailSource(Profile* profile, bool capture_thumbnails)
28 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), 29 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)),
29 capture_thumbnails_(capture_thumbnails), 30 capture_thumbnails_(capture_thumbnails),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // We need to explicitly return a mime type, otherwise if the user tries to 74 // We need to explicitly return a mime type, otherwise if the user tries to
74 // drag the image they get no extension. 75 // drag the image they get no extension.
75 return "image/png"; 76 return "image/png";
76 } 77 }
77 78
78 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath( 79 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath(
79 const std::string& path) const { 80 const std::string& path) const {
80 // TopSites can be accessed from the IO thread. Otherwise, the URLs should be 81 // TopSites can be accessed from the IO thread. Otherwise, the URLs should be
81 // accessed on the UI thread. 82 // accessed on the UI thread.
82 return thumbnail_service_.get() 83 return thumbnail_service_.get()
83 ? NULL 84 ? nullptr
84 : content::URLDataSource::MessageLoopForRequestPath(path); 85 : content::URLDataSource::MessageLoopForRequestPath(path);
85 } 86 }
86 87
87 bool ThumbnailSource::ShouldServiceRequest( 88 bool ThumbnailSource::ShouldServiceRequest(
88 const net::URLRequest* request) const { 89 const net::URLRequest* request) const {
89 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) 90 if (request->url().SchemeIs(chrome::kChromeSearchScheme))
90 return InstantIOContext::ShouldServiceRequest(request); 91 return InstantIOContext::ShouldServiceRequest(request);
91 return URLDataSource::ShouldServiceRequest(request); 92 return URLDataSource::ShouldServiceRequest(request);
92 } 93 }
93 94
(...skipping 10 matching lines...) Expand all
104 fallback_thumbnail_url_str = path.substr(pos + strlen(kUrlDelimiter)); 105 fallback_thumbnail_url_str = path.substr(pos + strlen(kUrlDelimiter));
105 } 106 }
106 107
107 *page_url = GURL(page_url_str); 108 *page_url = GURL(page_url_str);
108 *fallback_thumbnail_url = GURL(fallback_thumbnail_url_str); 109 *fallback_thumbnail_url = GURL(fallback_thumbnail_url_str);
109 } 110 }
110 111
111 void ThumbnailSource::SendFetchedUrlImage( 112 void ThumbnailSource::SendFetchedUrlImage(
112 const content::URLDataSource::GotDataCallback& callback, 113 const content::URLDataSource::GotDataCallback& callback,
113 const GURL& url, 114 const GURL& url,
114 const SkBitmap* bitmap) { 115 const gfx::Image& image) {
115 if (!bitmap) { 116 // In case the image could not be retrieved an empty image is returned.
117 if (image.IsEmpty()) {
116 callback.Run(default_thumbnail_.get()); 118 callback.Run(default_thumbnail_.get());
117 return; 119 return;
118 } 120 }
119 121
122 const SkBitmap* bitmap = image.ToSkBitmap();
120 scoped_refptr<base::RefCountedBytes> encoded_data( 123 scoped_refptr<base::RefCountedBytes> encoded_data(
121 new base::RefCountedBytes()); 124 new base::RefCountedBytes());
122 if (!suggestions::EncodeSkBitmapToJPEG(*bitmap, &encoded_data->data())) { 125 if (!suggestions::EncodeSkBitmapToJPEG(*bitmap, &encoded_data->data())) {
123 callback.Run(default_thumbnail_.get()); 126 callback.Run(default_thumbnail_.get());
124 return; 127 return;
125 } 128 }
126 129
127 callback.Run(encoded_data.get()); 130 callback.Run(encoded_data.get());
128 } 131 }
OLDNEW
« no previous file with comments | « chrome/browser/search/thumbnail_source.h ('k') | components/image_fetcher/image_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698