Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ash / display / projecting_observer_chromeos.cc
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
10 namespace ash {
11
12 namespace internal {
13
14 ProjectingObserver::ProjectingObserver()
15     : has_internal_output_(false),
16       output_count_(0),
17       casting_session_count_(0) {}
18
19 ProjectingObserver::~ProjectingObserver() {}
20
21 void ProjectingObserver::OnDisplayModeChanged(
22     const std::vector<chromeos::OutputConfigurator::OutputSnapshot>& outputs) {
23   has_internal_output_ = false;
24   output_count_ = outputs.size();
25
26   for (size_t i = 0; i < outputs.size(); ++i) {
27     if (outputs[i].type == ui::OUTPUT_TYPE_INTERNAL) {
28       has_internal_output_ = true;
29       break;
30     }
31   }
32
33   SetIsProjecting();
34 }
35
36 void ProjectingObserver::OnCastingSessionStartedOrStopped(bool started) {
37   if (started) {
38     ++casting_session_count_;
39   } else {
40     DCHECK_GT(casting_session_count_, 0);
41     --casting_session_count_;
42     if (casting_session_count_ < 0)
43       casting_session_count_ = 0;
44   }
45
46   SetIsProjecting();
47 }
48
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);
54
55   chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->SetIsProjecting(
56       projecting);
57 }
58
59 }  // namespace internal
60
61 }  // namespace ash