find_my_device_controller_impl.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/find_my_device_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. FindMyDeviceControllerImpl::FindMyDeviceControllerImpl(
  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. FindMyDeviceControllerImpl::~FindMyDeviceControllerImpl() = default;
  18. void FindMyDeviceControllerImpl::SetPhoneRingingStatusInternal(Status status) {
  19. if (phone_ringing_status_ == status)
  20. return;
  21. PA_LOG(INFO) << "Find My Device ringing status update: "
  22. << phone_ringing_status_ << " => " << status;
  23. phone_ringing_status_ = status;
  24. NotifyPhoneRingingStateChanged();
  25. }
  26. FindMyDeviceController::Status
  27. FindMyDeviceControllerImpl::GetPhoneRingingStatus() {
  28. return phone_ringing_status_;
  29. }
  30. void FindMyDeviceControllerImpl::RequestNewPhoneRingingState(bool ringing) {
  31. if (phone_ringing_status_ == Status::kRingingNotAvailable) {
  32. PA_LOG(WARNING) << "Cannot request new ringing status because DoNotDisturb "
  33. << "mode is enabled.";
  34. return;
  35. }
  36. PA_LOG(INFO) << "Attempting to set Find My Device phone ring state; new "
  37. << "value: " << ringing;
  38. user_action_recorder_->RecordFindMyDeviceAttempt();
  39. message_sender_->SendRingDeviceRequest(ringing);
  40. }
  41. } // namespace phonehub
  42. } // namespace ash