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"
14 ProjectingObserver::ProjectingObserver()
15 : has_internal_output_(false),
17 casting_session_count_(0) {}
19 ProjectingObserver::~ProjectingObserver() {}
21 void ProjectingObserver::OnDisplayModeChanged(
22 const std::vector<chromeos::OutputConfigurator::OutputSnapshot>& outputs) {
23 has_internal_output_ = false;
24 output_count_ = outputs.size();
26 for (size_t i = 0; i < outputs.size(); ++i) {
27 if (outputs[i].type == ui::OUTPUT_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(
59 } // namespace internal