| 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 "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search/instant_io_context.h" | 10 #include "chrome/browser/search/instant_io_context.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 void ThumbnailSource::StartDataRequest( | 35 void ThumbnailSource::StartDataRequest( |
| 36 const std::string& path, | 36 const std::string& path, |
| 37 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 37 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 38 const content::URLDataSource::GotDataCallback& callback) { | 38 const content::URLDataSource::GotDataCallback& callback) { |
| 39 GURL page_url; | 39 GURL page_url; |
| 40 GURL fallback_thumbnail_url; | 40 GURL fallback_thumbnail_url; |
| 41 ExtractPageAndThumbnailUrls(path, &page_url, &fallback_thumbnail_url); | 41 ExtractPageAndThumbnailUrls(path, &page_url, &fallback_thumbnail_url); |
| 42 | 42 |
| 43 scoped_refptr<base::RefCountedMemory> data; | 43 scoped_refptr<base::RefCountedMemory> data; |
| 44 if (page_url.is_valid() && | 44 if (page_url.is_valid() && thumbnail_service_->GetPageThumbnail( |
| 45 thumbnail_service_->GetPageThumbnail(page_url, capture_thumbnails_, | 45 page_url, |
| 46 &data)) { | 46 /*prefix_match=*/capture_thumbnails_, &data)) { |
| 47 // If a local thumbnail is available for the page's URL, provide it. | 47 // If a local thumbnail is available for the page's URL, provide it. |
| 48 callback.Run(data.get()); | 48 callback.Run(data.get()); |
| 49 } else if (fallback_thumbnail_url.is_valid()) { | 49 } else if (fallback_thumbnail_url.is_valid()) { |
| 50 // Otherwise, if a fallback thumbnail URL was provided, fetch it and | 50 // Otherwise, if a fallback thumbnail URL was provided, fetch it and |
| 51 // eventually return it. | 51 // eventually return it. |
| 52 image_data_fetcher_.FetchImageData( | 52 image_data_fetcher_.FetchImageData( |
| 53 fallback_thumbnail_url, | 53 fallback_thumbnail_url, |
| 54 base::Bind(&ThumbnailSource::SendFetchedUrlImage, | 54 base::Bind(&ThumbnailSource::SendFetchedUrlImage, |
| 55 weak_ptr_factory_.GetWeakPtr(), callback)); | 55 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 56 } else { | 56 } else { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 const content::URLDataSource::GotDataCallback& callback, | 116 const content::URLDataSource::GotDataCallback& callback, |
| 117 const std::string& image_data, | 117 const std::string& image_data, |
| 118 const image_fetcher::RequestMetadata& metadata) { | 118 const image_fetcher::RequestMetadata& metadata) { |
| 119 if (image_data.empty()) { | 119 if (image_data.empty()) { |
| 120 callback.Run(nullptr); | 120 callback.Run(nullptr); |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 std::string image_data_copy = image_data; | 123 std::string image_data_copy = image_data; |
| 124 callback.Run(base::RefCountedString::TakeString(&image_data_copy)); | 124 callback.Run(base::RefCountedString::TakeString(&image_data_copy)); |
| 125 } | 125 } |
| OLD | NEW |