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