do_not_disturb_controller_impl.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "ash/components/phonehub/do_not_disturb_controller_impl.h"
  5. #include "ash/components/multidevice/logging/logging.h"
  6. #include "ash/components/phonehub/message_sender.h"
  7. #include "ash/components/phonehub/user_action_recorder.h"
  8. namespace ash {
  9. namespace phonehub {
  10. DoNotDisturbControllerImpl::DoNotDisturbControllerImpl(
  11. MessageSender* message_sender,
  12. UserActionRecorder* user_action_recorder)
  13. : message_sender_(message_sender),
  14. user_action_recorder_(user_action_recorder) {
  15. DCHECK(message_sender_);
  16. }
  17. DoNotDisturbControllerImpl::~DoNotDisturbControllerImpl() = default;
  18. bool DoNotDisturbControllerImpl::IsDndEnabled() const {
  19. return is_dnd_enabled_;
  20. }
  21. void DoNotDisturbControllerImpl::SetDoNotDisturbStateInternal(
  22. bool is_dnd_enabled,
  23. bool can_request_new_dnd_state) {
  24. if (is_dnd_enabled_ == is_dnd_enabled &&
  25. can_request_new_dnd_state_ == can_request_new_dnd_state) {
  26. return;
  27. }
  28. if (is_dnd_enabled != is_dnd_enabled_) {
  29. PA_LOG(INFO) << "Do Not Disturb state updated: " << is_dnd_enabled_
  30. << " => " << is_dnd_enabled;
  31. is_dnd_enabled_ = is_dnd_enabled;
  32. }
  33. if (can_request_new_dnd_state != can_request_new_dnd_state_) {
  34. PA_LOG(INFO) << "Can request new Do Not Disturb state updated: "
  35. << can_request_new_dnd_state_ << " => "
  36. << can_request_new_dnd_state;
  37. can_request_new_dnd_state_ = can_request_new_dnd_state;
  38. }
  39. NotifyDndStateChanged();
  40. }
  41. void DoNotDisturbControllerImpl::RequestNewDoNotDisturbState(bool enabled) {
  42. if (enabled == is_dnd_enabled_)
  43. return;
  44. PA_LOG(INFO) << "Attempting to set DND state; new value: " << enabled;
  45. user_action_recorder_->RecordDndAttempt();
  46. message_sender_->SendUpdateNotificationModeRequest(enabled);
  47. }
  48. bool DoNotDisturbControllerImpl::CanRequestNewDndState() const {
  49. return can_request_new_dnd_state_;
  50. }
  51. } // namespace phonehub
  52. } // namespace ash