PermissionRequestCreatorApiary: switch from deprecated "namespace" to "eventType"
[chromium-blink-merge.git] / ash / display / projecting_observer_chromeos.cc
blob0bf6af47883e4b0f12c949a7e547c7ec08962177
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 "base/logging.h"
8 #include "chromeos/dbus/power_manager_client.h"
9 #include "ui/display/types/display_snapshot.h"
11 namespace ash {
13 ProjectingObserver::ProjectingObserver(
14 chromeos::PowerManagerClient* power_manager_client)
15 : has_internal_output_(false),
16 output_count_(0),
17 casting_session_count_(0),
18 power_manager_client_(power_manager_client) {
19 DCHECK(power_manager_client);
22 ProjectingObserver::~ProjectingObserver() {}
24 void ProjectingObserver::OnDisplayModeChanged(
25 const ui::DisplayConfigurator::DisplayStateList& display_states) {
26 has_internal_output_ = false;
27 output_count_ = display_states.size();
29 for (size_t i = 0; i < display_states.size(); ++i) {
30 if (display_states[i]->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) {
31 has_internal_output_ = true;
32 break;
36 SetIsProjecting();
39 void ProjectingObserver::OnCastingSessionStartedOrStopped(bool started) {
40 if (started) {
41 ++casting_session_count_;
42 } else {
43 DCHECK_GT(casting_session_count_, 0);
44 --casting_session_count_;
45 if (casting_session_count_ < 0)
46 casting_session_count_ = 0;
49 SetIsProjecting();
52 void ProjectingObserver::SetIsProjecting() {
53 // "Projecting" is defined as having more than 1 output connected while at
54 // least one of them is an internal output.
55 bool projecting = has_internal_output_ &&
56 (output_count_ + casting_session_count_ > 1);
58 power_manager_client_->SetIsProjecting(projecting);
61 } // namespace ash