Index: content/browser/power_save_blocker_android.cc |
=================================================================== |
--- content/browser/power_save_blocker_android.cc (revision 200680) |
+++ content/browser/power_save_blocker_android.cc (working copy) |
@@ -5,24 +5,66 @@ |
#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 { |
+namespace { |
+int g_blocker_count; |
+} // namespace |
class PowerSaveBlockerImpl::Delegate |
- : public base::RefCounted<PowerSaveBlockerImpl::Delegate> { |
+ : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { |
+ public: |
+ Delegate(PowerSaveBlockerType type, const std::string& reason) |
+ : type_(type), reason_(reason) {} |
+ |
+ // Does the actual work to apply or remove the desired power save block. |
+ void ApplyBlock(); |
+ void RemoveBlock(); |
+ |
private: |
- friend class base::RefCounted<Delegate>; |
+ friend class base::RefCountedThreadSafe<Delegate>; |
~Delegate() {} |
+ |
+ PowerSaveBlockerType type_; |
+ const std::string reason_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Delegate); |
}; |
+void PowerSaveBlockerImpl::Delegate::ApplyBlock() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (type_ == kPowerSaveBlockPreventDisplaySleep) { |
+ if (g_blocker_count == 0) { |
+ ContentVideoView::KeepScreenOn(true); |
+ } |
+ ++g_blocker_count; |
+ } |
+} |
+ |
+void PowerSaveBlockerImpl::Delegate::RemoveBlock() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (type_ == kPowerSaveBlockPreventDisplaySleep) { |
+ --g_blocker_count; |
+ if (g_blocker_count == 0) { |
+ ContentVideoView::KeepScreenOn(false); |
+ } |
+ } |
+} |
+ |
PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type, |
- const std::string& reason) { |
- // TODO(wangxianzhu): Implement it. |
- // This may be called on any thread. |
- NOTIMPLEMENTED(); |
+ const std::string& reason) |
+ : delegate_(new Delegate(type, reason)) { |
+ BrowserThread::PostTask( |
mkosiba (inactive)
2013/05/17 09:34:47
rather than spamming the UI thread maybe make the
wjia(left Chromium)
2013/05/17 18:04:43
Done.
|
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&Delegate::ApplyBlock, delegate_)); |
} |
PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&Delegate::RemoveBlock, delegate_)); |
} |
} // namespace content |