OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/dom_ui_thumbnail_source.h" | 5 #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
11 #include "chrome/browser/history/top_sites.h" | 11 #include "chrome/browser/history/top_sites.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "gfx/codec/jpeg_codec.h" | 15 #include "gfx/codec/jpeg_codec.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
19 | 19 |
20 DOMUIThumbnailSource::DOMUIThumbnailSource(Profile* profile) | 20 DOMUIThumbnailSource::DOMUIThumbnailSource(Profile* profile) |
21 : DataSource(chrome::kChromeUIThumbnailPath, MessageLoop::current()), | 21 : DataSource(chrome::kChromeUIThumbnailPath, MessageLoop::current()), |
22 profile_(profile) { | 22 profile_(profile) { |
23 } | 23 } |
24 | 24 |
25 DOMUIThumbnailSource::~DOMUIThumbnailSource() { | 25 DOMUIThumbnailSource::~DOMUIThumbnailSource() { |
26 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
27 } | 26 } |
28 | 27 |
29 void DOMUIThumbnailSource::StartDataRequest(const std::string& path, | 28 void DOMUIThumbnailSource::StartDataRequest(const std::string& path, |
30 bool is_off_the_record, | 29 bool is_off_the_record, |
31 int request_id) { | 30 int request_id) { |
32 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
33 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) { | 31 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) { |
34 scoped_refptr<history::TopSites> top_sites = profile_->GetTopSites(); | 32 scoped_refptr<history::TopSites> top_sites = profile_->GetTopSites(); |
35 RefCountedBytes* data = NULL; | 33 RefCountedBytes* data = NULL; |
36 if (top_sites->GetPageThumbnail(GURL(path), &data)) { | 34 if (top_sites->GetPageThumbnail(GURL(path), &data)) { |
37 // We have the thumbnail. | 35 // We have the thumbnail. |
38 SendResponse(request_id, data); | 36 SendResponse(request_id, data); |
39 } else { | 37 } else { |
40 SendDefaultThumbnail(request_id); | 38 SendDefaultThumbnail(request_id); |
41 } | 39 } |
42 return; | 40 return; |
(...skipping 25 matching lines...) Expand all Loading... |
68 default_thumbnail_ = | 66 default_thumbnail_ = |
69 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 67 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
70 IDR_DEFAULT_THUMBNAIL); | 68 IDR_DEFAULT_THUMBNAIL); |
71 } | 69 } |
72 SendResponse(request_id, default_thumbnail_); | 70 SendResponse(request_id, default_thumbnail_); |
73 } | 71 } |
74 | 72 |
75 void DOMUIThumbnailSource::OnThumbnailDataAvailable( | 73 void DOMUIThumbnailSource::OnThumbnailDataAvailable( |
76 HistoryService::Handle request_handle, | 74 HistoryService::Handle request_handle, |
77 scoped_refptr<RefCountedBytes> data) { | 75 scoped_refptr<RefCountedBytes> data) { |
78 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
79 HistoryService* hs = | 76 HistoryService* hs = |
80 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 77 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
81 int request_id = cancelable_consumer_.GetClientData(hs, request_handle); | 78 int request_id = cancelable_consumer_.GetClientData(hs, request_handle); |
82 // Forward the data along to the networking system. | 79 // Forward the data along to the networking system. |
83 if (data.get() && !data->data.empty()) { | 80 if (data.get() && !data->data.empty()) { |
84 SendResponse(request_id, data); | 81 SendResponse(request_id, data); |
85 } else { | 82 } else { |
86 SendDefaultThumbnail(request_id); | 83 SendDefaultThumbnail(request_id); |
87 } | 84 } |
88 } | 85 } |
OLD | NEW |