Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: content/browser/power_save_blocker_android.cc

Issue 15035013: Keep screen on when there is an active WebRTC session on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/power_save_blocker_impl.h" 5 #include "content/browser/power_save_blocker_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/android/content_video_view.h"
9 #include "content/public/browser/browser_thread.h"
8 10
9 namespace content { 11 namespace content {
12 namespace {
13 int blocker_count = 0;
sky 2013/05/21 21:57:48 Description? Also, since this is scoped to PowerSa
wjia(left Chromium) 2013/05/21 22:17:03 Done.
14 } // namespace
10 15
11 class PowerSaveBlockerImpl::Delegate 16 class PowerSaveBlockerImpl::Delegate
12 : public base::RefCounted<PowerSaveBlockerImpl::Delegate> { 17 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> {
18 public:
19 Delegate(PowerSaveBlockerType type) : type_(type) {}
20
21 // Does the actual work to apply or remove the desired power save block.
22 void ApplyBlock();
23 void RemoveBlock();
24
13 private: 25 private:
14 friend class base::RefCounted<Delegate>; 26 friend class base::RefCountedThreadSafe<Delegate>;
15 ~Delegate() {} 27 ~Delegate() {}
28
29 PowerSaveBlockerType type_;
sky 2013/05/21 21:57:48 const
wjia(left Chromium) 2013/05/21 22:17:03 Done.
30
31 DISALLOW_COPY_AND_ASSIGN(Delegate);
16 }; 32 };
17 33
34 void PowerSaveBlockerImpl::Delegate::ApplyBlock() {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
36 if (type_ != kPowerSaveBlockPreventDisplaySleep)
37 return;
38
39 if (blocker_count == 0)
40 ContentVideoView::KeepScreenOn(true);
41 ++blocker_count;
42 }
43
44 void PowerSaveBlockerImpl::Delegate::RemoveBlock() {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46 if (type_ != kPowerSaveBlockPreventDisplaySleep)
47 return;
48
49 --blocker_count;
50 if (blocker_count == 0)
51 ContentVideoView::KeepScreenOn(false);
52 }
53
18 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type, 54 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type,
19 const std::string& reason) { 55 const std::string& reason)
20 // TODO(wangxianzhu): Implement it. 56 : delegate_(new Delegate(type)) {
21 // This may be called on any thread. 57 // This may be called on any thread.
22 NOTIMPLEMENTED(); 58 BrowserThread::PostTask(
59 BrowserThread::UI, FROM_HERE,
60 base::Bind(&Delegate::ApplyBlock, delegate_));
23 } 61 }
24 62
25 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { 63 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() {
64 BrowserThread::PostTask(
65 BrowserThread::UI, FROM_HERE,
66 base::Bind(&Delegate::RemoveBlock, delegate_));
26 } 67 }
27 68
28 } // namespace content 69 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698