Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / system / chromeos / power / video_activity_notifier.cc
blob07f8490b01f18f6dab6dab83aeac24a67b341ead
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.
5 #include "ash/system/chromeos/power/video_activity_notifier.h"
7 #include "ash/shell.h"
8 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/power_manager_client.h"
11 namespace ash {
12 namespace {
14 // Minimum number of seconds between notifications.
15 const int kNotifyIntervalSec = 5;
17 } // namespace
19 VideoActivityNotifier::VideoActivityNotifier(VideoDetector* detector)
20 : detector_(detector),
21 screen_is_locked_(false) {
22 detector_->AddObserver(this);
23 ash::Shell::GetInstance()->AddShellObserver(this);
26 VideoActivityNotifier::~VideoActivityNotifier() {
27 ash::Shell::GetInstance()->RemoveShellObserver(this);
28 detector_->RemoveObserver(this);
31 void VideoActivityNotifier::OnVideoDetected(bool is_fullscreen) {
32 if (screen_is_locked_)
33 return;
35 base::TimeTicks now = base::TimeTicks::Now();
36 if (last_notify_time_.is_null() ||
37 (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) {
38 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
39 NotifyVideoActivity(is_fullscreen);
40 last_notify_time_ = now;
44 void VideoActivityNotifier::OnLockStateChanged(bool locked) {
45 screen_is_locked_ = locked;
48 } // namespace ash