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

Unified Diff: components/screenshot_taker/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: Restrict to use_aura==1 and fix gn build 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: components/screenshot_taker/screenshot_taker.h
diff --git a/components/screenshot_taker/screenshot_taker.h b/components/screenshot_taker/screenshot_taker.h
new file mode 100644
index 0000000000000000000000000000000000000000..41726593f69520c49fd8e21e1cbada321cc9ae1d
--- /dev/null
+++ b/components/screenshot_taker/screenshot_taker.h
@@ -0,0 +1,116 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
oshima 2014/11/12 11:32:14 nit: 2014
flackr 2014/11/18 16:46:30 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_SCREENSHOT_TAKER_SCREENSHOT_TAKER_H_
+#define COMPONENTS_SCREENSHOT_TAKER_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"
+
+class Profile;
oshima 2014/11/12 11:32:14 you don't need this right?
flackr 2014/11/18 16:46:30 Done.
+
+class ScreenshotTakerTest;
+
+namespace aura {
+class Window;
+}
+
+class 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 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;
+
+ // 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,
+ WritableFileCallback callback_on_blocking_pool);
+};
oshima 2014/11/12 11:32:14 virtual dtor
flackr 2014/11/18 16:46:30 Done.
+
+class ScreenshotTaker {
+ public:
+ ScreenshotTaker(ScreenshotTakerClient* client);
+ ~ScreenshotTaker();
+
+ void TakeScreenshot(aura::Window* window,
+ const gfx::Rect& rect,
+ const base::FilePath& screenshot_paths);
+ bool CanTakeScreenshot();
+
+ void AddObserver(ScreenshotTakerObserver* observer);
+ void RemoveObserver(ScreenshotTakerObserver* observer);
+ bool HasObserver(const ScreenshotTakerObserver* observer) const;
+
+ private:
+ friend class ScreenshotTakerTest;
+
+ void NotifyScreenshotCompleted(
+ ScreenshotTakerObserver::Result screenshot_result,
+ const base::FilePath& screenshot_path);
+
+ void GrabWindowSnapshotAsyncCallback(
+ const std::string& screen_bounds,
+ 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_;
+
+ ObserverList<ScreenshotTakerObserver> observers_;
+ base::WeakPtrFactory<ScreenshotTaker> factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker);
+};
+
+#endif // COMPONENTS_SCREENSHOT_TAKER_SCREENSHOT_TAKER_H_

Powered by Google App Engine
This is Rietveld 408576698