Chromium Code Reviews| 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 } |
| 17 | 27 |
| 18 class ScreenshotTaker : public ash::ScreenshotDelegate { | 28 class ScreenshotTakerObserver { |
| 19 public: | 29 public: |
| 20 ScreenshotTaker(); | 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, const base::FilePath& screenshot_path) = 0; | |
| 44 | |
| 45 protected: | |
| 46 virtual ~ScreenshotTakerObserver() {} | |
| 47 }; | |
| 48 | |
| 49 class ScreenshotTaker : public ash::ScreenshotDelegate | |
| 50 { | |
|
sky
2013/04/03 04:24:46
{ on previous line.
sschmitz
2013/04/03 17:57:40
old habits die hard;) Done.
| |
| 51 public: | |
| 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; |
|
James Cook
2013/04/02 22:47:18
I wish there was a way to pass the profile in here
sky
2013/04/03 04:24:46
This is invoked from ash, which doesn't know about
| |
| 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 // For test we override the screenshot directory and basename. |
| 31 // been taken. | 72 void OverrideScreenshotDirectory(const base::FilePath& directory); |
|
James Cook
2013/04/02 22:47:18
We usually call these SetScreenshotDirectoryForTes
sschmitz
2013/04/03 17:57:40
Done.
| |
| 32 void DisplayVisualFeedback(const gfx::Rect& rect); | 73 void OverrideScreenshotBasename(const std::string& basename); |
| 33 | 74 |
| 34 // Closes the visual feedback layer. | 75 Profile* profile_; |
| 35 void CloseVisualFeedbackLayer(); | 76 |
| 77 base::WeakPtrFactory<ScreenshotTaker> factory_; | |
| 36 | 78 |
| 37 // The timestamp when the screenshot task was issued last time. | 79 // The timestamp when the screenshot task was issued last time. |
| 38 base::Time last_screenshot_timestamp_; | 80 base::Time last_screenshot_timestamp_; |
| 39 | 81 |
| 40 // The flashing effect of the screen for the visual feedback when taking a | 82 ObserverList<ScreenshotTakerObserver> observers_; |
| 41 // screenshot. | 83 |
| 42 scoped_ptr<ui::Layer> visual_feedback_layer_; | 84 base::FilePath screenshot_directory_override_; |
| 85 std::string screenshot_basename_override_; | |
| 86 | |
| 87 friend class ash::test::ScreenshotTakerTest; | |
|
James Cook
2013/04/02 22:47:18
friends go at top of private section
sschmitz
2013/04/03 17:57:40
Done.
| |
| 43 | 88 |
| 44 DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker); | 89 DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker); |
| 45 }; | 90 }; |
| 46 | 91 |
| 47 #endif // CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ | 92 #endif // CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ |
| OLD | NEW |