screen_state_enabled_provider.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/quick_pair/feature_status_tracker/screen_state_enabled_provider.h"
  5. #include "ash/shell.h"
  6. #include "ui/display/types/display_mode.h"
  7. #include "ui/display/types/display_snapshot.h"
  8. namespace ash {
  9. namespace quick_pair {
  10. ScreenStateEnabledProvider::ScreenStateEnabledProvider() {
  11. auto* configurator = Shell::Get()->display_configurator();
  12. DCHECK(configurator);
  13. configurator_observation_.Observe(configurator);
  14. // IsDisplayOn() is true for a screen with brightness 0 but in practice
  15. // that edge case does not occur at initialization. We cover that edge
  16. // case later but we don't have access to a DisplayStateList here.
  17. SetEnabledAndInvokeCallback(configurator->IsDisplayOn());
  18. }
  19. ScreenStateEnabledProvider::~ScreenStateEnabledProvider() = default;
  20. void ScreenStateEnabledProvider::OnDisplayModeChanged(
  21. const display::DisplayConfigurator::DisplayStateList& display_states) {
  22. for (const display::DisplaySnapshot* state : display_states) {
  23. // If a display has current_mode, then it is (1) an external monitor or (2)
  24. // the internal display with non-zero brightness and an open laptop lid.
  25. if (state->current_mode()) {
  26. SetEnabledAndInvokeCallback(true);
  27. return;
  28. }
  29. }
  30. SetEnabledAndInvokeCallback(false);
  31. }
  32. } // namespace quick_pair
  33. } // namespace ash