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