eche_alert_generator.cc 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2021 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. #include "ash/webui/eche_app_ui/eche_alert_generator.h"
  5. #include "ash/components/multidevice/logging/logging.h"
  6. #include "ash/constants/ash_pref_names.h"
  7. #include "ash/webui/eche_app_ui/launch_app_helper.h"
  8. #include "components/prefs/pref_service.h"
  9. namespace ash {
  10. namespace eche_app {
  11. // The screen lock notification
  12. const char kEcheAppScreenLockNotifierId[] =
  13. "eche_app_notification_ids.screen_lock";
  14. // The notification type from WebUI is CONNECTION_FAILED or CONNECTION_LOST
  15. // allow users to retry.
  16. const char kEcheAppRetryConnectionNotifierId[] =
  17. "eche_app_notification_ids.retry_connection";
  18. // The notification type from WebUI is DEVICE_IDLE
  19. // allow users to retry.
  20. const char kEcheAppInactivityNotifierId[] =
  21. "eche_app_notification_ids.inactivity";
  22. // The notification type from WebUI without any actions need to do.
  23. const char kEcheAppFromWebWithoutButtonNotifierId[] =
  24. "eche_app_notification_ids.from_web_without_button";
  25. // The toast id of EcheApp.
  26. const char kEcheAppToastId[] = "eche_app_toast_id";
  27. // TODO(crbug.com/1241352): This should probably have a ?p=<FEATURE_NAME> at
  28. // some point.
  29. const char kEcheAppLearnMoreUrl[] = "https://support.google.com/chromebook";
  30. EcheAlertGenerator::EcheAlertGenerator(LaunchAppHelper* launch_app_helper,
  31. PrefService* pref_service)
  32. : launch_app_helper_(launch_app_helper), pref_service_(pref_service) {
  33. pref_change_registrar_.Init(pref_service);
  34. pref_change_registrar_.Add(
  35. ash::prefs::kEnableAutoScreenLock,
  36. base::BindRepeating(&EcheAlertGenerator::OnEnableScreenLockChanged,
  37. base::Unretained(this)));
  38. }
  39. EcheAlertGenerator::~EcheAlertGenerator() {
  40. pref_change_registrar_.RemoveAll();
  41. }
  42. void EcheAlertGenerator::ShowNotification(const std::u16string& title,
  43. const std::u16string& message,
  44. mojom::WebNotificationType type) {
  45. PA_LOG(INFO) << "echeapi EcheAlertGenerator ShowNotification";
  46. launch_app_helper_->ShowNotification(
  47. title, message,
  48. std::make_unique<LaunchAppHelper::NotificationInfo>(
  49. LaunchAppHelper::NotificationInfo::Category::kWebUI, type));
  50. }
  51. void EcheAlertGenerator::ShowToast(const std::u16string& text) {
  52. PA_LOG(INFO) << "echeapi EcheAlertGenerator ShowToast";
  53. launch_app_helper_->ShowToast(text);
  54. }
  55. void EcheAlertGenerator::Bind(
  56. mojo::PendingReceiver<mojom::NotificationGenerator> receiver) {
  57. notification_receiver_.reset();
  58. notification_receiver_.Bind(std::move(receiver));
  59. }
  60. void EcheAlertGenerator::OnEnableScreenLockChanged() {
  61. bool lock_screen_enabled =
  62. pref_service_->GetBoolean(ash::prefs::kEnableAutoScreenLock);
  63. if (lock_screen_enabled) {
  64. launch_app_helper_->CloseNotification(kEcheAppScreenLockNotifierId);
  65. }
  66. }
  67. } // namespace eche_app
  68. } // namespace ash