Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / frame_host / navigation_entry_screenshot_manager.h
blob072d6fd4a7fe19a1111acdb6b2e5c6c470f92285
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_SCREENSHOT_MANAGER_H_
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_SCREENSHOT_MANAGER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h"
11 #include "content/common/content_export.h"
13 class SkBitmap;
15 namespace content {
17 class NavigationControllerImpl;
18 class NavigationEntryImpl;
19 class RenderViewHost;
20 class ScreenshotData;
22 // NavigationEntryScreenshotManager takes care of taking image-captures for the
23 // current navigation entry of a NavigationControllerImpl, and managing these
24 // captured images. These image-captures are used for history navigation using
25 // overscroll gestures.
26 class CONTENT_EXPORT NavigationEntryScreenshotManager {
27 public:
28 explicit NavigationEntryScreenshotManager(
29 NavigationControllerImpl* controller);
30 virtual ~NavigationEntryScreenshotManager();
32 // Takes a screenshot of the last-committed entry of the controller.
33 void TakeScreenshot();
35 // Clears screenshots of all navigation entries.
36 void ClearAllScreenshots();
38 protected:
39 virtual void TakeScreenshotImpl(RenderViewHost* host,
40 NavigationEntryImpl* entry);
42 // Called after a screenshot has been set on an NavigationEntryImpl.
43 // Overridden in tests to get notified of when a screenshot is set.
44 virtual void OnScreenshotSet(NavigationEntryImpl* entry);
46 NavigationControllerImpl* owner() { return owner_; }
48 void SetMinScreenshotIntervalMS(int interval_ms);
50 // The callback invoked when taking the screenshot of the page is complete.
51 // This sets the screenshot on the navigation entry.
52 void OnScreenshotTaken(int unique_id,
53 bool success,
54 const SkBitmap& bitmap);
56 // Returns the number of entries with screenshots.
57 int GetScreenshotCount() const;
59 private:
60 // This is called when the screenshot data has beene encoded to PNG in a
61 // worker thread.
62 void OnScreenshotEncodeComplete(int unique_id,
63 scoped_refptr<ScreenshotData> data);
65 // Removes the screenshot for the entry, returning true if the entry had a
66 // screenshot.
67 bool ClearScreenshot(NavigationEntryImpl* entry);
69 // The screenshots in the NavigationEntryImpls can accumulate and consume a
70 // large amount of memory. This function makes sure that the memory
71 // consumption is within a certain limit.
72 void PurgeScreenshotsIfNecessary();
74 // The navigation controller that owns this screenshot-manager.
75 NavigationControllerImpl* owner_;
77 // 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
79 // does not trigger on a destroyed NavigationEntryScreenshotManager.
80 base::WeakPtrFactory<NavigationEntryScreenshotManager> screenshot_factory_;
82 base::Time last_screenshot_time_;
83 int min_screenshot_interval_ms_;
85 DISALLOW_COPY_AND_ASSIGN(NavigationEntryScreenshotManager);
88 } // namespace content
90 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_SCREENSHOT_MANAGER_H_