1 // Copyright (c) 2012 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 CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_
6 #define CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_
8 #include "ash/screenshot_delegate.h"
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/time/time.h"
16 #include "chrome/browser/notifications/notification.h"
22 class ScreenshotTakerTest
;
29 class ScreenshotTakerObserver
{
32 SCREENSHOT_SUCCESS
= 0,
33 SCREENSHOT_GRABWINDOW_PARTIAL_FAILED
,
34 SCREENSHOT_GRABWINDOW_FULL_FAILED
,
35 SCREENSHOT_CREATE_DIR_FAILED
,
36 SCREENSHOT_GET_DIR_FAILED
,
37 SCREENSHOT_CHECK_DIR_FAILED
,
38 SCREENSHOT_CREATE_FILE_FAILED
,
39 SCREENSHOT_WRITE_FILE_FAILED
,
41 SCREENSHOT_RESULT_COUNT
44 virtual void OnScreenshotCompleted(
45 Result screenshot_result
,
46 const base::FilePath
& screenshot_path
) = 0;
49 virtual ~ScreenshotTakerObserver() {}
52 class ScreenshotTaker
: public ash::ScreenshotDelegate
{
56 virtual ~ScreenshotTaker();
58 // Overridden from ash::ScreenshotDelegate:
59 virtual void HandleTakeScreenshotForAllRootWindows() OVERRIDE
;
60 virtual void HandleTakePartialScreenshot(aura::Window
* window
,
61 const gfx::Rect
& rect
) OVERRIDE
;
62 virtual bool CanTakeScreenshot() OVERRIDE
;
64 void ShowNotification(
65 ScreenshotTakerObserver::Result screenshot_result
,
66 const base::FilePath
& screenshot_path
);
68 void AddObserver(ScreenshotTakerObserver
* observer
);
69 void RemoveObserver(ScreenshotTakerObserver
* observer
);
70 bool HasObserver(ScreenshotTakerObserver
* observer
) const;
73 friend class ash::test::ScreenshotTakerTest
;
75 void GrabWindowSnapshotAsyncCallback(
76 base::FilePath screenshot_path
,
79 scoped_refptr
<base::RefCountedBytes
> png_data
);
80 void GrabPartialWindowSnapshotAsync(aura::Window
* window
,
81 const gfx::Rect
& snapshot_bounds
,
83 base::FilePath screenshot_path
);
84 void GrabFullWindowSnapshotAsync(aura::Window
* window
,
85 const gfx::Rect
& snapshot_bounds
,
87 base::FilePath screenshot_path
,
90 Profile
* GetProfile();
91 void SetScreenshotDirectoryForTest(const base::FilePath
& directory
);
92 void SetScreenshotBasenameForTest(const std::string
& basename
);
93 void SetScreenshotProfileForTest(Profile
* profile
);
95 Notification
* CreateNotification(
96 ScreenshotTakerObserver::Result screenshot_result
,
97 const base::FilePath
& screenshot_path
);
99 base::WeakPtrFactory
<ScreenshotTaker
> factory_
;
101 // The timestamp when the screenshot task was issued last time.
102 base::Time last_screenshot_timestamp_
;
104 ObserverList
<ScreenshotTakerObserver
> observers_
;
106 base::FilePath screenshot_directory_for_test_
;
107 std::string screenshot_basename_for_test_
;
108 Profile
* profile_for_test_
;
110 DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker
);
113 #endif // CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_