OLD | NEW |
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/ptr_util.h" |
10 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/search/instant_io_context.h" | 14 #include "chrome/browser/search/instant_io_context.h" |
14 #include "chrome/browser/search/suggestions/image_fetcher_impl.h" | 15 #include "chrome/browser/search/suggestions/image_decoder_impl.h" |
15 #include "chrome/browser/thumbnails/thumbnail_service.h" | 16 #include "chrome/browser/thumbnails/thumbnail_service.h" |
16 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" | 17 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" |
17 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "components/image_fetcher/image_fetcher_impl.h" |
18 #include "components/suggestions/image_encoder.h" | 20 #include "components/suggestions/image_encoder.h" |
19 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
20 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
21 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
22 | 24 |
23 // The delimiter between the first url and the fallback url passed to | 25 // The delimiter between the first url and the fallback url passed to |
24 // StartDataRequest. | 26 // StartDataRequest. |
25 const char kUrlDelimiter[] = "?fb="; | 27 const char kUrlDelimiter[] = "?fb="; |
26 | 28 |
27 // Set ThumbnailService now as Profile isn't thread safe. | 29 // Set ThumbnailService now as Profile isn't thread safe. |
28 ThumbnailSource::ThumbnailSource(Profile* profile, bool capture_thumbnails) | 30 ThumbnailSource::ThumbnailSource(Profile* profile, bool capture_thumbnails) |
29 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), | 31 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), |
30 capture_thumbnails_(capture_thumbnails), | 32 capture_thumbnails_(capture_thumbnails), |
31 weak_ptr_factory_(this) { | 33 weak_ptr_factory_(this) { |
32 image_fetcher_.reset( | 34 image_fetcher_.reset( |
33 new suggestions::ImageFetcherImpl(profile->GetRequestContext())); | 35 new image_fetcher::ImageFetcherImpl( |
| 36 base::MakeUnique<suggestions::ImageDecoderImpl>(), |
| 37 profile->GetRequestContext())); |
34 } | 38 } |
35 | 39 |
36 ThumbnailSource::~ThumbnailSource() { | 40 ThumbnailSource::~ThumbnailSource() { |
37 } | 41 } |
38 | 42 |
39 std::string ThumbnailSource::GetSource() const { | 43 std::string ThumbnailSource::GetSource() const { |
40 return capture_thumbnails_ ? | 44 return capture_thumbnails_ ? |
41 chrome::kChromeUIThumbnailHost2 : chrome::kChromeUIThumbnailHost; | 45 chrome::kChromeUIThumbnailHost2 : chrome::kChromeUIThumbnailHost; |
42 } | 46 } |
43 | 47 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 const SkBitmap* bitmap = image.ToSkBitmap(); | 126 const SkBitmap* bitmap = image.ToSkBitmap(); |
123 scoped_refptr<base::RefCountedBytes> encoded_data( | 127 scoped_refptr<base::RefCountedBytes> encoded_data( |
124 new base::RefCountedBytes()); | 128 new base::RefCountedBytes()); |
125 if (!suggestions::EncodeSkBitmapToJPEG(*bitmap, &encoded_data->data())) { | 129 if (!suggestions::EncodeSkBitmapToJPEG(*bitmap, &encoded_data->data())) { |
126 callback.Run(default_thumbnail_.get()); | 130 callback.Run(default_thumbnail_.get()); |
127 return; | 131 return; |
128 } | 132 } |
129 | 133 |
130 callback.Run(encoded_data.get()); | 134 callback.Run(encoded_data.get()); |
131 } | 135 } |
OLD | NEW |