| 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" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 scoped_refptr<base::SingleThreadTaskRunner> | 82 scoped_refptr<base::SingleThreadTaskRunner> |
| 83 ThumbnailSource::TaskRunnerForRequestPath(const std::string& path) const { | 83 ThumbnailSource::TaskRunnerForRequestPath(const std::string& path) const { |
| 84 // TopSites can be accessed from the IO thread. Otherwise, the URLs should be | 84 // TopSites can be accessed from the IO thread. Otherwise, the URLs should be |
| 85 // accessed on the UI thread. | 85 // accessed on the UI thread. |
| 86 return thumbnail_service_.get() | 86 return thumbnail_service_.get() |
| 87 ? nullptr | 87 ? nullptr |
| 88 : content::URLDataSource::TaskRunnerForRequestPath(path); | 88 : content::URLDataSource::TaskRunnerForRequestPath(path); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool ThumbnailSource::AllowCaching() const { |
| 92 return false; |
| 93 } |
| 94 |
| 91 bool ThumbnailSource::ShouldServiceRequest( | 95 bool ThumbnailSource::ShouldServiceRequest( |
| 92 const net::URLRequest* request) const { | 96 const net::URLRequest* request) const { |
| 93 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) | 97 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) |
| 94 return InstantIOContext::ShouldServiceRequest(request); | 98 return InstantIOContext::ShouldServiceRequest(request); |
| 95 return URLDataSource::ShouldServiceRequest(request); | 99 return URLDataSource::ShouldServiceRequest(request); |
| 96 } | 100 } |
| 97 | 101 |
| 98 void ThumbnailSource::ExtractPageAndThumbnailUrls( | 102 void ThumbnailSource::ExtractPageAndThumbnailUrls( |
| 99 const std::string& path, | 103 const std::string& path, |
| 100 GURL* page_url, | 104 GURL* page_url, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 125 const SkBitmap* bitmap = image.ToSkBitmap(); | 129 const SkBitmap* bitmap = image.ToSkBitmap(); |
| 126 scoped_refptr<base::RefCountedBytes> encoded_data( | 130 scoped_refptr<base::RefCountedBytes> encoded_data( |
| 127 new base::RefCountedBytes()); | 131 new base::RefCountedBytes()); |
| 128 if (!suggestions::EncodeSkBitmapToJPEG(*bitmap, &encoded_data->data())) { | 132 if (!suggestions::EncodeSkBitmapToJPEG(*bitmap, &encoded_data->data())) { |
| 129 callback.Run(default_thumbnail_.get()); | 133 callback.Run(default_thumbnail_.get()); |
| 130 return; | 134 return; |
| 131 } | 135 } |
| 132 | 136 |
| 133 callback.Run(encoded_data.get()); | 137 callback.Run(encoded_data.get()); |
| 134 } | 138 } |
| OLD | NEW |