projecting_observer_chromeos.cc revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
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. 4 5#include "ash/display/projecting_observer_chromeos.h" 6 7#include "chromeos/dbus/dbus_thread_manager.h" 8#include "chromeos/dbus/power_manager_client.h" 9#include "ui/display/chromeos/display_snapshot.h" 10 11namespace ash { 12 13namespace internal { 14 15ProjectingObserver::ProjectingObserver() 16 : has_internal_output_(false), 17 output_count_(0), 18 casting_session_count_(0) {} 19 20ProjectingObserver::~ProjectingObserver() {} 21 22void ProjectingObserver::OnDisplayModeChanged( 23 const ui::OutputConfigurator::DisplayStateList& outputs) { 24 has_internal_output_ = false; 25 output_count_ = outputs.size(); 26 27 for (size_t i = 0; i < outputs.size(); ++i) { 28 if (outputs[i].display->type() == ui::OUTPUT_TYPE_INTERNAL) { 29 has_internal_output_ = true; 30 break; 31 } 32 } 33 34 SetIsProjecting(); 35} 36 37void ProjectingObserver::OnCastingSessionStartedOrStopped(bool started) { 38 if (started) { 39 ++casting_session_count_; 40 } else { 41 DCHECK_GT(casting_session_count_, 0); 42 --casting_session_count_; 43 if (casting_session_count_ < 0) 44 casting_session_count_ = 0; 45 } 46 47 SetIsProjecting(); 48} 49 50void ProjectingObserver::SetIsProjecting() { 51 // "Projecting" is defined as having more than 1 output connected while at 52 // least one of them is an internal output. 53 bool projecting = has_internal_output_ && 54 (output_count_ + casting_session_count_ > 1); 55 56 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->SetIsProjecting( 57 projecting); 58} 59 60} // namespace internal 61 62} // namespace ash 63