OLD | NEW |
---|---|
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; | |
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) | |
20 : 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.
| |
21 | |
22 // Does the actual work to apply or remove the desired power save block. | |
23 void ApplyBlock(); | |
24 void RemoveBlock(); | |
25 | |
13 private: | 26 private: |
14 friend class base::RefCounted<Delegate>; | 27 friend class base::RefCountedThreadSafe<Delegate>; |
15 ~Delegate() {} | 28 ~Delegate() {} |
29 | |
30 PowerSaveBlockerType type_; | |
31 | |
32 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
16 }; | 33 }; |
17 | 34 |
35 void PowerSaveBlockerImpl::Delegate::ApplyBlock() { | |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
37 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.
| |
38 if (blocker_count == 0) | |
39 ContentVideoView::KeepScreenOn(true); | |
40 ++blocker_count; | |
41 } | |
42 } | |
43 | |
44 void PowerSaveBlockerImpl::Delegate::RemoveBlock() { | |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
46 if (type_ == kPowerSaveBlockPreventDisplaySleep) { | |
qinmin
2013/05/21 21:40:24
ditto
wjia(left Chromium)
2013/05/21 21:50:24
Done.
| |
47 --blocker_count; | |
48 if (blocker_count == 0) | |
49 ContentVideoView::KeepScreenOn(false); | |
50 } | |
51 } | |
52 | |
18 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type, | 53 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type, |
19 const std::string& reason) { | 54 const std::string& reason) |
20 // TODO(wangxianzhu): Implement it. | 55 : delegate_(new Delegate(type)) { |
21 // This may be called on any thread. | 56 // This may be called on any thread. |
22 NOTIMPLEMENTED(); | 57 BrowserThread::PostTask( |
58 BrowserThread::UI, FROM_HERE, | |
59 base::Bind(&Delegate::ApplyBlock, delegate_)); | |
23 } | 60 } |
24 | 61 |
25 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { | 62 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { |
63 BrowserThread::PostTask( | |
64 BrowserThread::UI, FROM_HERE, | |
65 base::Bind(&Delegate::RemoveBlock, delegate_)); | |
26 } | 66 } |
27 | 67 |
28 } // namespace content | 68 } // namespace content |
OLD | NEW |