| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_THUMBNAILS_THUMBNAIL_LIST_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_THUMBNAILS_THUMBNAIL_LIST_SOURCE_H_ |
| 6 #define CHROME_BROWSER_THUMBNAILS_THUMBNAIL_LIST_SOURCE_H_ | 6 #define CHROME_BROWSER_THUMBNAILS_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" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "components/history/core/browser/history_types.h" | 13 #include "components/history/core/browser/history_types.h" |
| 14 #include "content/public/browser/url_data_source.h" | 14 #include "content/public/browser/url_data_source.h" |
| 15 | 15 |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class RefCountedMemory; | 19 class RefCountedMemory; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace history { |
| 23 class TopSites; |
| 24 } |
| 25 |
| 22 namespace thumbnails { | 26 namespace thumbnails { |
| 23 class ThumbnailService; | 27 class ThumbnailService; |
| 24 } | 28 } |
| 25 | 29 |
| 26 // ThumbnailListSource renders a webpage to list all thumbnails stored in | 30 // ThumbnailListSource renders a webpage to list all thumbnails stored in |
| 27 // TopSites, along with all associated URLs. The thumbnail images are embedded | 31 // TopSites, along with all associated URLs. The thumbnail images are embedded |
| 28 // into the HTML via Base64, so we can easily produce a dump of TopSites and | 32 // into the HTML via Base64, so we can easily produce a dump of TopSites and |
| 29 // the thumbnails it stores. | 33 // the thumbnails it stores. |
| 30 class ThumbnailListSource : public content::URLDataSource { | 34 class ThumbnailListSource : public content::URLDataSource { |
| 31 public: | 35 public: |
| 32 explicit ThumbnailListSource(Profile* profile); | 36 explicit ThumbnailListSource(Profile* profile); |
| 33 | 37 |
| 34 // content::URLDataSource implementation. | 38 // content::URLDataSource implementation. |
| 35 std::string GetSource() const override; | 39 std::string GetSource() const override; |
| 40 // Called on the IO thread. |
| 36 void StartDataRequest( | 41 void StartDataRequest( |
| 37 const std::string& path, | 42 const std::string& path, |
| 38 int render_process_id, | 43 int render_process_id, |
| 39 int render_frame_id, | 44 int render_frame_id, |
| 40 const content::URLDataSource::GotDataCallback& callback) override; | 45 const content::URLDataSource::GotDataCallback& callback) override; |
| 46 |
| 41 std::string GetMimeType(const std::string& path) const override; | 47 std::string GetMimeType(const std::string& path) const override; |
| 42 base::MessageLoop* MessageLoopForRequestPath( | 48 base::MessageLoop* MessageLoopForRequestPath( |
| 43 const std::string& path) const override; | 49 const std::string& path) const override; |
| 44 bool ShouldServiceRequest(const net::URLRequest* request) const override; | 50 bool ShouldServiceRequest(const net::URLRequest* request) const override; |
| 45 bool ShouldReplaceExistingSource() const override; | 51 bool ShouldReplaceExistingSource() const override; |
| 46 | 52 |
| 47 private: | 53 private: |
| 48 ~ThumbnailListSource() override; | 54 ~ThumbnailListSource() override; |
| 49 | 55 |
| 56 // Called on the IO thread. |
| 50 void OnMostVisitedURLsAvailable( | 57 void OnMostVisitedURLsAvailable( |
| 51 const content::URLDataSource::GotDataCallback& callback, | 58 const content::URLDataSource::GotDataCallback& callback, |
| 52 const history::MostVisitedURLList& mvurl_list); | 59 const history::MostVisitedURLList& mvurl_list); |
| 53 | 60 |
| 54 // ThumbnailService. | 61 // ThumbnailService. |
| 55 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service_; | 62 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service_; |
| 56 | 63 |
| 57 // Only used when servicing requests on the UI thread. | 64 scoped_refptr<history::TopSites> top_sites_; |
| 58 Profile* const profile_; | |
| 59 | 65 |
| 60 // For callbacks may be run after destruction. | 66 // For callbacks may be run after destruction. |
| 61 base::WeakPtrFactory<ThumbnailListSource> weak_ptr_factory_; | 67 base::WeakPtrFactory<ThumbnailListSource> weak_ptr_factory_; |
| 62 | 68 |
| 63 DISALLOW_COPY_AND_ASSIGN(ThumbnailListSource); | 69 DISALLOW_COPY_AND_ASSIGN(ThumbnailListSource); |
| 64 }; | 70 }; |
| 65 | 71 |
| 66 | 72 |
| 67 #endif // CHROME_BROWSER_THUMBNAILS_THUMBNAIL_LIST_SOURCE_H_ | 73 #endif // CHROME_BROWSER_THUMBNAILS_THUMBNAIL_LIST_SOURCE_H_ |
| OLD | NEW |