OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_ |
6 #define CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_ | 6 #define CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 13 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
14 #include "chrome/browser/history/history.h" | 14 #include "chrome/browser/history/history.h" |
15 | 15 |
16 class Profile; | 16 class Profile; |
17 class ThumbnailStore; | 17 class ThumbnailStore; |
18 | 18 |
19 // ThumbnailSource is the gateway between network-level chrome: | 19 // ThumbnailSource is the gateway between network-level chrome: |
20 // requests for thumbnails and the history backend that serves these. | 20 // requests for thumbnails and the history backend that serves these. |
21 class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource { | 21 class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource { |
22 public: | 22 public: |
23 explicit DOMUIThumbnailSource(Profile* profile); | 23 explicit DOMUIThumbnailSource(Profile* profile); |
24 virtual ~DOMUIThumbnailSource(); | |
25 | 24 |
26 // Called when the network layer has requested a resource underneath | 25 // Called when the network layer has requested a resource underneath |
27 // the path we registered. | 26 // the path we registered. |
28 virtual void StartDataRequest(const std::string& path, int request_id); | 27 virtual void StartDataRequest(const std::string& path, int request_id); |
29 | 28 |
30 // Used only when chromium is invoked with the --thumbnail-store switch. | |
31 // If StartDataRequest does not return thumbnail data synchronously, this | |
32 // method will be invoked when the thumbnail data becomes available. | |
33 virtual void ReturnData(int request_id, scoped_refptr<RefCountedBytes> data); | |
34 | |
35 virtual std::string GetMimeType(const std::string&) const { | 29 virtual std::string GetMimeType(const std::string&) const { |
36 // We need to explicitly return a mime type, otherwise if the user tries to | 30 // We need to explicitly return a mime type, otherwise if the user tries to |
37 // drag the image they get no extension. | 31 // drag the image they get no extension. |
38 return "image/png"; | 32 return "image/png"; |
39 } | 33 } |
40 | 34 |
41 // Called when thumbnail data is available from the history backend. | 35 // Called when thumbnail data is available from the history backend. |
42 void OnThumbnailDataAvailable(HistoryService::Handle request_handle, | 36 void OnThumbnailDataAvailable(HistoryService::Handle request_handle, |
43 scoped_refptr<RefCountedBytes> data); | 37 scoped_refptr<RefCountedBytes> data); |
44 | 38 |
45 private: | 39 private: |
46 Profile* profile_; | 40 Profile* profile_; |
47 CancelableRequestConsumerT<int, 0> cancelable_consumer_; | 41 CancelableRequestConsumerT<int, 0> cancelable_consumer_; |
48 | 42 |
49 // A set of outstanding request_id's. These are canceled on destruction. | |
50 std::set<int> pending_requests_; | |
51 | |
52 // The ThumbnailStore from which thumbnails are requested. | 43 // The ThumbnailStore from which thumbnails are requested. |
53 scoped_refptr<ThumbnailStore> store_; | 44 scoped_refptr<ThumbnailStore> store_; |
54 | 45 |
55 // Raw PNG representation of the thumbnail to show when the thumbnail | 46 // Raw PNG representation of the thumbnail to show when the thumbnail |
56 // database doesn't have a thumbnail for a webpage. | 47 // database doesn't have a thumbnail for a webpage. |
57 scoped_refptr<RefCountedBytes> default_thumbnail_; | 48 scoped_refptr<RefCountedBytes> default_thumbnail_; |
58 | 49 |
59 DISALLOW_COPY_AND_ASSIGN(DOMUIThumbnailSource); | 50 DISALLOW_COPY_AND_ASSIGN(DOMUIThumbnailSource); |
60 }; | 51 }; |
61 | 52 |
62 #endif // CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_ | 53 #endif // CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_ |
OLD | NEW |