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

Side by Side Diff: ui/snapshot/screenshot_grabber.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: Merge and fix gn Created 6 years 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 unified diff | Download patch
« no previous file with comments | « ui/snapshot/BUILD.gn ('k') | ui/snapshot/screenshot_grabber.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_GRABBER_H_
6 #define UI_SNAPSHOT_SCREENSHOT_GRABBER_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted_memory.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/time/time.h"
17 #include "ui/aura/window.h"
18 #include "ui/gfx/rect.h"
19 #include "ui/snapshot/screenshot_grabber_observer.h"
20 #include "ui/snapshot/snapshot_export.h"
21
22 namespace base {
23 class TaskRunner;
24 }
25
26 namespace ui {
27
28 // TODO(flackr): Componentize google drive so that we don't need the
29 // ScreenshotGrabberDelegate.
30 class SNAPSHOT_EXPORT ScreenshotGrabberDelegate {
31 public:
32 enum FileResult {
33 FILE_SUCCESS,
34 FILE_CHECK_DIR_FAILED,
35 FILE_CREATE_DIR_FAILED,
36 FILE_CREATE_FAILED
37 };
38
39 // Callback called with the |result| of trying to create a local writable
40 // |path| for the possibly remote path.
41 using FileCallback =
42 base::Callback<void(FileResult result, const base::FilePath& path)>;
43
44 ScreenshotGrabberDelegate() {}
45 virtual ~ScreenshotGrabberDelegate() {}
46
47 // Prepares a writable file for |path|. If |path| is a non-local path (i.e.
48 // Google drive) and it is supported this will create a local cached copy of
49 // the remote file and call the callback with the local path.
50 virtual void PrepareFileAndRunOnBlockingPool(
51 const base::FilePath& path,
52 scoped_refptr<base::TaskRunner> blocking_task_runner,
53 const FileCallback& callback_on_blocking_pool);
54 };
55
56 class SNAPSHOT_EXPORT ScreenshotGrabber {
57 public:
58 ScreenshotGrabber(ScreenshotGrabberDelegate* client,
59 scoped_refptr<base::TaskRunner> blocking_task_runner);
60 ~ScreenshotGrabber();
61
62 // Takes a screenshot of |rect| in |window| in that window's coordinate space
63 // saving the result to |screenshot_path|.
64 void TakeScreenshot(gfx::NativeWindow window,
65 const gfx::Rect& rect,
66 const base::FilePath& screenshot_path);
67 bool CanTakeScreenshot();
68
69 void NotifyScreenshotCompleted(
70 ScreenshotGrabberObserver::Result screenshot_result,
71 const base::FilePath& screenshot_path);
72
73 void AddObserver(ScreenshotGrabberObserver* observer);
74 void RemoveObserver(ScreenshotGrabberObserver* observer);
75 bool HasObserver(const ScreenshotGrabberObserver* observer) const;
76
77 private:
78 void GrabWindowSnapshotAsyncCallback(
79 const std::string& window_identifier,
80 base::FilePath screenshot_path,
81 bool is_partial,
82 scoped_refptr<base::RefCountedBytes> png_data);
83
84 // A weak pointer to the screenshot taker client.
85 ScreenshotGrabberDelegate* client_;
86
87 // The timestamp when the screenshot task was issued last time.
88 base::TimeTicks last_screenshot_timestamp_;
89
90 // Task runner for blocking tasks.
91 scoped_refptr<base::TaskRunner> blocking_task_runner_;
92
93 ObserverList<ScreenshotGrabberObserver> observers_;
94 base::WeakPtrFactory<ScreenshotGrabber> factory_;
95
96 DISALLOW_COPY_AND_ASSIGN(ScreenshotGrabber);
97 };
98
99 } // namespace ui
100
101 #endif // UI_SNAPSHOT_SCREENSHOT_GRABBER_H_
OLDNEW
« no previous file with comments | « ui/snapshot/BUILD.gn ('k') | ui/snapshot/screenshot_grabber.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698