OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_UI_ASH_SCREENSHOT_TAKER_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ |
6 #define CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ | 6 #define CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ |
7 | 7 |
8 #include "ash/screenshot_delegate.h" | 8 #include "ash/screenshot_delegate.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.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" |
11 #include "base/time.h" | 15 #include "base/time.h" |
12 #include "ui/compositor/layer.h" | |
13 | 16 |
| 17 class Profile; |
| 18 |
| 19 namespace ash { |
| 20 namespace test { |
| 21 class ScreenshotTakerTest; |
| 22 } |
| 23 } |
14 namespace aura { | 24 namespace aura { |
15 class Window; | 25 class Window; |
16 } // namespace aura | 26 } |
| 27 |
| 28 class ScreenshotTakerObserver { |
| 29 public: |
| 30 enum Result { |
| 31 SCREENSHOT_SUCCESS = 0, |
| 32 SCREENSHOT_GRABWINDOW_PARTIAL_FAILED, |
| 33 SCREENSHOT_GRABWINDOW_FULL_FAILED, |
| 34 SCREENSHOT_CREATE_DIR_FAILED, |
| 35 SCREENSHOT_GET_DIR_FAILED, |
| 36 SCREENSHOT_CHECK_DIR_FAILED, |
| 37 SCREENSHOT_CREATE_FILE_FAILED, |
| 38 SCREENSHOT_WRITE_FILE_FAILED, |
| 39 SCREENSHOT_RESULT_COUNT |
| 40 }; |
| 41 |
| 42 virtual void OnScreenshotCompleted( |
| 43 Result screenshot_result, |
| 44 const base::FilePath& screenshot_path) = 0; |
| 45 |
| 46 protected: |
| 47 virtual ~ScreenshotTakerObserver() {} |
| 48 }; |
17 | 49 |
18 class ScreenshotTaker : public ash::ScreenshotDelegate { | 50 class ScreenshotTaker : public ash::ScreenshotDelegate { |
19 public: | 51 public: |
20 ScreenshotTaker(); | 52 explicit ScreenshotTaker(Profile* profile); |
| 53 |
21 virtual ~ScreenshotTaker(); | 54 virtual ~ScreenshotTaker(); |
22 | 55 |
23 // Overridden from ash::ScreenshotDelegate: | 56 // Overridden from ash::ScreenshotDelegate: |
24 virtual void HandleTakeScreenshotForAllRootWindows() OVERRIDE; | 57 virtual void HandleTakeScreenshotForAllRootWindows() OVERRIDE; |
25 virtual void HandleTakePartialScreenshot(aura::Window* window, | 58 virtual void HandleTakePartialScreenshot(aura::Window* window, |
26 const gfx::Rect& rect) OVERRIDE; | 59 const gfx::Rect& rect) OVERRIDE; |
27 virtual bool CanTakeScreenshot() OVERRIDE; | 60 virtual bool CanTakeScreenshot() OVERRIDE; |
28 | 61 |
| 62 void ShowNotification( |
| 63 ScreenshotTakerObserver::Result screenshot_result, |
| 64 const base::FilePath& screenshot_path); |
| 65 |
| 66 void AddObserver(ScreenshotTakerObserver* observer); |
| 67 void RemoveObserver(ScreenshotTakerObserver* observer); |
| 68 bool HasObserver(ScreenshotTakerObserver* observer) const; |
| 69 |
29 private: | 70 private: |
30 // Flashes the screen to provide visual feedback that a screenshot has | 71 friend class ash::test::ScreenshotTakerTest; |
31 // been taken. | |
32 void DisplayVisualFeedback(const gfx::Rect& rect); | |
33 | 72 |
34 // Closes the visual feedback layer. | 73 void SetScreenshotDirectoryForTest(const base::FilePath& directory); |
35 void CloseVisualFeedbackLayer(); | 74 void SetScreenshotBasenameForTest(const std::string& basename); |
| 75 |
| 76 Profile* profile_; |
| 77 |
| 78 base::WeakPtrFactory<ScreenshotTaker> factory_; |
36 | 79 |
37 // The timestamp when the screenshot task was issued last time. | 80 // The timestamp when the screenshot task was issued last time. |
38 base::Time last_screenshot_timestamp_; | 81 base::Time last_screenshot_timestamp_; |
39 | 82 |
40 // The flashing effect of the screen for the visual feedback when taking a | 83 ObserverList<ScreenshotTakerObserver> observers_; |
41 // screenshot. | 84 base::FilePath screenshot_directory_for_test_; |
42 scoped_ptr<ui::Layer> visual_feedback_layer_; | 85 std::string screenshot_basename_for_test_; |
43 | 86 |
44 DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker); | 87 DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker); |
45 }; | 88 }; |
46 | 89 |
47 #endif // CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ | 90 #endif // CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ |
OLD | NEW |