OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | |
11 #include <vector> | |
12 | 10 |
13 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
14 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
15 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 13 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
16 #include "chrome/browser/history/history.h" | 14 #include "chrome/browser/history/history.h" |
17 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
18 | 16 |
19 class Profile; | 17 class Profile; |
20 class ThumbnailStore; | 18 class ThumbnailStore; |
21 | 19 |
22 // ThumbnailSource is the gateway between network-level chrome: | 20 // ThumbnailSource is the gateway between network-level chrome: |
23 // requests for thumbnails and the history backend that serves these. | 21 // requests for thumbnails and the history backend that serves these. |
24 class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource { | 22 class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource { |
25 public: | 23 public: |
26 explicit DOMUIThumbnailSource(Profile* profile); | 24 explicit DOMUIThumbnailSource(Profile* profile); |
27 | 25 |
28 // Called when the network layer has requested a resource underneath | 26 // Called when the network layer has requested a resource underneath |
29 // the path we registered. | 27 // the path we registered. |
30 virtual void StartDataRequest(const std::string& path, | 28 virtual void StartDataRequest(const std::string& path, |
31 bool is_off_the_record, | 29 bool is_off_the_record, |
32 int request_id); | 30 int request_id); |
33 | 31 |
34 virtual std::string GetMimeType(const std::string&) const { | 32 virtual std::string GetMimeType(const std::string&) const; |
35 // We need to explicitly return a mime type, otherwise if the user tries to | |
36 // drag the image they get no extension. | |
37 return "image/png"; | |
38 } | |
39 | 33 |
40 // Called when thumbnail data is available from the history backend. | 34 // Called when thumbnail data is available from the history backend. |
41 void OnThumbnailDataAvailable(HistoryService::Handle request_handle, | 35 void OnThumbnailDataAvailable(HistoryService::Handle request_handle, |
42 scoped_refptr<RefCountedBytes> data); | 36 scoped_refptr<RefCountedBytes> data); |
43 | 37 |
44 private: | 38 private: |
45 ~DOMUIThumbnailSource() {} | 39 virtual ~DOMUIThumbnailSource(); |
46 | 40 |
47 // Send the default thumbnail when we are missing a real one. | 41 // Send the default thumbnail when we are missing a real one. |
48 void SendDefaultThumbnail(int request_id); | 42 void SendDefaultThumbnail(int request_id); |
49 | 43 |
50 Profile* profile_; | 44 Profile* profile_; |
51 CancelableRequestConsumerT<int, 0> cancelable_consumer_; | 45 CancelableRequestConsumerT<int, 0> cancelable_consumer_; |
52 | 46 |
53 // Raw PNG representation of the thumbnail to show when the thumbnail | 47 // Raw PNG representation of the thumbnail to show when the thumbnail |
54 // database doesn't have a thumbnail for a webpage. | 48 // database doesn't have a thumbnail for a webpage. |
55 scoped_refptr<RefCountedMemory> default_thumbnail_; | 49 scoped_refptr<RefCountedMemory> default_thumbnail_; |
56 | 50 |
57 // Store requests when the ThumbnailStore isn't ready. When a notification is | |
58 // received that it is ready, then serve these requests. | |
59 std::vector<std::pair<std::string, int> > pending_requests_; | |
60 | |
61 // To register to be notified when the ThumbnailStore is ready. | 51 // To register to be notified when the ThumbnailStore is ready. |
62 NotificationRegistrar registrar_; | 52 NotificationRegistrar registrar_; |
63 | 53 |
64 DISALLOW_COPY_AND_ASSIGN(DOMUIThumbnailSource); | 54 DISALLOW_COPY_AND_ASSIGN(DOMUIThumbnailSource); |
65 }; | 55 }; |
66 | 56 |
67 #endif // CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_ | 57 #endif // CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_ |
OLD | NEW |