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

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: code review: static member 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 {
10 12
11 class PowerSaveBlockerImpl::Delegate 13 class PowerSaveBlockerImpl::Delegate
12 : public base::RefCounted<PowerSaveBlockerImpl::Delegate> { 14 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> {
15 public:
16 Delegate(PowerSaveBlockerType type) : type_(type) {}
sky 2013/05/21 23:54:38 nit: explicit
wjia(left Chromium) 2013/05/22 02:17:51 Done.
17
18 // Does the actual work to apply or remove the desired power save block.
19 void ApplyBlock();
20 void RemoveBlock();
21
13 private: 22 private:
14 friend class base::RefCounted<Delegate>; 23 friend class base::RefCountedThreadSafe<Delegate>;
15 ~Delegate() {} 24 ~Delegate() {}
25
26 // The counter of requests from clients for type
27 // kPowerSaveBlockPreventDisplaySleep.
28 static int blocker_count_;
29 const PowerSaveBlockerType type_;
30
31 DISALLOW_COPY_AND_ASSIGN(Delegate);
16 }; 32 };
17 33
34 int PowerSaveBlockerImpl::Delegate::blocker_count_ = 0;
35
36 void PowerSaveBlockerImpl::Delegate::ApplyBlock() {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
38 if (type_ != kPowerSaveBlockPreventDisplaySleep)
39 return;
40
41 if (blocker_count_ == 0)
42 ContentVideoView::KeepScreenOn(true);
joth 2013/05/21 23:56:08 Having PowerSaveBlocker depend on ContentVideoView
wjia(left Chromium) 2013/05/22 02:17:51 Yeah, we could iterate later.
joth 2013/05/24 18:07:00 I realized part of the answer - the screen_on stat
43 ++blocker_count_;
44 }
45
46 void PowerSaveBlockerImpl::Delegate::RemoveBlock() {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48 if (type_ != kPowerSaveBlockPreventDisplaySleep)
49 return;
50
51 --blocker_count_;
52 if (blocker_count_ == 0)
53 ContentVideoView::KeepScreenOn(false);
54 }
55
18 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type, 56 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type,
19 const std::string& reason) { 57 const std::string& reason)
20 // TODO(wangxianzhu): Implement it. 58 : delegate_(new Delegate(type)) {
21 // This may be called on any thread. 59 // This may be called on any thread.
22 NOTIMPLEMENTED(); 60 BrowserThread::PostTask(
61 BrowserThread::UI, FROM_HERE,
62 base::Bind(&Delegate::ApplyBlock, delegate_));
23 } 63 }
24 64
25 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { 65 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() {
66 BrowserThread::PostTask(
67 BrowserThread::UI, FROM_HERE,
68 base::Bind(&Delegate::RemoveBlock, delegate_));
26 } 69 }
27 70
28 } // namespace content 71 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698