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/shell.h" 8#include "chromeos/dbus/dbus_thread_manager.h" 9#include "chromeos/dbus/power_manager_client.h" 10 11namespace ash { 12namespace { 13 14// Minimum number of seconds between notifications. 15const int kNotifyIntervalSec = 5; 16 17} // namespace 18 19VideoActivityNotifier::VideoActivityNotifier(VideoDetector* detector) 20 : detector_(detector), 21 screen_is_locked_(false) { 22 detector_->AddObserver(this); 23 ash::Shell::GetInstance()->AddShellObserver(this); 24} 25 26VideoActivityNotifier::~VideoActivityNotifier() { 27 ash::Shell::GetInstance()->RemoveShellObserver(this); 28 detector_->RemoveObserver(this); 29} 30 31void VideoActivityNotifier::OnVideoDetected(bool is_fullscreen) { 32 if (screen_is_locked_) 33 return; 34 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; 41 } 42} 43 44void VideoActivityNotifier::OnLockStateChanged(bool locked) { 45 screen_is_locked_ = locked; 46} 47 48} // namespace ash 49