chromeos: Notify powerd about video activity via D-Bus.

This removes the old code that set a _CHROME_VIDEO_TIME
property on the X root window and replaces it with code that
makes a HandleVideoActivity method call to powerd.

BUG=chromium-os:31351
TEST=manual: went to youtube and checked that powerd logs "Got HandleVideoActivity method call" every five seconds


Review URL: https://chromiumcodereview.appspot.com/10456056

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140540 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
index 2fd5d2d..8d38e8e1 100644
--- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
+++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
@@ -48,7 +48,7 @@
 #include "chrome/browser/chromeos/power/resume_observer.h"
 #include "chrome/browser/chromeos/power/screen_dimming_observer.h"
 #include "chrome/browser/chromeos/power/screen_lock_observer.h"
-#include "chrome/browser/chromeos/power/video_property_writer.h"
+#include "chrome/browser/chromeos/power/video_activity_notifier.h"
 #include "chrome/browser/chromeos/system/statistics_provider.h"
 #include "chrome/browser/chromeos/system_key_event_listener.h"
 #include "chrome/browser/chromeos/upgrade_detector_chromeos.h"
@@ -451,7 +451,7 @@
   // These are dependent on the ash::Shell singleton already having been
   // initialized.
   power_button_observer_.reset(new chromeos::PowerButtonObserver);
-  video_property_writer_.reset(new chromeos::VideoPropertyWriter);
+  video_activity_notifier_.reset(new chromeos::VideoActivityNotifier);
   screen_dimming_observer_.reset(new chromeos::ScreenDimmingObserver);
 
   ChromeBrowserMainPartsLinux::PostBrowserStart();
@@ -500,9 +500,9 @@
 
   chromeos::WebSocketProxyController::Shutdown();
 
-  // Let VideoPropertyWriter unregister itself as an observer of the ash::Shell
-  // singleton before the shell is destroyed.
-  video_property_writer_.reset();
+  // Let VideoActivityNotifier unregister itself as an observer of the
+  // ash::Shell singleton before the shell is destroyed.
+  video_activity_notifier_.reset();
 
   // Detach D-Bus clients before DBusThreadManager is shut down.
   power_button_observer_.reset();
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.h b/chrome/browser/chromeos/chrome_browser_main_chromeos.h
index 8dc29df8..88903804 100644
--- a/chrome/browser/chromeos/chrome_browser_main_chromeos.h
+++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.h
@@ -17,7 +17,7 @@
 class ScreenDimmingObserver;
 class ScreenLockObserver;
 class SessionManagerObserver;
-class VideoPropertyWriter;
+class VideoActivityNotifier;
 }  // namespace chromeos
 
 namespace policy {
@@ -56,7 +56,7 @@
   scoped_ptr<chromeos::SessionManagerObserver> session_manager_observer_;
   scoped_ptr<chromeos::PowerButtonObserver> power_button_observer_;
   scoped_ptr<chromeos::PowerStateOverride> power_state_override_;
-  scoped_ptr<chromeos::VideoPropertyWriter> video_property_writer_;
+  scoped_ptr<chromeos::VideoActivityNotifier> video_activity_notifier_;
   scoped_ptr<chromeos::ScreenDimmingObserver> screen_dimming_observer_;
   scoped_ptr<policy::NetworkConfigurationUpdater> network_config_updater_;
 
diff --git a/chrome/browser/chromeos/power/video_activity_notifier.cc b/chrome/browser/chromeos/power/video_activity_notifier.cc
new file mode 100644
index 0000000..d088062
--- /dev/null
+++ b/chrome/browser/chromeos/power/video_activity_notifier.cc
@@ -0,0 +1,39 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/power/video_activity_notifier.h"
+
+#include "ash/shell.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/power_manager_client.h"
+
+namespace {
+
+// Minimum number of seconds between notifications.
+const int kNotifyIntervalSec = 5;
+
+}  // namespace
+
+namespace chromeos {
+
+VideoActivityNotifier::VideoActivityNotifier() {
+  ash::Shell::GetInstance()->video_detector()->AddObserver(this);
+}
+
+VideoActivityNotifier::~VideoActivityNotifier() {
+  ash::Shell::GetInstance()->video_detector()->RemoveObserver(this);
+}
+
+void VideoActivityNotifier::OnVideoDetected() {
+  base::TimeTicks now = base::TimeTicks::Now();
+  // InSeconds() truncates rather than rounding, so it's fine for this
+  // comparison.
+  if (last_notify_time_.is_null() ||
+      (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) {
+    DBusThreadManager::Get()->GetPowerManagerClient()->NotifyVideoActivity(now);
+    last_notify_time_ = now;
+  }
+}
+
+}  // namespace chromeos
diff --git a/chrome/browser/chromeos/power/video_activity_notifier.h b/chrome/browser/chromeos/power/video_activity_notifier.h
new file mode 100644
index 0000000..bfbb01f3
--- /dev/null
+++ b/chrome/browser/chromeos/power/video_activity_notifier.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_POWER_VIDEO_ACTIVITY_NOTIFIER_H_
+#define CHROME_BROWSER_CHROMEOS_POWER_VIDEO_ACTIVITY_NOTIFIER_H_
+#pragma once
+
+#include "ash/wm/video_detector.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/time.h"
+
+namespace chromeos {
+
+// Notifies the power manager when a video is playing.
+class VideoActivityNotifier : public ash::VideoDetectorObserver {
+ public:
+  VideoActivityNotifier();
+  virtual ~VideoActivityNotifier();
+
+  // ash::VideoDetectorObserver implementation.
+  virtual void OnVideoDetected() OVERRIDE;
+
+ private:
+  // Last time that the power manager was notified.
+  base::TimeTicks last_notify_time_;
+
+  DISALLOW_COPY_AND_ASSIGN(VideoActivityNotifier);
+};
+
+}  // namespace chromeos
+
+#endif  // CHROME_BROWSER_CHROMEOS_POWER_VIDEO_ACTIVITY_NOTIFIER_H_
diff --git a/chrome/browser/chromeos/power/video_property_writer.cc b/chrome/browser/chromeos/power/video_property_writer.cc
deleted file mode 100644
index 186e104..0000000
--- a/chrome/browser/chromeos/power/video_property_writer.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/chromeos/power/video_property_writer.h"
-
-#include <ctime>
-
-#include "ash/shell.h"
-#include "ui/base/x/x11_util.h"
-
-namespace {
-
-// Minimum number of seconds between updates to the X property.
-const int kUpdateIntervalSec = 5;
-
-// Name of the X property on the root window.  Also used as the property's type.
-const char kPropertyName[] = "_CHROME_VIDEO_TIME";
-
-}  // namespace
-
-namespace chromeos {
-
-VideoPropertyWriter::VideoPropertyWriter() {
-  ash::Shell::GetInstance()->video_detector()->AddObserver(this);
-}
-
-VideoPropertyWriter::~VideoPropertyWriter() {
-  ash::Shell::GetInstance()->video_detector()->RemoveObserver(this);
-}
-
-void VideoPropertyWriter::OnVideoDetected() {
-  base::TimeTicks now = base::TimeTicks::Now();
-  if (last_update_time_.is_null() ||
-      (now - last_update_time_).InSecondsF() >= kUpdateIntervalSec) {
-    last_update_time_ = now;
-    if (!ui::SetIntProperty(
-            ui::GetX11RootWindow(),
-            kPropertyName,
-            kPropertyName,
-            time(NULL))) {
-      LOG(WARNING) << "Failed setting " << kPropertyName << " on root window";
-    }
-  }
-}
-
-}  // namespace chromeos
diff --git a/chrome/browser/chromeos/power/video_property_writer.h b/chrome/browser/chromeos/power/video_property_writer.h
deleted file mode 100644
index 95480a72..0000000
--- a/chrome/browser/chromeos/power/video_property_writer.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_CHROMEOS_POWER_VIDEO_PROPERTY_WRITER_H_
-#define CHROME_BROWSER_CHROMEOS_POWER_VIDEO_PROPERTY_WRITER_H_
-#pragma once
-
-#include "ash/wm/video_detector.h"
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/time.h"
-
-namespace chromeos {
-
-// Writes a property on the X root window to inform the power manager that a
-// video is playing.
-class VideoPropertyWriter : public ash::VideoDetectorObserver {
- public:
-  VideoPropertyWriter();
-  virtual ~VideoPropertyWriter();
-
-  // ash::VideoDetectorObserver implementation.
-  virtual void OnVideoDetected() OVERRIDE;
-
- private:
-  // Last time that the X property was updated.
-  base::TimeTicks last_update_time_;
-
-  DISALLOW_COPY_AND_ASSIGN(VideoPropertyWriter);
-};
-
-}  // namespace chromeos
-
-#endif  // CHROME_BROWSER_CHROMEOS_POWER_VIDEO_PROPERTY_WRITER_H_