Index: ui/snapshot/screenshot_taker.h |
diff --git a/ui/snapshot/screenshot_taker.h b/ui/snapshot/screenshot_taker.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..001ed518ed4d990279da178e9034f58f1ebb03d1 |
--- /dev/null |
+++ b/ui/snapshot/screenshot_taker.h |
@@ -0,0 +1,121 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef UI_SNAPSHOT_SCREENSHOT_TAKER_H_ |
+#define UI_SNAPSHOT_SCREENSHOT_TAKER_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "base/files/file_path.h" |
+#include "base/memory/ref_counted_memory.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/observer_list.h" |
+#include "base/time/time.h" |
+#include "ui/aura/window.h" |
+#include "ui/gfx/rect.h" |
+#include "ui/snapshot/snapshot_export.h" |
+ |
+namespace base { |
+class TaskRunner; |
+} |
+ |
+namespace ui { |
+ |
+class SNAPSHOT_EXPORT ScreenshotTakerObserver { |
+ public: |
+ enum Result { |
+ SCREENSHOT_SUCCESS = 0, |
+ SCREENSHOT_GRABWINDOW_PARTIAL_FAILED, |
+ SCREENSHOT_GRABWINDOW_FULL_FAILED, |
+ SCREENSHOT_CREATE_DIR_FAILED, |
+ SCREENSHOT_GET_DIR_FAILED, |
+ SCREENSHOT_CHECK_DIR_FAILED, |
+ SCREENSHOT_CREATE_FILE_FAILED, |
+ SCREENSHOT_WRITE_FILE_FAILED, |
+ SCREENSHOTS_DISABLED, |
+ SCREENSHOT_RESULT_COUNT |
+ }; |
+ |
+ // Dispatched after attempting to take a screenshot with the |result| and |
+ // |screenshot_path| of the taken screenshot (if successful). |
+ virtual void OnScreenshotCompleted(Result screenshot_result, |
+ const base::FilePath& screenshot_path) = 0; |
+ |
+ protected: |
+ virtual ~ScreenshotTakerObserver() {} |
+}; |
+ |
+// TODO(flackr): Componentize google drive so that we don't need the |
+// ScreenshotTakerClient. |
+class SNAPSHOT_EXPORT ScreenshotTakerClient { |
+ public: |
+ enum WritableFileResult { |
+ WRITABLE_FILE_SUCCESS, |
+ WRITABLE_FILE_CHECK_DIR_FAILED, |
+ WRITABLE_FILE_CREATE_DIR_FAILED, |
+ WRITABLE_FILE_CREATE_FAILED |
+ }; |
+ |
+ // Callback called with the |result| of trying to create a local writable |
+ // |path| for the possibly remote path. |
+ typedef base::Callback<void(WritableFileResult result, |
+ const base::FilePath& path)> WritableFileCallback; |
+ |
+ ScreenshotTakerClient() {} |
+ virtual ~ScreenshotTakerClient() {} |
+ |
+ // Prepares a writable file for |path|. If |path| is a non-local path (i.e. |
+ // Google drive) and it is supported this will create a local cached copy of |
+ // the remote file and call the callback with the local path. |
+ virtual void PrepareWritableFileAndRunOnBlockingPool( |
+ const base::FilePath& path, |
+ scoped_refptr<base::TaskRunner> blocking_task_runner, |
+ WritableFileCallback callback_on_blocking_pool); |
+}; |
+ |
+class SNAPSHOT_EXPORT ScreenshotTaker { |
+ public: |
+ ScreenshotTaker(ScreenshotTakerClient* client, |
+ scoped_refptr<base::TaskRunner> blocking_task_runner); |
+ ~ScreenshotTaker(); |
+ |
+ void TakeScreenshot(gfx::NativeWindow window, |
+ const gfx::Rect& rect, |
+ const base::FilePath& screenshot_paths); |
+ bool CanTakeScreenshot(); |
+ |
+ void NotifyScreenshotCompleted( |
+ ScreenshotTakerObserver::Result screenshot_result, |
+ const base::FilePath& screenshot_path); |
+ |
+ void AddObserver(ScreenshotTakerObserver* observer); |
+ void RemoveObserver(ScreenshotTakerObserver* observer); |
+ bool HasObserver(const ScreenshotTakerObserver* observer) const; |
+ |
+ private: |
+ void GrabWindowSnapshotAsyncCallback( |
+ const std::string& window_identifier, |
+ base::FilePath screenshot_path, |
+ bool is_partial, |
+ scoped_refptr<base::RefCountedBytes> png_data); |
+ |
+ // A weak pointer to the screenshot taker client. |
+ ScreenshotTakerClient* client_; |
+ |
+ // The timestamp when the screenshot task was issued last time. |
+ base::Time last_screenshot_timestamp_; |
+ |
+ // Task runner for blocking tasks. |
+ scoped_refptr<base::TaskRunner> blocking_task_runner_; |
+ |
+ ObserverList<ScreenshotTakerObserver> observers_; |
+ base::WeakPtrFactory<ScreenshotTaker> factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker); |
+}; |
+ |
+} // namespace ui |
+ |
+#endif // UI_SNAPSHOT_SCREENSHOT_TAKER_H_ |