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/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 "base/memory/ref_counted_memory.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/search/instant_io_context.h" | 11 #include "chrome/browser/search/instant_io_context.h" |
12 #include "chrome/browser/thumbnails/thumbnail_service.h" | 12 #include "chrome/browser/thumbnails/thumbnail_service.h" |
13 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" | 13 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 | 19 |
20 using content::BrowserThread; | 20 using content::BrowserThread; |
21 | 21 |
22 // Set ThumbnailService now as Profile isn't thread safe. | 22 // Set ThumbnailService now as Profile isn't thread safe. |
23 ThumbnailSource::ThumbnailSource(Profile* profile, bool prefix_match) | 23 ThumbnailSource::ThumbnailSource(Profile* profile, bool capture_thumbnails) |
24 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), | 24 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), |
25 profile_(profile), | 25 profile_(profile), |
26 prefix_match_(prefix_match) { | 26 capture_thumbnails_(capture_thumbnails) { |
27 } | 27 } |
28 | 28 |
29 ThumbnailSource::~ThumbnailSource() { | 29 ThumbnailSource::~ThumbnailSource() { |
30 } | 30 } |
31 | 31 |
32 std::string ThumbnailSource::GetSource() const { | 32 std::string ThumbnailSource::GetSource() const { |
33 return prefix_match_ ? | 33 return capture_thumbnails_ ? |
34 chrome::kChromeUIThumbnailHost2 : chrome::kChromeUIThumbnailHost; | 34 chrome::kChromeUIThumbnailHost2 : chrome::kChromeUIThumbnailHost; |
35 } | 35 } |
36 | 36 |
37 void ThumbnailSource::StartDataRequest( | 37 void ThumbnailSource::StartDataRequest( |
38 const std::string& path, | 38 const std::string& path, |
39 int render_process_id, | 39 int render_process_id, |
40 int render_view_id, | 40 int render_view_id, |
41 const content::URLDataSource::GotDataCallback& callback) { | 41 const content::URLDataSource::GotDataCallback& callback) { |
42 scoped_refptr<base::RefCountedMemory> data; | 42 scoped_refptr<base::RefCountedMemory> data; |
43 if (thumbnail_service_->GetPageThumbnail(GURL(path), prefix_match_, &data)) { | 43 if (thumbnail_service_->GetPageThumbnail(GURL(path), capture_thumbnails_, |
| 44 &data)) { |
44 // We have the thumbnail. | 45 // We have the thumbnail. |
45 callback.Run(data.get()); | 46 callback.Run(data.get()); |
46 } else { | 47 } else { |
47 callback.Run(default_thumbnail_.get()); | 48 callback.Run(default_thumbnail_.get()); |
48 } | 49 } |
| 50 if (capture_thumbnails_) |
| 51 thumbnail_service_->AddForcedURL(GURL(path)); |
49 } | 52 } |
50 | 53 |
51 std::string ThumbnailSource::GetMimeType(const std::string&) const { | 54 std::string ThumbnailSource::GetMimeType(const std::string&) const { |
52 // We need to explicitly return a mime type, otherwise if the user tries to | 55 // We need to explicitly return a mime type, otherwise if the user tries to |
53 // drag the image they get no extension. | 56 // drag the image they get no extension. |
54 return "image/png"; | 57 return "image/png"; |
55 } | 58 } |
56 | 59 |
57 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath( | 60 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath( |
58 const std::string& path) const { | 61 const std::string& path) const { |
59 // TopSites can be accessed from the IO thread. | 62 // TopSites can be accessed from the IO thread. |
60 return thumbnail_service_.get() ? | 63 return thumbnail_service_.get() ? |
61 NULL : content::URLDataSource::MessageLoopForRequestPath(path); | 64 NULL : content::URLDataSource::MessageLoopForRequestPath(path); |
62 } | 65 } |
63 | 66 |
64 bool ThumbnailSource::ShouldServiceRequest( | 67 bool ThumbnailSource::ShouldServiceRequest( |
65 const net::URLRequest* request) const { | 68 const net::URLRequest* request) const { |
66 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) | 69 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) |
67 return InstantIOContext::ShouldServiceRequest(request); | 70 return InstantIOContext::ShouldServiceRequest(request); |
68 return URLDataSource::ShouldServiceRequest(request); | 71 return URLDataSource::ShouldServiceRequest(request); |
69 } | 72 } |
OLD | NEW |