OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_SCREENSHOT_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_SCREENSHOT_MANAGER_H_ |
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_SCREENSHOT_MANAGER_H_ | 6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_SCREENSHOT_MANAGER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" |
9 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
10 #include "base/time/time.h" | 12 #include "base/time/time.h" |
11 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/public/browser/web_contents_observer.h" |
12 | 15 |
13 class SkBitmap; | 16 class SkBitmap; |
14 | 17 |
15 namespace content { | 18 namespace content { |
16 | 19 |
17 class NavigationControllerImpl; | 20 class NavigationControllerImpl; |
18 class NavigationEntryImpl; | 21 class NavigationEntryImpl; |
19 class RenderViewHost; | 22 class RenderViewHost; |
20 class ScreenshotData; | 23 class ScreenshotData; |
| 24 class SiteInstanceKeepAlive; |
21 | 25 |
22 // NavigationEntryScreenshotManager takes care of taking image-captures for the | 26 // NavigationEntryScreenshotManager takes care of taking image-captures for the |
23 // current navigation entry of a NavigationControllerImpl, and managing these | 27 // current navigation entry of a NavigationControllerImpl, and managing these |
24 // captured images. These image-captures are used for history navigation using | 28 // captured images. These image-captures are used for history navigation using |
25 // overscroll gestures. | 29 // overscroll gestures. |
26 class CONTENT_EXPORT NavigationEntryScreenshotManager { | 30 class CONTENT_EXPORT NavigationEntryScreenshotManager |
| 31 : public WebContentsObserver { |
27 public: | 32 public: |
28 explicit NavigationEntryScreenshotManager( | 33 explicit NavigationEntryScreenshotManager( |
29 NavigationControllerImpl* controller); | 34 NavigationControllerImpl* controller); |
30 virtual ~NavigationEntryScreenshotManager(); | 35 virtual ~NavigationEntryScreenshotManager(); |
31 | 36 |
32 // Takes a screenshot of the last-committed entry of the controller. | 37 // Takes a screenshot of the last-committed entry of the controller. |
33 void TakeScreenshot(); | 38 void TakeScreenshot(); |
34 | 39 |
35 // Clears screenshots of all navigation entries. | 40 // Clears screenshots of all navigation entries. |
36 void ClearAllScreenshots(); | 41 void ClearAllScreenshots(); |
37 | 42 |
38 protected: | 43 protected: |
39 virtual void TakeScreenshotImpl(RenderViewHost* host, | 44 virtual void TakeScreenshotImpl(RenderViewHost* host, |
40 NavigationEntryImpl* entry); | 45 NavigationEntryImpl* entry); |
41 | 46 |
42 // Called after a screenshot has been set on an NavigationEntryImpl. | 47 // Called after a screenshot has been set on an NavigationEntryImpl. |
43 // Overridden in tests to get notified of when a screenshot is set. | 48 // Overridden in tests to get notified of when a screenshot is set. |
44 virtual void OnScreenshotSet(NavigationEntryImpl* entry); | 49 virtual void OnScreenshotSet(NavigationEntryImpl* entry); |
45 | 50 |
46 NavigationControllerImpl* owner() { return owner_; } | 51 NavigationControllerImpl* owner() { return owner_; } |
47 | 52 |
48 void SetMinScreenshotIntervalMS(int interval_ms); | 53 void SetMinScreenshotIntervalMS(int interval_ms); |
49 | 54 |
50 // The callback invoked when taking the screenshot of the page is complete. | 55 // The callback invoked when taking the screenshot of the page is complete. |
51 // This sets the screenshot on the navigation entry. | 56 // This sets the screenshot on the navigation entry. |
52 void OnScreenshotTaken(int unique_id, | 57 void OnScreenshotTaken(int unique_id, |
| 58 SiteInstanceKeepAlive* keep_alive, |
53 bool success, | 59 bool success, |
54 const SkBitmap& bitmap); | 60 const SkBitmap& bitmap); |
55 | 61 |
56 // Returns the number of entries with screenshots. | 62 // Returns the number of entries with screenshots. |
57 int GetScreenshotCount() const; | 63 int GetScreenshotCount() const; |
58 | 64 |
59 private: | 65 private: |
60 // This is called when the screenshot data has beene encoded to PNG in a | 66 // This is called when the screenshot data has beene encoded to PNG in a |
61 // worker thread. | 67 // worker thread. |
62 void OnScreenshotEncodeComplete(int unique_id, | 68 void OnScreenshotEncodeComplete(int unique_id, |
63 scoped_refptr<ScreenshotData> data); | 69 scoped_refptr<ScreenshotData> data); |
64 | 70 |
65 // Removes the screenshot for the entry, returning true if the entry had a | 71 // Removes the screenshot for the entry, returning true if the entry had a |
66 // screenshot. | 72 // screenshot. |
67 bool ClearScreenshot(NavigationEntryImpl* entry); | 73 bool ClearScreenshot(NavigationEntryImpl* entry); |
68 | 74 |
69 // The screenshots in the NavigationEntryImpls can accumulate and consume a | 75 // The screenshots in the NavigationEntryImpls can accumulate and consume a |
70 // large amount of memory. This function makes sure that the memory | 76 // large amount of memory. This function makes sure that the memory |
71 // consumption is within a certain limit. | 77 // consumption is within a certain limit. |
72 void PurgeScreenshotsIfNecessary(); | 78 void PurgeScreenshotsIfNecessary(); |
73 | 79 |
| 80 // WebContentsObserver: |
| 81 virtual void WebContentsDestroyed(WebContents* contents) OVERRIDE; |
| 82 |
74 // The navigation controller that owns this screenshot-manager. | 83 // The navigation controller that owns this screenshot-manager. |
75 NavigationControllerImpl* owner_; | 84 NavigationControllerImpl* owner_; |
76 | 85 |
| 86 // Keeps track of (and owns) all the SiteInstanceKeepAlive objects created for |
| 87 // screenshot requests. |
| 88 ScopedVector<SiteInstanceKeepAlive> keep_alives_; |
| 89 |
77 // Taking a screenshot and encoding them can be async. So use a weakptr for | 90 // Taking a screenshot and encoding them can be async. So use a weakptr for |
78 // the callback to make sure that the screenshot/encoding completion callback | 91 // the callback to make sure that the screenshot/encoding completion callback |
79 // does not trigger on a destroyed NavigationEntryScreenshotManager. | 92 // does not trigger on a destroyed NavigationEntryScreenshotManager. |
80 base::WeakPtrFactory<NavigationEntryScreenshotManager> screenshot_factory_; | 93 base::WeakPtrFactory<NavigationEntryScreenshotManager> screenshot_factory_; |
81 | 94 |
82 base::Time last_screenshot_time_; | 95 base::Time last_screenshot_time_; |
83 int min_screenshot_interval_ms_; | 96 int min_screenshot_interval_ms_; |
84 | 97 |
85 DISALLOW_COPY_AND_ASSIGN(NavigationEntryScreenshotManager); | 98 DISALLOW_COPY_AND_ASSIGN(NavigationEntryScreenshotManager); |
86 }; | 99 }; |
87 | 100 |
88 } // namespace content | 101 } // namespace content |
89 | 102 |
90 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_SCREENSHOT_MANAGER_H_ | 103 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_SCREENSHOT_MANAGER_H_ |
OLD | NEW |