OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/chromeos/power/video_activity_notifier.h" | 5 #include "ash/system/chromeos/power/video_activity_notifier.h" |
6 | 6 |
7 #include "ash/common/wm_shell.h" | 7 #include "ash/common/wm_shell.h" |
8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
9 #include "chromeos/dbus/power_manager_client.h" | 9 #include "chromeos/dbus/power_manager_client.h" |
10 | 10 |
11 namespace ash { | 11 namespace ash { |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Minimum number of seconds between notifications. | 14 // Minimum number of seconds between notifications. |
15 const int kNotifyIntervalSec = 5; | 15 const int kNotifyIntervalSec = 5; |
16 | 16 |
17 } // namespace | 17 } // namespace |
18 | 18 |
19 VideoActivityNotifier::VideoActivityNotifier(VideoDetector* detector) | 19 VideoActivityNotifier::VideoActivityNotifier(VideoDetector* detector) |
20 : detector_(detector), | 20 : detector_(detector), screen_is_locked_(false) { |
21 screen_is_locked_(false) { | |
22 detector_->AddObserver(this); | 21 detector_->AddObserver(this); |
23 ash::WmShell::Get()->AddShellObserver(this); | 22 ash::WmShell::Get()->AddShellObserver(this); |
24 } | 23 } |
25 | 24 |
26 VideoActivityNotifier::~VideoActivityNotifier() { | 25 VideoActivityNotifier::~VideoActivityNotifier() { |
27 ash::WmShell::Get()->RemoveShellObserver(this); | 26 ash::WmShell::Get()->RemoveShellObserver(this); |
28 detector_->RemoveObserver(this); | 27 detector_->RemoveObserver(this); |
29 } | 28 } |
30 | 29 |
31 void VideoActivityNotifier::OnVideoDetected(bool is_fullscreen) { | 30 void VideoActivityNotifier::OnVideoDetected(bool is_fullscreen) { |
32 if (screen_is_locked_) | 31 if (screen_is_locked_) |
33 return; | 32 return; |
34 | 33 |
35 base::TimeTicks now = base::TimeTicks::Now(); | 34 base::TimeTicks now = base::TimeTicks::Now(); |
36 if (last_notify_time_.is_null() || | 35 if (last_notify_time_.is_null() || |
37 (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) { | 36 (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) { |
38 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 37 chromeos::DBusThreadManager::Get() |
39 NotifyVideoActivity(is_fullscreen); | 38 ->GetPowerManagerClient() |
| 39 ->NotifyVideoActivity(is_fullscreen); |
40 last_notify_time_ = now; | 40 last_notify_time_ = now; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 void VideoActivityNotifier::OnLockStateChanged(bool locked) { | 44 void VideoActivityNotifier::OnLockStateChanged(bool locked) { |
45 screen_is_locked_ = locked; | 45 screen_is_locked_ = locked; |
46 } | 46 } |
47 | 47 |
48 } // namespace ash | 48 } // namespace ash |
OLD | NEW |