[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 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 | |||||
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame^] | 7 | #include "ash/shell.h" |
pneubeck | 8be1f542 | 2014-10-09 16:46:18 | [diff] [blame] | 8 | #include "base/logging.h" |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame^] | 9 | #include "chromeos/dbus/dbus_thread_manager.h" |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 10 | #include "chromeos/dbus/power_manager_client.h" |
spang | cef1097 | 2014-09-18 15:47:10 | [diff] [blame] | 11 | #include "ui/display/types/display_snapshot.h" |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 12 | |
13 | namespace ash { | ||||
14 | |||||
pneubeck | 8be1f542 | 2014-10-09 16:46:18 | [diff] [blame] | 15 | ProjectingObserver::ProjectingObserver( |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame^] | 16 | display::DisplayConfigurator* display_configurator) |
17 | : display_configurator_(display_configurator) { | ||||
18 | if (Shell::HasInstance()) | ||||
19 | Shell::Get()->AddShellObserver(this); | ||||
20 | if (display_configurator_) | ||||
21 | display_configurator_->AddObserver(this); | ||||
pneubeck | 8be1f542 | 2014-10-09 16:46:18 | [diff] [blame] | 22 | } |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 23 | |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame^] | 24 | ProjectingObserver::~ProjectingObserver() { |
25 | if (Shell::HasInstance()) | ||||
26 | Shell::Get()->RemoveShellObserver(this); | ||||
27 | if (display_configurator_) | ||||
28 | display_configurator_->RemoveObserver(this); | ||||
29 | } | ||||
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 30 | |
31 | void ProjectingObserver::OnDisplayModeChanged( | ||||
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 32 | const display::DisplayConfigurator::DisplayStateList& display_states) { |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 33 | has_internal_output_ = false; |
[email protected] | bcec7fb6 | 2014-04-08 20:59:09 | [diff] [blame] | 34 | output_count_ = display_states.size(); |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 35 | |
[email protected] | bcec7fb6 | 2014-04-08 20:59:09 | [diff] [blame] | 36 | for (size_t i = 0; i < display_states.size(); ++i) { |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 37 | if (display_states[i]->type() == |
38 | display::DISPLAY_CONNECTION_TYPE_INTERNAL) { | ||||
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 39 | has_internal_output_ = true; |
40 | break; | ||||
41 | } | ||||
42 | } | ||||
43 | |||||
44 | SetIsProjecting(); | ||||
45 | } | ||||
46 | |||||
47 | void ProjectingObserver::OnCastingSessionStartedOrStopped(bool started) { | ||||
48 | if (started) { | ||||
49 | ++casting_session_count_; | ||||
50 | } else { | ||||
51 | DCHECK_GT(casting_session_count_, 0); | ||||
52 | --casting_session_count_; | ||||
53 | if (casting_session_count_ < 0) | ||||
54 | casting_session_count_ = 0; | ||||
55 | } | ||||
56 | |||||
57 | SetIsProjecting(); | ||||
58 | } | ||||
59 | |||||
60 | void ProjectingObserver::SetIsProjecting() { | ||||
61 | // "Projecting" is defined as having more than 1 output connected while at | ||||
62 | // least one of them is an internal output. | ||||
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 63 | bool projecting = |
64 | has_internal_output_ && (output_count_ + casting_session_count_ > 1); | ||||
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 65 | |
Steven Bennetts | 7683e34 | 2018-01-02 21:29:52 | [diff] [blame^] | 66 | chromeos::PowerManagerClient* power_manager_client = |
67 | power_manager_client_for_test_ | ||||
68 | ? power_manager_client_for_test_ | ||||
69 | : chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | ||||
70 | if (power_manager_client) | ||||
71 | power_manager_client->SetIsProjecting(projecting); | ||||
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 72 | } |
73 | |||||
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 74 | } // namespace ash |