OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef COMPONENTS_SCREENSHOT_TAKER_SCREENSHOT_TAKER_H_ |
| 6 #define COMPONENTS_SCREENSHOT_TAKER_SCREENSHOT_TAKER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/ref_counted_memory.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 "ui/aura/window.h" |
| 17 #include "ui/gfx/rect.h" |
| 18 |
| 19 class Profile; |
| 20 |
| 21 class ScreenshotTakerTest; |
| 22 |
| 23 namespace aura { |
| 24 class Window; |
| 25 } |
| 26 |
| 27 class ScreenshotTakerObserver { |
| 28 public: |
| 29 enum Result { |
| 30 SCREENSHOT_SUCCESS = 0, |
| 31 SCREENSHOT_GRABWINDOW_PARTIAL_FAILED, |
| 32 SCREENSHOT_GRABWINDOW_FULL_FAILED, |
| 33 SCREENSHOT_CREATE_DIR_FAILED, |
| 34 SCREENSHOT_GET_DIR_FAILED, |
| 35 SCREENSHOT_CHECK_DIR_FAILED, |
| 36 SCREENSHOT_CREATE_FILE_FAILED, |
| 37 SCREENSHOT_WRITE_FILE_FAILED, |
| 38 SCREENSHOTS_DISABLED, |
| 39 SCREENSHOT_RESULT_COUNT |
| 40 }; |
| 41 |
| 42 // Dispatched after attempting to take a screenshot with the |result| and |
| 43 // |screenshot_path| of the taken screenshot (if successful). |
| 44 virtual void OnScreenshotCompleted( |
| 45 Result screenshot_result, |
| 46 const base::FilePath& screenshot_path) = 0; |
| 47 |
| 48 protected: |
| 49 virtual ~ScreenshotTakerObserver() {} |
| 50 }; |
| 51 |
| 52 // TODO(flackr): Componentize google drive so that we don't need the |
| 53 // ScreenshotTakerClient. |
| 54 class ScreenshotTakerClient { |
| 55 public: |
| 56 enum WritableFileResult { |
| 57 WRITABLE_FILE_SUCCESS, |
| 58 WRITABLE_FILE_CHECK_DIR_FAILED, |
| 59 WRITABLE_FILE_CREATE_DIR_FAILED, |
| 60 WRITABLE_FILE_CREATE_FAILED |
| 61 }; |
| 62 |
| 63 // Callback called with the |result| of trying to create a local writable |
| 64 // |path| for the possibly remote path. |
| 65 typedef base::Callback<void (WritableFileResult result, |
| 66 const base::FilePath& path)> |
| 67 WritableFileCallback; |
| 68 |
| 69 // Prepares a writable file for |path|. If |path| is a non-local path (i.e. |
| 70 // Google drive) and it is supported this will create a local cached copy of |
| 71 // the remote file and call the callback with the local path. |
| 72 virtual void PrepareWritableFileAndRunOnBlockingPool( |
| 73 const base::FilePath& path, |
| 74 WritableFileCallback callback_on_blocking_pool); |
| 75 }; |
| 76 |
| 77 class ScreenshotTaker { |
| 78 public: |
| 79 ScreenshotTaker(ScreenshotTakerClient* client); |
| 80 ~ScreenshotTaker(); |
| 81 |
| 82 void TakeScreenshot(aura::Window* window, |
| 83 const gfx::Rect& rect, |
| 84 const base::FilePath& screenshot_paths); |
| 85 bool CanTakeScreenshot(); |
| 86 |
| 87 void NotifyScreenshotCompleted( |
| 88 ScreenshotTakerObserver::Result screenshot_result, |
| 89 const base::FilePath& screenshot_path); |
| 90 |
| 91 void AddObserver(ScreenshotTakerObserver* observer); |
| 92 void RemoveObserver(ScreenshotTakerObserver* observer); |
| 93 bool HasObserver(const ScreenshotTakerObserver* observer) const; |
| 94 |
| 95 private: |
| 96 friend class ScreenshotTakerTest; |
| 97 |
| 98 void GrabWindowSnapshotAsyncCallback( |
| 99 const std::string& screen_bounds, |
| 100 base::FilePath screenshot_path, |
| 101 bool is_partial, |
| 102 scoped_refptr<base::RefCountedBytes> png_data); |
| 103 |
| 104 // A weak pointer to the screenshot taker client. |
| 105 ScreenshotTakerClient* client_; |
| 106 |
| 107 // The timestamp when the screenshot task was issued last time. |
| 108 base::Time last_screenshot_timestamp_; |
| 109 |
| 110 ObserverList<ScreenshotTakerObserver> observers_; |
| 111 base::WeakPtrFactory<ScreenshotTaker> factory_; |
| 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker); |
| 114 }; |
| 115 |
| 116 #endif // COMPONENTS_SCREENSHOT_TAKER_SCREENSHOT_TAKER_H_ |
OLD | NEW |