1 // Copyright 2014 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.
5 #include "ash/display/projecting_observer_chromeos.h"
7 #include "chromeos/dbus/dbus_thread_manager.h"
8 #include "chromeos/dbus/power_manager_client.h"
9 #include "ui/display/types/chromeos/display_snapshot.h"
13 ProjectingObserver::ProjectingObserver()
14 : has_internal_output_(false),
16 casting_session_count_(0) {}
18 ProjectingObserver::~ProjectingObserver() {}
20 void ProjectingObserver::OnDisplayModeChanged(
21 const ui::DisplayConfigurator::DisplayStateList
& display_states
) {
22 has_internal_output_
= false;
23 output_count_
= display_states
.size();
25 for (size_t i
= 0; i
< display_states
.size(); ++i
) {
26 if (display_states
[i
].display
->type() ==
27 ui::DISPLAY_CONNECTION_TYPE_INTERNAL
) {
28 has_internal_output_
= true;
36 void ProjectingObserver::OnCastingSessionStartedOrStopped(bool started
) {
38 ++casting_session_count_
;
40 DCHECK_GT(casting_session_count_
, 0);
41 --casting_session_count_
;
42 if (casting_session_count_
< 0)
43 casting_session_count_
= 0;
49 void ProjectingObserver::SetIsProjecting() {
50 // "Projecting" is defined as having more than 1 output connected while at
51 // least one of them is an internal output.
52 bool projecting
= has_internal_output_
&&
53 (output_count_
+ casting_session_count_
> 1);
55 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->SetIsProjecting(