screen_security_notification_controller.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2018 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_SYSTEM_SCREEN_SECURITY_SCREEN_SECURITY_NOTIFICATION_CONTROLLER_H_
  5. #define ASH_SYSTEM_SCREEN_SECURITY_SCREEN_SECURITY_NOTIFICATION_CONTROLLER_H_
  6. #include <string>
  7. #include <vector>
  8. #include "ash/shell_observer.h"
  9. #include "ash/system/screen_security/screen_capture_observer.h"
  10. #include "ash/system/screen_security/screen_share_observer.h"
  11. #include "base/memory/weak_ptr.h"
  12. namespace ash {
  13. extern ASH_EXPORT const char kScreenCaptureNotificationId[];
  14. extern ASH_EXPORT const char kScreenShareNotificationId[];
  15. extern ASH_EXPORT const char kNotifierScreenCapture[];
  16. extern ASH_EXPORT const char kNotifierScreenShare[];
  17. // Controller class to manage screen security notifications.
  18. class ASH_EXPORT ScreenSecurityNotificationController
  19. : public ScreenCaptureObserver,
  20. public ScreenShareObserver,
  21. public ShellObserver {
  22. public:
  23. ScreenSecurityNotificationController();
  24. ScreenSecurityNotificationController(
  25. const ScreenSecurityNotificationController&) = delete;
  26. ScreenSecurityNotificationController& operator=(
  27. const ScreenSecurityNotificationController&) = delete;
  28. ~ScreenSecurityNotificationController() override;
  29. private:
  30. void CreateNotification(const std::u16string& message, bool is_capture);
  31. // Remove the notification and call all the callbacks in
  32. // |capture_stop_callbacks_| or |share_stop_callbacks_|, depending on
  33. // |is_capture| argument.
  34. void StopAllSessions(bool is_capture);
  35. // Change the source of current capture session by bringing up the picker
  36. // again, only if there is only one screen capture session.
  37. void ChangeSource();
  38. // ScreenCaptureObserver:
  39. void OnScreenCaptureStart(
  40. const base::RepeatingClosure& stop_callback,
  41. const base::RepeatingClosure& source_callback,
  42. const std::u16string& screen_capture_status) override;
  43. void OnScreenCaptureStop() override;
  44. // ScreenShareObserver:
  45. void OnScreenShareStart(const base::RepeatingClosure& stop_callback,
  46. const std::u16string& helper_name) override;
  47. void OnScreenShareStop() override;
  48. // ShellObserver:
  49. void OnCastingSessionStartedOrStopped(bool started) override;
  50. bool is_casting_ = false;
  51. // There can be multiple cast sessions at the same time. If the user hits the
  52. // stop button, stop all sessions since there is not a good UI to distinguish
  53. // between the different sessions.
  54. std::vector<base::OnceClosure> capture_stop_callbacks_;
  55. std::vector<base::OnceClosure> share_stop_callbacks_;
  56. base::RepeatingClosure change_source_callback_;
  57. base::WeakPtrFactory<ScreenSecurityNotificationController> weak_ptr_factory_{
  58. this};
  59. };
  60. } // namespace ash
  61. #endif // ASH_SYSTEM_SCREEN_SECURITY_SCREEN_SECURITY_NOTIFICATION_CONTROLLER_H_