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 g_blocker_count; | |
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, const std::string& reason) | |
20 : type_(type), reason_(reason) {} | |
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 const std::string reason_; | |
32 | |
33 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
16 }; | 34 }; |
17 | 35 |
36 void PowerSaveBlockerImpl::Delegate::ApplyBlock() { | |
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
38 if (type_ == kPowerSaveBlockPreventDisplaySleep) { | |
39 if (g_blocker_count == 0) { | |
40 ContentVideoView::KeepScreenOn(true); | |
41 } | |
42 ++g_blocker_count; | |
43 } | |
44 } | |
45 | |
46 void PowerSaveBlockerImpl::Delegate::RemoveBlock() { | |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
48 if (type_ == kPowerSaveBlockPreventDisplaySleep) { | |
49 --g_blocker_count; | |
50 if (g_blocker_count == 0) { | |
51 ContentVideoView::KeepScreenOn(false); | |
52 } | |
53 } | |
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, reason)) { |
21 // This may be called on any thread. | 59 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.
| |
22 NOTIMPLEMENTED(); | 60 BrowserThread::UI, FROM_HERE, |
61 base::Bind(&Delegate::ApplyBlock, delegate_)); | |
23 } | 62 } |
24 | 63 |
25 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { | 64 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { |
65 BrowserThread::PostTask( | |
66 BrowserThread::UI, FROM_HERE, | |
67 base::Bind(&Delegate::RemoveBlock, delegate_)); | |
26 } | 68 } |
27 | 69 |
28 } // namespace content | 70 } // namespace content |
OLD | NEW |