fake_host_backend_delegate.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include "ash/services/multidevice_setup/fake_host_backend_delegate.h"
  5. #include "base/callback.h"
  6. namespace ash {
  7. namespace multidevice_setup {
  8. FakeHostBackendDelegate::FakeHostBackendDelegate() : HostBackendDelegate() {}
  9. FakeHostBackendDelegate::~FakeHostBackendDelegate() = default;
  10. void FakeHostBackendDelegate::NotifyHostChangedOnBackend(
  11. const absl::optional<multidevice::RemoteDeviceRef>&
  12. host_device_on_backend) {
  13. host_device_on_backend_ = host_device_on_backend;
  14. if (pending_host_request_ && *pending_host_request_ == host_device_on_backend)
  15. pending_host_request_.reset();
  16. HostBackendDelegate::NotifyHostChangedOnBackend();
  17. }
  18. void FakeHostBackendDelegate::NotifyBackendRequestFailed() {
  19. // A request must be active in order for a back-end request to fail.
  20. DCHECK(pending_host_request_);
  21. HostBackendDelegate::NotifyBackendRequestFailed();
  22. }
  23. void FakeHostBackendDelegate::AttemptToSetMultiDeviceHostOnBackend(
  24. const absl::optional<multidevice::RemoteDeviceRef>& host_device) {
  25. ++num_attempt_to_set_calls_;
  26. if (host_device_on_backend_ == host_device) {
  27. if (pending_host_request_) {
  28. pending_host_request_.reset();
  29. NotifyPendingHostRequestChange();
  30. }
  31. return;
  32. }
  33. // If |pending_host_request_| was set and already referred to |host_device|,
  34. // there is no need to notify observers.
  35. if (pending_host_request_ && *pending_host_request_ == host_device)
  36. return;
  37. pending_host_request_ = host_device;
  38. NotifyPendingHostRequestChange();
  39. }
  40. bool FakeHostBackendDelegate::HasPendingHostRequest() {
  41. return pending_host_request_ != absl::nullopt;
  42. }
  43. absl::optional<multidevice::RemoteDeviceRef>
  44. FakeHostBackendDelegate::GetPendingHostRequest() const {
  45. return *pending_host_request_;
  46. }
  47. absl::optional<multidevice::RemoteDeviceRef>
  48. FakeHostBackendDelegate::GetMultiDeviceHostFromBackend() const {
  49. return host_device_on_backend_;
  50. }
  51. FakeHostBackendDelegateObserver::FakeHostBackendDelegateObserver() = default;
  52. FakeHostBackendDelegateObserver::~FakeHostBackendDelegateObserver() = default;
  53. void FakeHostBackendDelegateObserver::OnHostChangedOnBackend() {
  54. ++num_changes_on_backend_;
  55. }
  56. void FakeHostBackendDelegateObserver::OnBackendRequestFailed() {
  57. ++num_failed_backend_requests_;
  58. }
  59. void FakeHostBackendDelegateObserver::OnPendingHostRequestChange() {
  60. ++num_pending_host_request_changes_;
  61. }
  62. } // namespace multidevice_setup
  63. } // namespace ash