Home | History | Annotate | Download | only in power
      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 
     11 namespace ash {
     12 namespace internal {
     13 
     14 namespace {
     15 
     16 // Minimum number of seconds between notifications.
     17 const int kNotifyIntervalSec = 5;
     18 
     19 }  // namespace
     20 
     21 VideoActivityNotifier::VideoActivityNotifier(VideoDetector* detector)
     22     : detector_(detector) {
     23   detector_->AddObserver(this);
     24 }
     25 
     26 VideoActivityNotifier::~VideoActivityNotifier() {
     27   detector_->RemoveObserver(this);
     28 }
     29 
     30 void VideoActivityNotifier::OnVideoDetected(bool is_fullscreen) {
     31   base::TimeTicks now = base::TimeTicks::Now();
     32   if (last_notify_time_.is_null() ||
     33       (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) {
     34     chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
     35         NotifyVideoActivity(is_fullscreen);
     36     last_notify_time_ = now;
     37   }
     38 }
     39 
     40 }  // namespace internal
     41 }  // namespace ash
     42