| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/ntp/thumbnail_source.h" | 5 #include "chrome/browser/ui/webui/ntp/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 "chrome/browser/history/top_sites.h" | 9 #include "chrome/browser/history/top_sites.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 11 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 12 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 14 | 15 |
| 15 ThumbnailSource::ThumbnailSource(Profile* profile) | 16 ThumbnailSource::ThumbnailSource(Profile* profile) |
| 16 : DataSource(chrome::kChromeUIThumbnailHost, MessageLoop::current()), | 17 : DataSource(chrome::kChromeUIThumbnailHost, MessageLoop::current()), |
| 17 // Set TopSites now as Profile isn't thread safe. | 18 // Set TopSites now as Profile isn't thread safe. |
| 18 top_sites_(profile->GetTopSites()) { | 19 top_sites_(profile->GetTopSites()) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 ThumbnailSource::~ThumbnailSource() { | 22 ThumbnailSource::~ThumbnailSource() { |
| 22 } | 23 } |
| 23 | 24 |
| 24 void ThumbnailSource::StartDataRequest(const std::string& path, | 25 void ThumbnailSource::StartDataRequest(const std::string& path, |
| 25 bool is_incognito, | 26 bool is_incognito, |
| 26 int request_id) { | 27 int request_id) { |
| 27 scoped_refptr<RefCountedMemory> data; | 28 scoped_refptr<base::RefCountedMemory> data; |
| 28 if (top_sites_->GetPageThumbnail(GURL(path), &data)) { | 29 if (top_sites_->GetPageThumbnail(GURL(path), &data)) { |
| 29 // We have the thumbnail. | 30 // We have the thumbnail. |
| 30 SendResponse(request_id, data.get()); | 31 SendResponse(request_id, data.get()); |
| 31 } else { | 32 } else { |
| 32 SendDefaultThumbnail(request_id); | 33 SendDefaultThumbnail(request_id); |
| 33 } | 34 } |
| 34 } | 35 } |
| 35 | 36 |
| 36 std::string ThumbnailSource::GetMimeType(const std::string&) const { | 37 std::string ThumbnailSource::GetMimeType(const std::string&) const { |
| 37 // We need to explicitly return a mime type, otherwise if the user tries to | 38 // We need to explicitly return a mime type, otherwise if the user tries to |
| 38 // drag the image they get no extension. | 39 // drag the image they get no extension. |
| 39 return "image/png"; | 40 return "image/png"; |
| 40 } | 41 } |
| 41 | 42 |
| 42 MessageLoop* ThumbnailSource::MessageLoopForRequestPath( | 43 MessageLoop* ThumbnailSource::MessageLoopForRequestPath( |
| 43 const std::string& path) const { | 44 const std::string& path) const { |
| 44 // TopSites can be accessed from the IO thread. | 45 // TopSites can be accessed from the IO thread. |
| 45 return top_sites_.get() ? NULL : DataSource::MessageLoopForRequestPath(path); | 46 return top_sites_.get() ? NULL : DataSource::MessageLoopForRequestPath(path); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void ThumbnailSource::SendDefaultThumbnail(int request_id) { | 49 void ThumbnailSource::SendDefaultThumbnail(int request_id) { |
| 49 SendResponse(request_id, default_thumbnail_); | 50 SendResponse(request_id, default_thumbnail_); |
| 50 } | 51 } |
| OLD | NEW |