OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_THUMBNAIL_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_THUMBNAIL_LIST_SOURCE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_NTP_THUMBNAIL_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_NTP_THUMBNAIL_LIST_SOURCE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/history/history_types.h" |
12 #include "content/public/browser/url_data_source.h" | 14 #include "content/public/browser/url_data_source.h" |
13 | 15 |
14 class Profile; | 16 class Profile; |
15 | 17 |
16 namespace base { | 18 namespace base { |
17 class RefCountedMemory; | 19 class RefCountedMemory; |
18 } | 20 } |
19 | 21 |
20 namespace thumbnails { | 22 namespace thumbnails { |
21 class ThumbnailService; | 23 class ThumbnailService; |
22 } | 24 } |
23 | 25 |
24 // ThumbnailSource is the gateway between network-level chrome: requests for | 26 // ThumbnailListSource renders a webpage to list all thumbnails stored in |
25 // thumbnails and the history/top-sites backend that serves these. | 27 // TopSites, along with all associated URLs. The thumbnail images are embedded |
26 class ThumbnailSource : public content::URLDataSource { | 28 // into the HTML via Base64, so we can easily produce a dump of TopSites and |
| 29 // the thumbnails it stores. |
| 30 class ThumbnailListSource : public content::URLDataSource { |
27 public: | 31 public: |
28 ThumbnailSource(Profile* profile, bool prefix_match); | 32 explicit ThumbnailListSource(Profile* profile); |
29 | 33 |
30 // content::URLDataSource implementation. | 34 // content::URLDataSource implementation. |
31 virtual std::string GetSource() const OVERRIDE; | 35 virtual std::string GetSource() const OVERRIDE; |
32 virtual void StartDataRequest( | 36 virtual void StartDataRequest( |
33 const std::string& path, | 37 const std::string& path, |
34 int render_process_id, | 38 int render_process_id, |
35 int render_view_id, | 39 int render_view_id, |
36 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; | 40 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; |
37 virtual std::string GetMimeType(const std::string& path) const OVERRIDE; | 41 virtual std::string GetMimeType(const std::string& path) const OVERRIDE; |
38 virtual base::MessageLoop* MessageLoopForRequestPath( | 42 virtual base::MessageLoop* MessageLoopForRequestPath( |
39 const std::string& path) const OVERRIDE; | 43 const std::string& path) const OVERRIDE; |
40 virtual bool ShouldServiceRequest( | 44 virtual bool ShouldServiceRequest( |
41 const net::URLRequest* request) const OVERRIDE; | 45 const net::URLRequest* request) const OVERRIDE; |
42 | 46 |
43 private: | 47 private: |
44 virtual ~ThumbnailSource(); | 48 virtual ~ThumbnailListSource(); |
45 | 49 |
46 // Raw PNG representation of the thumbnail to show when the thumbnail | 50 void OnMostVisitedURLsAvailable( |
47 // database doesn't have a thumbnail for a webpage. | 51 const content::URLDataSource::GotDataCallback& callback, |
48 scoped_refptr<base::RefCountedMemory> default_thumbnail_; | 52 const history::MostVisitedURLList& mvurl_list); |
49 | 53 |
50 // ThumbnailService. | 54 // ThumbnailService. |
51 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service_; | 55 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service_; |
52 | 56 |
53 // Only used when servicing requests on the UI thread. | 57 // Only used when servicing requests on the UI thread. |
54 Profile* const profile_; | 58 Profile* const profile_; |
55 | 59 |
56 // If an exact thumbnail URL match fails, specifies whether or not to try | 60 // For callbacks may be run after destruction. |
57 // harder by matching the query thumbnail URL as URL prefix. This affects | 61 base::WeakPtrFactory<ThumbnailListSource> weak_ptr_factory_; |
58 // GetSource(). | |
59 const bool prefix_match_; | |
60 | 62 |
61 DISALLOW_COPY_AND_ASSIGN(ThumbnailSource); | 63 DISALLOW_COPY_AND_ASSIGN(ThumbnailListSource); |
62 }; | 64 }; |
63 | 65 |
64 #endif // CHROME_BROWSER_UI_WEBUI_NTP_THUMBNAIL_SOURCE_H_ | 66 |
| 67 #endif // CHROME_BROWSER_UI_WEBUI_NTP_THUMBNAIL_LIST_SOURCE_H_ |
OLD | NEW |