Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 UI_SNAPSHOT_SCREENSHOT_TAKER_H_ | |
| 6 #define UI_SNAPSHOT_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 #include "ui/snapshot/snapshot_export.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class TaskRunner; | |
| 22 } | |
| 23 | |
| 24 namespace ui { | |
| 25 | |
| 26 class SNAPSHOT_EXPORT ScreenshotTakerObserver { | |
|
sky
2014/11/20 15:03:59
move to its own file.
flackr
2014/11/26 18:05:08
Done.
| |
| 27 public: | |
| 28 enum Result { | |
| 29 SCREENSHOT_SUCCESS = 0, | |
| 30 SCREENSHOT_GRABWINDOW_PARTIAL_FAILED, | |
| 31 SCREENSHOT_GRABWINDOW_FULL_FAILED, | |
| 32 SCREENSHOT_CREATE_DIR_FAILED, | |
| 33 SCREENSHOT_GET_DIR_FAILED, | |
| 34 SCREENSHOT_CHECK_DIR_FAILED, | |
| 35 SCREENSHOT_CREATE_FILE_FAILED, | |
| 36 SCREENSHOT_WRITE_FILE_FAILED, | |
| 37 SCREENSHOTS_DISABLED, | |
| 38 SCREENSHOT_RESULT_COUNT | |
| 39 }; | |
| 40 | |
| 41 // Dispatched after attempting to take a screenshot with the |result| and | |
| 42 // |screenshot_path| of the taken screenshot (if successful). | |
| 43 virtual void OnScreenshotCompleted(Result screenshot_result, | |
| 44 const base::FilePath& screenshot_path) = 0; | |
| 45 | |
| 46 protected: | |
| 47 virtual ~ScreenshotTakerObserver() {} | |
| 48 }; | |
| 49 | |
| 50 // TODO(flackr): Componentize google drive so that we don't need the | |
| 51 // ScreenshotTakerClient. | |
| 52 class SNAPSHOT_EXPORT ScreenshotTakerClient { | |
|
sky
2014/11/20 15:03:59
'taker' should sounds like bad english. Did you co
flackr
2014/11/26 18:05:09
Done.
| |
| 53 public: | |
| 54 enum WritableFileResult { | |
|
sky
2014/11/20 15:03:59
'Writable' is rather extraneous and confusing here
flackr
2014/11/26 18:05:08
Done.
| |
| 55 WRITABLE_FILE_SUCCESS, | |
| 56 WRITABLE_FILE_CHECK_DIR_FAILED, | |
| 57 WRITABLE_FILE_CREATE_DIR_FAILED, | |
| 58 WRITABLE_FILE_CREATE_FAILED | |
| 59 }; | |
| 60 | |
| 61 // Callback called with the |result| of trying to create a local writable | |
| 62 // |path| for the possibly remote path. | |
| 63 typedef base::Callback<void(WritableFileResult result, | |
|
sky
2014/11/20 15:03:59
using.
flackr
2014/11/26 18:05:09
Done.
| |
| 64 const base::FilePath& path)> WritableFileCallback; | |
| 65 | |
| 66 ScreenshotTakerClient() {} | |
| 67 virtual ~ScreenshotTakerClient() {} | |
| 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( | |
|
sky
2014/11/20 15:03:59
PrepareFileAndRun...
flackr
2014/11/26 18:05:09
Done.
| |
| 73 const base::FilePath& path, | |
| 74 scoped_refptr<base::TaskRunner> blocking_task_runner, | |
| 75 WritableFileCallback callback_on_blocking_pool); | |
|
sky
2014/11/20 15:03:59
const&?
flackr
2014/11/26 18:05:09
Done.
| |
| 76 }; | |
| 77 | |
| 78 class SNAPSHOT_EXPORT ScreenshotTaker { | |
| 79 public: | |
| 80 ScreenshotTaker(ScreenshotTakerClient* client, | |
| 81 scoped_refptr<base::TaskRunner> blocking_task_runner); | |
| 82 ~ScreenshotTaker(); | |
| 83 | |
| 84 void TakeScreenshot(gfx::NativeWindow window, | |
| 85 const gfx::Rect& rect, | |
|
sky
2014/11/20 15:03:59
It's not clear what coordinates rect is in. Please
flackr
2014/11/26 18:05:08
Done.
| |
| 86 const base::FilePath& screenshot_paths); | |
|
sky
2014/11/20 15:03:59
screenshot_path
flackr
2014/11/26 18:05:09
Done.
| |
| 87 bool CanTakeScreenshot(); | |
| 88 | |
| 89 void NotifyScreenshotCompleted( | |
| 90 ScreenshotTakerObserver::Result screenshot_result, | |
| 91 const base::FilePath& screenshot_path); | |
| 92 | |
| 93 void AddObserver(ScreenshotTakerObserver* observer); | |
| 94 void RemoveObserver(ScreenshotTakerObserver* observer); | |
| 95 bool HasObserver(const ScreenshotTakerObserver* observer) const; | |
| 96 | |
| 97 private: | |
| 98 void GrabWindowSnapshotAsyncCallback( | |
| 99 const std::string& window_identifier, | |
| 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_; | |
|
sky
2014/11/20 15:03:59
timeticks
flackr
2014/11/26 18:05:09
Done.
| |
| 109 | |
| 110 // Task runner for blocking tasks. | |
| 111 scoped_refptr<base::TaskRunner> blocking_task_runner_; | |
| 112 | |
| 113 ObserverList<ScreenshotTakerObserver> observers_; | |
| 114 base::WeakPtrFactory<ScreenshotTaker> factory_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker); | |
| 117 }; | |
| 118 | |
| 119 } // namespace ui | |
| 120 | |
| 121 #endif // UI_SNAPSHOT_SCREENSHOT_TAKER_H_ | |
| OLD | NEW |