Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Unified Diff: ui/snapshot/screenshot_taker.h

Issue 706013004: Move non-browser specific ScreenshotTaker code to ui/snapshot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move screenshot_taker to ui/snapshot/ Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698