| 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..d50a37497199f31d26d0615b54ccc5b29ea1f396
|
| --- /dev/null
|
| +++ b/components/screenshot_taker/screenshot_taker.h
|
| @@ -0,0 +1,116 @@
|
| +// Copyright (c) 2012 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 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;
|
| +
|
| +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);
|
| +};
|
| +
|
| +class ScreenshotTaker {
|
| + public:
|
| + ScreenshotTaker(ScreenshotTakerClient* client);
|
| + ~ScreenshotTaker();
|
| +
|
| + void TakeScreenshot(aura::Window* 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:
|
| + friend class ScreenshotTakerTest;
|
| +
|
| + 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_
|
|
|