From 9029313d4c5f10c8b53bd38e1c1caea99bc3d9a9 Mon Sep 17 00:00:00 2001 From: "wjia@chromium.org" Date: Wed, 22 May 2013 02:21:46 +0000 Subject: Keep screen on when there is an active WebRTC session on Android. When WebRTC session has video channel, the screen is kept on. R=bulach@chromium.org, joth@chromium.org, qinmin@chromium.org, sky@chromium.org Review URL: https://codereview.chromium.org/15035013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201424 0039d316-1c4b-4281-b951-d872f2087c98 --- content/browser/power_save_blocker_android.cc | 53 ++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 'content/browser/power_save_blocker_android.cc') diff --git a/content/browser/power_save_blocker_android.cc b/content/browser/power_save_blocker_android.cc index c349fe5..2358049 100644 --- a/content/browser/power_save_blocker_android.cc +++ b/content/browser/power_save_blocker_android.cc @@ -5,24 +5,67 @@ #include "content/browser/power_save_blocker_impl.h" #include "base/logging.h" +#include "content/browser/android/content_video_view.h" +#include "content/public/browser/browser_thread.h" namespace content { class PowerSaveBlockerImpl::Delegate - : public base::RefCounted { + : public base::RefCountedThreadSafe { + public: + explicit Delegate(PowerSaveBlockerType type) : type_(type) {} + + // Does the actual work to apply or remove the desired power save block. + void ApplyBlock(); + void RemoveBlock(); + private: - friend class base::RefCounted; + friend class base::RefCountedThreadSafe; ~Delegate() {} + + // The counter of requests from clients for type + // kPowerSaveBlockPreventDisplaySleep. + static int blocker_count_; + const PowerSaveBlockerType type_; + + DISALLOW_COPY_AND_ASSIGN(Delegate); }; +int PowerSaveBlockerImpl::Delegate::blocker_count_ = 0; + +void PowerSaveBlockerImpl::Delegate::ApplyBlock() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (type_ != kPowerSaveBlockPreventDisplaySleep) + return; + + if (blocker_count_ == 0) + ContentVideoView::KeepScreenOn(true); + ++blocker_count_; +} + +void PowerSaveBlockerImpl::Delegate::RemoveBlock() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (type_ != kPowerSaveBlockPreventDisplaySleep) + return; + + --blocker_count_; + if (blocker_count_ == 0) + ContentVideoView::KeepScreenOn(false); +} + PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type, - const std::string& reason) { - // TODO(wangxianzhu): Implement it. + const std::string& reason) + : delegate_(new Delegate(type)) { // This may be called on any thread. - NOTIMPLEMENTED(); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&Delegate::ApplyBlock, delegate_)); } PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&Delegate::RemoveBlock, delegate_)); } } // namespace content -- cgit v1.1