Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: chrome/browser/ui/webui/ntp/thumbnail_source.cc

Issue 11885021: Don't derive from ChromeURLDataManager::DataSource, and instead have these classes implement a dele… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: nits Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/memory/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
10 #include "chrome/browser/thumbnails/thumbnail_service.h" 10 #include "chrome/browser/thumbnails/thumbnail_service.h"
11 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" 11 #include "chrome/browser/thumbnails/thumbnail_service_factory.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
13 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
14 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
15 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 18
19 // Set ThumbnailService now as Profile isn't thread safe.
18 ThumbnailSource::ThumbnailSource(Profile* profile) 20 ThumbnailSource::ThumbnailSource(Profile* profile)
19 : DataSource(chrome::kChromeUIThumbnailHost, MessageLoop::current()), 21 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)) {
20 // Set ThumbnailService now as Profile isn't thread safe.
21 thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)) {
22 } 22 }
23 23
24 ThumbnailSource::~ThumbnailSource() { 24 ThumbnailSource::~ThumbnailSource() {
25 } 25 }
26 26
27 std::string ThumbnailSource::GetSource() {
28 return chrome::kChromeUIThumbnailHost;
29 }
30
27 void ThumbnailSource::StartDataRequest(const std::string& path, 31 void ThumbnailSource::StartDataRequest(const std::string& path,
28 bool is_incognito, 32 bool is_incognito,
29 int request_id) { 33 int request_id) {
30 scoped_refptr<base::RefCountedMemory> data; 34 scoped_refptr<base::RefCountedMemory> data;
31 if (thumbnail_service_->GetPageThumbnail(GURL(path), &data)) { 35 if (thumbnail_service_->GetPageThumbnail(GURL(path), &data)) {
32 // We have the thumbnail. 36 // We have the thumbnail.
33 SendResponse(request_id, data.get()); 37 url_data_source()->SendResponse(request_id, data.get());
34 } else { 38 } else {
35 SendDefaultThumbnail(request_id); 39 SendDefaultThumbnail(request_id);
36 } 40 }
37 } 41 }
38 42
39 std::string ThumbnailSource::GetMimeType(const std::string&) const { 43 std::string ThumbnailSource::GetMimeType(const std::string&) const {
40 // We need to explicitly return a mime type, otherwise if the user tries to 44 // We need to explicitly return a mime type, otherwise if the user tries to
41 // drag the image they get no extension. 45 // drag the image they get no extension.
42 return "image/png"; 46 return "image/png";
43 } 47 }
44 48
45 MessageLoop* ThumbnailSource::MessageLoopForRequestPath( 49 MessageLoop* ThumbnailSource::MessageLoopForRequestPath(
46 const std::string& path) const { 50 const std::string& path) const {
47 // TopSites can be accessed from the IO thread. 51 // TopSites can be accessed from the IO thread.
48 return thumbnail_service_.get() ? 52 return thumbnail_service_.get() ?
49 NULL : DataSource::MessageLoopForRequestPath(path); 53 NULL : content::URLDataSourceDelegate::MessageLoopForRequestPath(path);
50 } 54 }
51 55
52 void ThumbnailSource::SendDefaultThumbnail(int request_id) { 56 void ThumbnailSource::SendDefaultThumbnail(int request_id) {
53 SendResponse(request_id, default_thumbnail_); 57 url_data_source()->SendResponse(request_id, default_thumbnail_);
54 } 58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698