lock_screen_note_launcher.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2017 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_LOCK_SCREEN_ACTION_LOCK_SCREEN_NOTE_LAUNCHER_H_
  5. #define ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_NOTE_LAUNCHER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/tray_action/tray_action.h"
  8. #include "ash/tray_action/tray_action_observer.h"
  9. #include "base/callback.h"
  10. #include "base/scoped_observation.h"
  11. namespace ash {
  12. // A helper class for requesting a lock screen app that provides a callback run
  13. // when the action launch process finishes (both successfuly or with a failure).
  14. class ASH_EXPORT LockScreenNoteLauncher : public TrayActionObserver {
  15. public:
  16. using LaunchCallback = base::OnceCallback<void(bool success)>;
  17. LockScreenNoteLauncher();
  18. LockScreenNoteLauncher(const LockScreenNoteLauncher&) = delete;
  19. LockScreenNoteLauncher& operator=(const LockScreenNoteLauncher&) = delete;
  20. ~LockScreenNoteLauncher() override;
  21. // Whether the lock screen note state indicates that a note action launch can
  22. // be requested - note that |Run| will not succeed if this returns false.
  23. static bool CanAttemptLaunch();
  24. // Requests a lock screen note launch, and starts observing lock screen note
  25. // state changes - when the state changes to a non-launching state (either
  26. // kActive - indicating launch success, or kAvailable or kNotAvailable -
  27. // indicating launch failure), it runs |callback|.
  28. // This can handle only one launch requests at a time - i.e. it should not be
  29. // called again before |callback| is run.
  30. // Returns whether the note launch was successfully requested. |callback| will
  31. // not be called if the return value is false.
  32. bool Run(mojom::LockScreenNoteOrigin action_origin, LaunchCallback callback);
  33. // TrayActionObserver:
  34. void OnLockScreenNoteStateChanged(mojom::TrayActionState state) override;
  35. private:
  36. // Called when the launch attempt completes - resets the object state and runs
  37. // the launch callback provided to |Run|.
  38. void OnLaunchDone(bool success);
  39. // The callback provided to |Run|.
  40. LaunchCallback callback_;
  41. base::ScopedObservation<TrayAction, TrayActionObserver>
  42. tray_action_observation_{this};
  43. };
  44. } // namespace ash
  45. #endif // ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_NOTE_LAUNCHER_H_