| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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/system/chromeos/power/video_activity_notifier.h" | |
| 6 | |
| 7 #include "ash/common/session/session_state_delegate.h" | |
| 8 #include "ash/common/wm_shell.h" | |
| 9 #include "ash/shell.h" | |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 11 #include "chromeos/dbus/power_manager_client.h" | |
| 12 | |
| 13 namespace ash { | |
| 14 namespace { | |
| 15 | |
| 16 // Minimum number of seconds between repeated notifications of the same state. | |
| 17 // This should be less than powerd's timeout for determining whether video is | |
| 18 // still active for the purposes of controlling the keyboard backlight. | |
| 19 const int kNotifyIntervalSec = 5; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 VideoActivityNotifier::VideoActivityNotifier(VideoDetector* detector) | |
| 24 : detector_(detector), | |
| 25 video_state_(detector->state()), | |
| 26 screen_is_locked_( | |
| 27 Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) { | |
| 28 detector_->AddObserver(this); | |
| 29 WmShell::Get()->AddShellObserver(this); | |
| 30 | |
| 31 MaybeNotifyPowerManager(); | |
| 32 UpdateTimer(); | |
| 33 } | |
| 34 | |
| 35 VideoActivityNotifier::~VideoActivityNotifier() { | |
| 36 WmShell::Get()->RemoveShellObserver(this); | |
| 37 detector_->RemoveObserver(this); | |
| 38 } | |
| 39 | |
| 40 void VideoActivityNotifier::OnVideoStateChanged(VideoDetector::State state) { | |
| 41 if (video_state_ != state) { | |
| 42 video_state_ = state; | |
| 43 MaybeNotifyPowerManager(); | |
| 44 UpdateTimer(); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 void VideoActivityNotifier::OnLockStateChanged(bool locked) { | |
| 49 if (screen_is_locked_ != locked) { | |
| 50 screen_is_locked_ = locked; | |
| 51 MaybeNotifyPowerManager(); | |
| 52 UpdateTimer(); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 bool VideoActivityNotifier::TriggerTimeoutForTest() { | |
| 57 if (!notify_timer_.IsRunning()) | |
| 58 return false; | |
| 59 | |
| 60 MaybeNotifyPowerManager(); | |
| 61 return true; | |
| 62 } | |
| 63 | |
| 64 void VideoActivityNotifier::UpdateTimer() { | |
| 65 if (!should_notify_power_manager()) { | |
| 66 notify_timer_.Stop(); | |
| 67 } else { | |
| 68 notify_timer_.Start(FROM_HERE, | |
| 69 base::TimeDelta::FromSeconds(kNotifyIntervalSec), this, | |
| 70 &VideoActivityNotifier::MaybeNotifyPowerManager); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 void VideoActivityNotifier::MaybeNotifyPowerManager() { | |
| 75 if (should_notify_power_manager()) { | |
| 76 chromeos::DBusThreadManager::Get() | |
| 77 ->GetPowerManagerClient() | |
| 78 ->NotifyVideoActivity(video_state_ == | |
| 79 VideoDetector::State::PLAYING_FULLSCREEN); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 } // namespace ash | |
| OLD | NEW |