| 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 #ifndef ASH_SYSTEM_CHROMEOS_POWER_VIDEO_ACTIVITY_NOTIFIER_H_ | |
| 6 #define ASH_SYSTEM_CHROMEOS_POWER_VIDEO_ACTIVITY_NOTIFIER_H_ | |
| 7 | |
| 8 #include "ash/ash_export.h" | |
| 9 #include "ash/wm/video_detector.h" | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/time/time.h" | |
| 13 | |
| 14 namespace ash { | |
| 15 | |
| 16 // Notifies the power manager when a video is playing. | |
| 17 class ASH_EXPORT VideoActivityNotifier : public VideoDetector::Observer, | |
| 18 public ShellObserver { | |
| 19 public: | |
| 20 explicit VideoActivityNotifier(VideoDetector* detector); | |
| 21 ~VideoActivityNotifier() override; | |
| 22 | |
| 23 // VideoDetector::Observer implementation. | |
| 24 void OnVideoStateChanged(VideoDetector::State state) override; | |
| 25 | |
| 26 // ShellObserver implementation. | |
| 27 void OnLockStateChanged(bool locked) override; | |
| 28 | |
| 29 // If |notify_timer_| is running, calls MaybeNotifyPowerManager() and returns | |
| 30 // true. Returns false otherwise. | |
| 31 bool TriggerTimeoutForTest() WARN_UNUSED_RESULT; | |
| 32 | |
| 33 private: | |
| 34 bool should_notify_power_manager() { | |
| 35 return video_state_ != VideoDetector::State::NOT_PLAYING && | |
| 36 !screen_is_locked_; | |
| 37 } | |
| 38 | |
| 39 // Starts or stops |notify_timer_| as needed. | |
| 40 void UpdateTimer(); | |
| 41 | |
| 42 // Notifies powerd about video activity if should_notify_power_manager() is | |
| 43 // true. | |
| 44 void MaybeNotifyPowerManager(); | |
| 45 | |
| 46 VideoDetector* detector_; // not owned | |
| 47 | |
| 48 // Most-recently-observed video state. | |
| 49 VideoDetector::State video_state_; | |
| 50 | |
| 51 // True if the screen is currently locked. | |
| 52 bool screen_is_locked_; | |
| 53 | |
| 54 // Periodically calls MaybeNotifyPowerManager() while | |
| 55 // should_notify_power_manager() is true. | |
| 56 base::RepeatingTimer notify_timer_; | |
| 57 | |
| 58 DISALLOW_COPY_AND_ASSIGN(VideoActivityNotifier); | |
| 59 }; | |
| 60 | |
| 61 } // namespace ash | |
| 62 | |
| 63 #endif // ASH_SYSTEM_CHROMEOS_POWER_VIDEO_ACTIVITY_NOTIFIER_H_ | |
| OLD | NEW |