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

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

Issue 11881055: Simplify WebUI data sources. Currently WebUI data sources implement a URLDataSourceDelegate interfa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix issue in about_ui exposed by cros tests 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"
14 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
15 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
16 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
17 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
18 17
19 // Set ThumbnailService now as Profile isn't thread safe. 18 // Set ThumbnailService now as Profile isn't thread safe.
20 ThumbnailSource::ThumbnailSource(Profile* profile) 19 ThumbnailSource::ThumbnailSource(Profile* profile)
21 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)) { 20 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)) {
22 } 21 }
23 22
24 ThumbnailSource::~ThumbnailSource() { 23 ThumbnailSource::~ThumbnailSource() {
25 } 24 }
26 25
27 std::string ThumbnailSource::GetSource() { 26 std::string ThumbnailSource::GetSource() {
28 return chrome::kChromeUIThumbnailHost; 27 return chrome::kChromeUIThumbnailHost;
29 } 28 }
30 29
31 void ThumbnailSource::StartDataRequest(const std::string& path, 30 void ThumbnailSource::StartDataRequest(
32 bool is_incognito, 31 const std::string& path,
33 int request_id) { 32 bool is_incognito,
33 const content::URLDataSource::GotDataCallback& callback) {
34 scoped_refptr<base::RefCountedMemory> data; 34 scoped_refptr<base::RefCountedMemory> data;
35 if (thumbnail_service_->GetPageThumbnail(GURL(path), &data)) { 35 if (thumbnail_service_->GetPageThumbnail(GURL(path), &data)) {
36 // We have the thumbnail. 36 // We have the thumbnail.
37 url_data_source()->SendResponse(request_id, data.get()); 37 callback.Run(data.get());
38 } else { 38 } else {
39 SendDefaultThumbnail(request_id); 39 callback.Run(default_thumbnail_);
40 } 40 }
41 } 41 }
42 42
43 std::string ThumbnailSource::GetMimeType(const std::string&) const { 43 std::string ThumbnailSource::GetMimeType(const std::string&) const {
44 // 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
45 // drag the image they get no extension. 45 // drag the image they get no extension.
46 return "image/png"; 46 return "image/png";
47 } 47 }
48 48
49 MessageLoop* ThumbnailSource::MessageLoopForRequestPath( 49 MessageLoop* ThumbnailSource::MessageLoopForRequestPath(
50 const std::string& path) const { 50 const std::string& path) const {
51 // TopSites can be accessed from the IO thread. 51 // TopSites can be accessed from the IO thread.
52 return thumbnail_service_.get() ? 52 return thumbnail_service_.get() ?
53 NULL : content::URLDataSourceDelegate::MessageLoopForRequestPath(path); 53 NULL : content::URLDataSource::MessageLoopForRequestPath(path);
54 } 54 }
55
56 void ThumbnailSource::SendDefaultThumbnail(int request_id) {
57 url_data_source()->SendResponse(request_id, default_thumbnail_);
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698