1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/display/projecting_observer.h"
8 #include "ash/system/power/power_event_observer.h"
9 #include "base/check_op.h"
10 #include "chromeos/dbus/power/power_manager_client.h"
11 #include "ui/display/types/display_snapshot.h"
15 ProjectingObserver::ProjectingObserver(
16 display::DisplayConfigurator* display_configurator)
17 : display_configurator_(display_configurator) {
18 if (Shell::HasInstance())
19 Shell::Get()->AddShellObserver(this);
20 if (display_configurator_)
21 display_configurator_->AddObserver(this);
24 ProjectingObserver::~ProjectingObserver() {
25 if (Shell::HasInstance())
26 Shell::Get()->RemoveShellObserver(this);
27 if (display_configurator_)
28 display_configurator_->RemoveObserver(this);
31 void ProjectingObserver::OnDisplayModeChanged(
32 const display::DisplayConfigurator::DisplayStateList& display_states) {
33 has_internal_output_ = false;
34 output_count_ = display_states.size();
36 for (size_t i = 0; i < display_states.size(); ++i) {
37 if (display_states[i]->type() ==
38 display::DISPLAY_CONNECTION_TYPE_INTERNAL) {
39 has_internal_output_ = true;
47 void ProjectingObserver::OnCastingSessionStartedOrStopped(bool started) {
49 ++casting_session_count_;
51 DCHECK_GT(casting_session_count_, 0);
52 --casting_session_count_;
53 if (casting_session_count_ < 0)
54 casting_session_count_ = 0;
60 void ProjectingObserver::SetIsProjecting() {
61 // "Projecting" is defined as having more than 1 output connected while at
62 // least one of them is an internal output.
64 has_internal_output_ && (output_count_ + casting_session_count_ > 1);
66 chromeos::PowerManagerClient::Get()->SetIsProjecting(is_projecting_);
67 if (Shell::HasInstance())
68 Shell::Get()->power_event_observer()->SetIsProjecting(is_projecting_);