Index: content/browser/power_save_blocker_android.cc |
=================================================================== |
--- content/browser/power_save_blocker_android.cc (revision 201139) |
+++ content/browser/power_save_blocker_android.cc (working copy) |
@@ -5,24 +5,64 @@ |
#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 blocker_count = 0; |
+} // namespace |
class PowerSaveBlockerImpl::Delegate |
- : public base::RefCounted<PowerSaveBlockerImpl::Delegate> { |
+ : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { |
+ public: |
+ Delegate(PowerSaveBlockerType type) |
+ : type_(type) {} |
qinmin
2013/05/21 21:40:24
nit: can move to a single line
wjia(left Chromium)
2013/05/21 21:50:24
Done.
|
+ |
+ // 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_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Delegate); |
}; |
+void PowerSaveBlockerImpl::Delegate::ApplyBlock() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (type_ == kPowerSaveBlockPreventDisplaySleep) { |
qinmin
2013/05/21 21:40:24
nit: remove nested loops.
if (type_ != kPowerSaveB
wjia(left Chromium)
2013/05/21 21:50:24
Done.
|
+ if (blocker_count == 0) |
+ ContentVideoView::KeepScreenOn(true); |
+ ++blocker_count; |
+ } |
+} |
+ |
+void PowerSaveBlockerImpl::Delegate::RemoveBlock() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (type_ == kPowerSaveBlockPreventDisplaySleep) { |
qinmin
2013/05/21 21:40:24
ditto
wjia(left Chromium)
2013/05/21 21:50:24
Done.
|
+ --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 |