capture_mode_controller.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. // Copyright 2020 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. #ifndef ASH_CAPTURE_MODE_CAPTURE_MODE_CONTROLLER_H_
  5. #define ASH_CAPTURE_MODE_CAPTURE_MODE_CONTROLLER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "ash/ash_export.h"
  9. #include "ash/capture_mode/capture_mode_metrics.h"
  10. #include "ash/capture_mode/capture_mode_types.h"
  11. #include "ash/capture_mode/video_recording_watcher.h"
  12. #include "ash/public/cpp/capture_mode/capture_mode_delegate.h"
  13. #include "ash/public/cpp/session/session_observer.h"
  14. #include "ash/services/recording/public/mojom/recording_service.mojom.h"
  15. #include "base/callback_forward.h"
  16. #include "base/files/file_path.h"
  17. #include "base/memory/ref_counted_memory.h"
  18. #include "base/memory/scoped_refptr.h"
  19. #include "base/memory/weak_ptr.h"
  20. #include "base/time/time.h"
  21. #include "base/timer/timer.h"
  22. #include "chromeos/dbus/power/power_manager_client.h"
  23. #include "mojo/public/cpp/bindings/pending_receiver.h"
  24. #include "mojo/public/cpp/bindings/remote.h"
  25. #include "services/viz/privileged/mojom/compositing/frame_sink_video_capture.mojom-forward.h"
  26. #include "third_party/abseil-cpp/absl/types/optional.h"
  27. #include "ui/gfx/geometry/rect.h"
  28. #include "ui/gfx/image/image.h"
  29. class PrefRegistrySimple;
  30. namespace base {
  31. class FilePath;
  32. class Time;
  33. class SequencedTaskRunner;
  34. } // namespace base
  35. namespace ash {
  36. class CaptureModeCameraController;
  37. class CaptureModeSession;
  38. // Defines a callback type that will be invoked when an attempt to delete the
  39. // given `path` is completed with the given status `delete_successful`.
  40. using OnFileDeletedCallback =
  41. base::OnceCallback<void(const base::FilePath& path,
  42. bool delete_successful)>;
  43. // Controls starting and ending a Capture Mode session and its behavior. There
  44. // are various checks that are run when a capture session start is attempted,
  45. // and when a capture operation is performed, to make sure they're allowed. For
  46. // example, checking that policy allows screen capture, and there are no content
  47. // on the screen restricted by DLP (Data Leak Prevention). In the case of video
  48. // recording, HDCP is also checked to ensure no protected content is being
  49. // recorded.
  50. class ASH_EXPORT CaptureModeController
  51. : public recording::mojom::RecordingServiceClient,
  52. public recording::mojom::DriveFsQuotaDelegate,
  53. public SessionObserver,
  54. public chromeos::PowerManagerClient::Observer {
  55. public:
  56. // Contains info about the folder used for saving the captured images and
  57. // videos.
  58. struct CaptureFolder {
  59. // The absolute path of the folder used for saving the captures.
  60. base::FilePath path;
  61. // True if the above `path` is the default "Downloads" folder on the device.
  62. bool is_default_downloads_folder = false;
  63. };
  64. explicit CaptureModeController(std::unique_ptr<CaptureModeDelegate> delegate);
  65. CaptureModeController(const CaptureModeController&) = delete;
  66. CaptureModeController& operator=(const CaptureModeController&) = delete;
  67. ~CaptureModeController() override;
  68. // Convenience function to get the controller instance, which is created and
  69. // owned by Shell.
  70. static CaptureModeController* Get();
  71. static void RegisterProfilePrefs(PrefRegistrySimple* registry);
  72. CaptureModeCameraController* camera_controller() {
  73. return camera_controller_.get();
  74. }
  75. CaptureModeType type() const { return type_; }
  76. CaptureModeSource source() const { return source_; }
  77. CaptureModeSession* capture_mode_session() const {
  78. return capture_mode_session_.get();
  79. }
  80. gfx::Rect user_capture_region() const { return user_capture_region_; }
  81. bool enable_audio_recording() const { return enable_audio_recording_; }
  82. bool is_recording_in_progress() const {
  83. return is_initializing_recording_ ||
  84. (video_recording_watcher_ &&
  85. !video_recording_watcher_->is_shutting_down());
  86. }
  87. // Returns true if a capture mode session is currently active. If you only
  88. // need to call this method, but don't need the rest of the controller, use
  89. // capture_mode_util::IsCaptureModeActive().
  90. bool IsActive() const;
  91. // Sets the capture source/type, which will be applied to an ongoing capture
  92. // session (if any), or to a future capture session when Start() is called.
  93. void SetSource(CaptureModeSource source);
  94. void SetType(CaptureModeType type);
  95. // Sets the audio recording flag, which will be applied to any future
  96. // recordings (cannot be set mid recording), or to a future capture mode
  97. // session when Start() is called.
  98. void EnableAudioRecording(bool enable_audio_recording);
  99. // Starts a new capture session with the most-recently used |type_| and
  100. // |source_|. Also records what |entry_type| that started capture mode.
  101. void Start(CaptureModeEntryType entry_type);
  102. // Stops an existing capture session.
  103. void Stop();
  104. // Sets the user capture region. If it's non-empty and changed by the user,
  105. // update |last_capture_region_update_time_|.
  106. void SetUserCaptureRegion(const gfx::Rect& region, bool by_user);
  107. // Returns true if we can show a user nudge animation and a toast message to
  108. // alert users any available new features.
  109. bool CanShowUserNudge() const;
  110. // Disables showing the user nudge from now on. Calling the above
  111. // CanShowUserNudge() will return false for the current active user going
  112. // forward.
  113. void DisableUserNudgeForever();
  114. // Sets whether the currently logged in user selected to use the default
  115. // "Downloads" folder as the current save location, even while they already
  116. // have a currently set custom folder. When this setting is true, any
  117. // currently set custom folder is ignored but not removed.
  118. // This can only be called when user is logged in.
  119. void SetUsesDefaultCaptureFolder(bool value);
  120. // Sets the given |path| as the custom save location of captured images and
  121. // videos for the currently logged in user. Setting an empty |path| clears any
  122. // custom selected folder resulting in using the default downloads folder.
  123. // Calling this function will reset the value of "UsesDefaultCaptureFolder" to
  124. // false, since it means the user wants to switch to a custom folder when it's
  125. // set.
  126. // This can only be called when user is logged in.
  127. void SetCustomCaptureFolder(const base::FilePath& path);
  128. base::FilePath GetCustomCaptureFolder() const;
  129. // Returns the folder in which all taken screenshots and videos will be saved.
  130. // It can be the temp directory if the user is not logged in, the default
  131. // "Downloads" folder, or a user-selected custom location.
  132. CaptureFolder GetCurrentCaptureFolder() const;
  133. // Full screen capture for each available display if no restricted
  134. // content exists on that display, each capture is saved as an individual
  135. // file. Note: this won't start a capture mode session.
  136. void CaptureScreenshotsOfAllDisplays();
  137. // Called only while a capture session is in progress to perform the actual
  138. // capture depending on the current selected |source_| and |type_|, and ends
  139. // the capture session.
  140. void PerformCapture();
  141. void EndVideoRecording(EndRecordingReason reason);
  142. // Posts a task to the blocking pool to check the availability of the given
  143. // `folder` and replies back asynchronously by calling the given `callback`
  144. // with `available` set either to true or false.
  145. void CheckFolderAvailability(
  146. const base::FilePath& folder,
  147. base::OnceCallback<void(bool available)> callback);
  148. // Sets the |protection_mask| that is currently set on the given |window|. If
  149. // the |protection_mask| is |display::CONTENT_PROTECTION_METHOD_NONE|, then
  150. // the window will no longer be tracked.
  151. // Note that content protection (a.k.a. HDCP (High-bandwidth Digital Content
  152. // Protection)) is different from DLP (Data Leak Prevention). The latter is
  153. // enforced by admins and applies to both image and video capture, whereas
  154. // the former is enforced by apps and content providers and is applied only to
  155. // video capture.
  156. void SetWindowProtectionMask(aura::Window* window, uint32_t protection_mask);
  157. // If a video recording is in progress, it will end if so required by content
  158. // protection.
  159. void RefreshContentProtection();
  160. // Toggles the recording overlay on or off. When on, the recording overlay
  161. // widget's window will be shown and can consume all the events targeting the
  162. // window being recorded. Otherwise, it's hidden and cannot accept any events.
  163. // This can only be called while recording is in progress for a Projector
  164. // session.
  165. void ToggleRecordingOverlayEnabled();
  166. // Returns a new instance of the concrete view that will be used as the
  167. // content view of the recording overlay widget.
  168. std::unique_ptr<RecordingOverlayView> CreateRecordingOverlayView();
  169. // Returns true if the given `path` is the root folder of DriveFS, false
  170. // otherwise.
  171. bool IsRootDriveFsPath(const base::FilePath& path) const;
  172. // Returns true if the given `path` is the same as the Android Play files
  173. // path, false otherwise.
  174. bool IsAndroidFilesPath(const base::FilePath& path) const;
  175. // Returns true if the given `path` is the same as the Linux Files path, false
  176. // otherwise.
  177. bool IsLinuxFilesPath(const base::FilePath& path) const;
  178. // Returns the current parent window for
  179. // `CaptureModeCameraController::camera_preview_widget_`.
  180. aura::Window* GetCameraPreviewParentWindow() const;
  181. // Returns the camera preview's confine bounds, which actually indicates the
  182. // bounds of the surface that will be recorded. The bounds is in screen
  183. // coordinate when capture source is `kFullscreen` or 'kRegion', but in
  184. // window's coordinate when it is 'kWindow' type.
  185. gfx::Rect GetCameraPreviewConfineBounds() const;
  186. // recording::mojom::RecordingServiceClient:
  187. void OnRecordingEnded(recording::mojom::RecordingStatus status,
  188. const gfx::ImageSkia& thumbnail) override;
  189. // recording::mojom::DriveFsQuotaDelegate:
  190. void GetDriveFsFreeSpaceBytes(
  191. GetDriveFsFreeSpaceBytesCallback callback) override;
  192. // SessionObserver:
  193. void OnActiveUserSessionChanged(const AccountId& account_id) override;
  194. void OnSessionStateChanged(session_manager::SessionState state) override;
  195. void OnChromeTerminating() override;
  196. // chromeos::PowerManagerClient::Observer:
  197. void SuspendImminent(power_manager::SuspendImminent::Reason reason) override;
  198. // Skips the 3-second count down, and IsCaptureAllowed() checks, and starts
  199. // video recording right away for testing purposes.
  200. void StartVideoRecordingImmediatelyForTesting();
  201. CaptureModeDelegate* delegate_for_testing() const { return delegate_.get(); }
  202. VideoRecordingWatcher* video_recording_watcher_for_testing() const {
  203. return video_recording_watcher_.get();
  204. }
  205. private:
  206. friend class CaptureModeTestApi;
  207. friend class VideoRecordingWatcher;
  208. // Called by |video_recording_watcher_| when the display on which recording is
  209. // happening changes its bounds such as on display rotation or device scale
  210. // factor changes. In this case we push the new |root_size| in DIPs, and the
  211. // |device_scale_factor| to the recording service so that it can update the
  212. // video size. Note that we do this only when recording a window or a partial
  213. // region. When recording a fullscreen, the capturer can handle these changes
  214. // and would center and letter-box the video frames within the requested size.
  215. void PushNewRootSizeToRecordingService(const gfx::Size& root_size,
  216. float device_scale_factor);
  217. // Called by |video_recording_watcher_| to inform us that the |window| being
  218. // recorded (i.e. |is_recording_in_progress()| is true) is about to move to a
  219. // |new_root|. This is needed so we can inform the recording service of this
  220. // change so that it can switch its capture target to the new root's frame
  221. // sink.
  222. void OnRecordedWindowChangingRoot(aura::Window* window,
  223. aura::Window* new_root);
  224. // Called by |video_recording_watcher_| to inform us that the size of the
  225. // |window| being recorded was changed to |new_size| in DIPs. This is pushed
  226. // to the recording service in order to update the video dimensions.
  227. void OnRecordedWindowSizeChanged(const gfx::Size& new_size);
  228. // Returns true if screen recording needs to be blocked due to protected
  229. // content. |window| is the window being recorded or desired to be recorded.
  230. bool ShouldBlockRecordingForContentProtection(aura::Window* window) const;
  231. // Used by user session change, and suspend events to end the capture mode
  232. // session if it's active, or stop the video recording if one is in progress.
  233. void EndSessionOrRecording(EndRecordingReason reason);
  234. // Returns the capture parameters for the capture operation that is about to
  235. // be performed (i.e. the window to be captured, and the capture bounds). If
  236. // nothing is to be captured (e.g. when there's no window selected in a
  237. // kWindow source, or no region is selected in a kRegion source), then a
  238. // absl::nullopt is returned.
  239. struct CaptureParams {
  240. aura::Window* window = nullptr;
  241. // The capture bounds, either in root coordinates (in kFullscreen or kRegion
  242. // capture sources), or window-local coordinates (in a kWindow capture
  243. // source).
  244. gfx::Rect bounds;
  245. };
  246. absl::optional<CaptureParams> GetCaptureParams() const;
  247. // Launches the mojo service that handles audio and video recording, and
  248. // begins recording according to the given |capture_params|. It creates an
  249. // overlay on the video capturer so that can be used to record the mouse
  250. // cursor. It gives the pending receiver end to that overlay on Viz, and the
  251. // other end should be owned by the |video_recording_watcher_|.
  252. void LaunchRecordingServiceAndStartRecording(
  253. const CaptureParams& capture_params,
  254. mojo::PendingReceiver<viz::mojom::FrameSinkVideoCaptureOverlay>
  255. cursor_overlay);
  256. // Called back when the mojo pipe to the recording service gets disconnected.
  257. void OnRecordingServiceDisconnected();
  258. // Terminates the recording service process, closes any recording-related UI
  259. // elements (only if |success| is false as this indicates that recording was
  260. // not ended normally by calling EndVideoRecording()), and shows the video
  261. // file notification with the given |thumbnail|.
  262. void FinalizeRecording(bool success, const gfx::ImageSkia& thumbnail);
  263. // Called to terminate the stop-recording shelf pod button, and the
  264. // |video_recording_watcher_| when recording ends.
  265. void TerminateRecordingUiElements();
  266. // The below functions start the actual image/video capture. They expect that
  267. // the capture session is still active when called, so they can retrieve the
  268. // capture parameters they need. They will end the sessions themselves.
  269. // They should never be called if IsCaptureAllowed() returns false.
  270. void CaptureImage(const CaptureParams& capture_params,
  271. const base::FilePath& path);
  272. void CaptureVideo(const CaptureParams& capture_params);
  273. // Called back when an image has been captured to trigger an attempt to save
  274. // the image as a file. |timestamp| is the time at which the capture was
  275. // triggered. |was_cursor_originally_blocked| is whether the cursor was
  276. // blocked at the time the screenshot capture request was made. |png_bytes| is
  277. // the buffer containing the captured image in a PNG format.
  278. void OnImageCaptured(const base::FilePath& path,
  279. bool was_cursor_originally_blocked,
  280. scoped_refptr<base::RefCountedMemory> png_bytes);
  281. // Called back when an attempt to save the image file has been completed, with
  282. // `file_saved_path` indicating whether the attempt succeeded or failed. If
  283. // `file_saved_path` is empty, the attempt failed. `png_bytes` is the buffer
  284. // containing the captured image in a PNG format, which will be used to show a
  285. // preview of the image in a notification, and save it as a bitmap in the
  286. // clipboard. If saving was successful, then the image was saved in
  287. // `file_saved_path`.
  288. void OnImageFileSaved(scoped_refptr<base::RefCountedMemory> png_bytes,
  289. const base::FilePath& file_saved_path);
  290. // Called back when the check for custom folder's availability is done in
  291. // `CheckFolderAvailability`, with `available` indicating whether the custom
  292. // folder is available or not.
  293. void OnCustomFolderAvailabilityChecked(bool available);
  294. // Called back when the |video_file_handler_| flushes the remaining cached
  295. // video chunks in its buffer. Called on the UI thread. |video_thumbnail| is
  296. // an RGB image provided by the recording service that can be used as a
  297. // thumbnail of the video in the notification. If |in_projector_mode| is true
  298. // the recording will not be shown in tote or notification.
  299. void OnVideoFileSaved(const base::FilePath& saved_video_file_path,
  300. const gfx::ImageSkia& video_thumbnail,
  301. bool success,
  302. bool in_projector_mode);
  303. // Shows a preview notification of the newly taken screenshot or screen
  304. // recording.
  305. void ShowPreviewNotification(const base::FilePath& screen_capture_path,
  306. const gfx::Image& preview_image,
  307. const CaptureModeType type);
  308. void HandleNotificationClicked(const base::FilePath& screen_capture_path,
  309. const CaptureModeType type,
  310. absl::optional<int> button_index);
  311. // Builds a path for a file of an image screenshot, or a video screen
  312. // recording, builds with display index if there are
  313. // multiple displays.
  314. base::FilePath BuildImagePath() const;
  315. base::FilePath BuildVideoPath() const;
  316. base::FilePath BuildImagePathForDisplay(int display_index) const;
  317. // Used by the above three functions by providing the corresponding file name
  318. // |format_string| to a capture type (image or video). The returned file path
  319. // excludes the file extension. The above functions are responsible for adding
  320. // it.
  321. base::FilePath BuildPathNoExtension(const char* const format_string,
  322. base::Time timestamp) const;
  323. // Returns a fallback path concatenating the default `Downloads` folder and
  324. // the base name of `path`.
  325. base::FilePath GetFallbackFilePathFromFile(const base::FilePath& path);
  326. // Records the number of screenshots taken.
  327. void RecordAndResetScreenshotsTakenInLastDay();
  328. void RecordAndResetScreenshotsTakenInLastWeek();
  329. // Records the number of consecutive screenshots taken within 5s of each
  330. // other.
  331. void RecordAndResetConsecutiveScreenshots();
  332. // Called when the video record 3-seconds count down finishes.
  333. void OnVideoRecordCountDownFinished();
  334. // Called when the Projector controller creates the DriveFS folder that will
  335. // host the video file along with the associated metadata file created by the
  336. // Projector session. Note that |file_path_no_extension| is the full path of
  337. // the video file minus its (.webm) extension.
  338. void OnProjectorContainerFolderCreated(
  339. const CaptureParams& capture_params,
  340. const base::FilePath& file_path_no_extension);
  341. // Ends the capture session and starts the video recording for the given
  342. // |capture_params|. The video will be saved to a file to the given
  343. // |video_file_path|. |for_projector| will be true if this recording was
  344. // initiated for a Projector session.
  345. // This can only be called while the session is still active.
  346. void BeginVideoRecording(const CaptureParams& capture_params,
  347. bool for_projector,
  348. const base::FilePath& video_file_path);
  349. // Called to interrupt the ongoing video recording because it's not anymore
  350. // allowed to be captured.
  351. void InterruptVideoRecording();
  352. // Called by the DLP manager when it's checked for any on-screen content
  353. // restriction at the time when the capture operation is attempted. `proceed`
  354. // will be set to true if the capture operation should continue, false if it
  355. // should be aborted.
  356. void OnDlpRestrictionCheckedAtPerformingCapture(bool proceed);
  357. // Called by the DLP manager when it's checked again for any on-screen content
  358. // restriction at the time when the video capture 3-second countdown ends.
  359. // `proceed` will be set to true if video recording should begin, or false if
  360. // it should be aborted.
  361. void OnDlpRestrictionCheckedAtCountDownFinished(bool proceed);
  362. // Bound to a callback that will be called by the DLP manager to let us know
  363. // whether a pending session initialization should `proceed` or abort due to
  364. // some restricted contents on the screen.
  365. void OnDlpRestrictionCheckedAtSessionInit(CaptureModeEntryType entry_type,
  366. bool proceed);
  367. // At the end of a video recording, the DLP manager is checked to see if there
  368. // were any restricted content of a warning level type during the recording
  369. // (warning-level restrictions do not result in interrupting the video
  370. // recording), if so, the DLP manager shows a dialog asking the user whether
  371. // to continue with saving the video file. When the dialog closes, this
  372. // function is called to provide the user choice; save the video file when
  373. // `proceed` is true, or to delete it when `proceed` is false.
  374. void OnDlpRestrictionCheckedAtVideoEnd(const gfx::ImageSkia& video_thumbnail,
  375. bool success,
  376. bool in_projector_mode,
  377. bool proceed);
  378. // Bound to a callback that will be called by DLP manager to let the user know
  379. // whether full screen capture on all displays should `proceed` or abort due
  380. // to some restricted contents on the screen.
  381. void OnDlpRestrictionCheckedAtCaptureScreenshotsOfAllDisplays(bool proceed);
  382. // Gets the corresponding `SaveLocation` enum value on the given `path`.
  383. CaptureModeSaveToLocation GetSaveToOption(const base::FilePath& path);
  384. std::unique_ptr<CaptureModeDelegate> delegate_;
  385. // Controls the selfie camera feature of capture mode.
  386. std::unique_ptr<CaptureModeCameraController> camera_controller_;
  387. CaptureModeType type_ = CaptureModeType::kImage;
  388. CaptureModeSource source_ = CaptureModeSource::kRegion;
  389. // A blocking task runner for file IO operations.
  390. scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
  391. mojo::Remote<recording::mojom::RecordingService> recording_service_remote_;
  392. mojo::Receiver<recording::mojom::RecordingServiceClient>
  393. recording_service_client_receiver_{this};
  394. mojo::Receiver<recording::mojom::DriveFsQuotaDelegate>
  395. drive_fs_quota_delegate_receiver_{this};
  396. // This is the file path of the video file currently being recorded. It is
  397. // empty when no video recording is in progress or when no video is being
  398. // saved.
  399. base::FilePath current_video_file_path_;
  400. // We remember the user selected capture region when the source is |kRegion|
  401. // between sessions. Initially, this value is empty at which point we display
  402. // a message to the user instructing them to start selecting a region.
  403. gfx::Rect user_capture_region_;
  404. std::unique_ptr<CaptureModeSession> capture_mode_session_;
  405. // Remember the user selected audio preference of whether to record audio or
  406. // not for a video, between sessions. Initially, this value is set to false,
  407. // ensuring that this is an opt-in feature.
  408. bool enable_audio_recording_ = false;
  409. // If true, the 3-second countdown UI will be skipped, and video recording
  410. // will start immediately.
  411. bool skip_count_down_ui_ = false;
  412. // True only if the recording service detects a |kLowDiskSpace| condition
  413. // while writing the video file to the file system. This value is used only to
  414. // determine the message shown to the user in the video preview notification
  415. // to explain why the recording was ended, and is then reset back to false.
  416. bool low_disk_space_threshold_reached_ = false;
  417. // Set to true when we're waiting for a callback from the DLP manager to check
  418. // content restrictions that may block capture mode at any of its stages
  419. // (initialization or performing the capture).
  420. bool pending_dlp_check_ = false;
  421. // Watches events that lead to ending video recording.
  422. std::unique_ptr<VideoRecordingWatcher> video_recording_watcher_;
  423. // Tracks the windows that currently have content protection enabled, so that
  424. // we prevent them from being video recorded. Each window is mapped to its
  425. // currently-set protection_mask. Windows in this map are only the ones that
  426. // have protection masks other than |display::CONTENT_PROTECTION_METHOD_NONE|.
  427. base::flat_map<aura::Window*, /*protection_mask*/ uint32_t>
  428. protected_windows_;
  429. // If set, it will be called when either an image or video file is saved.
  430. base::OnceCallback<void(const base::FilePath&)>
  431. on_file_saved_callback_for_test_;
  432. OnFileDeletedCallback on_file_deleted_callback_for_test_;
  433. base::OnceClosure on_countdown_finished_callback_for_test_;
  434. // Timers used to schedule recording of the number of screenshots taken.
  435. base::RepeatingTimer num_screenshots_taken_in_last_day_scheduler_;
  436. base::RepeatingTimer num_screenshots_taken_in_last_week_scheduler_;
  437. // Counters used to track the number of screenshots taken. These values are
  438. // not persisted across crashes, restarts or sessions so they only provide a
  439. // rough approximation.
  440. int num_screenshots_taken_in_last_day_ = 0;
  441. int num_screenshots_taken_in_last_week_ = 0;
  442. // Counter used to track the number of consecutive screenshots taken.
  443. int num_consecutive_screenshots_ = 0;
  444. base::DelayTimer num_consecutive_screenshots_scheduler_;
  445. // The time when OnVideoRecordCountDownFinished is called and video has
  446. // started recording. It is used when video has finished recording for metrics
  447. // collection.
  448. base::TimeTicks recording_start_time_;
  449. // The last time the user sets a non-empty capture region. It will be used to
  450. // clear the user capture region from previous capture sessions if 8+ minutes
  451. // has passed since the last time the user changes the capture region when the
  452. // new capture session starts .
  453. base::TimeTicks last_capture_region_update_time_;
  454. // True in the scope of BeginVideoRecording().
  455. bool is_initializing_recording_ = false;
  456. base::WeakPtrFactory<CaptureModeController> weak_ptr_factory_{this};
  457. };
  458. } // namespace ash
  459. #endif // ASH_CAPTURE_MODE_CAPTURE_MODE_CONTROLLER_H_