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

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

Issue 946643002: Use PowerSaveBlocker for audio and video on Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: apply nits Created 5 years, 10 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
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 <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "chromeos/dbus/power_policy_controller.h" 14 #include "chromeos/dbus/power_policy_controller.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 namespace {
20
21 // Converts a PowerSaveBlocker::Reason to a
22 // chromeos::PowerPolicyController::WakeLockReason.
23 chromeos::PowerPolicyController::WakeLockReason GetWakeLockReason(
24 PowerSaveBlocker::Reason reason) {
25 switch (reason) {
26 case PowerSaveBlocker::kReasonAudioPlayback:
27 return chromeos::PowerPolicyController::REASON_AUDIO_PLAYBACK;
28 case PowerSaveBlocker::kReasonVideoPlayback:
29 return chromeos::PowerPolicyController::REASON_VIDEO_PLAYBACK;
30 case PowerSaveBlocker::kReasonOther:
31 return chromeos::PowerPolicyController::REASON_OTHER;
32 }
33 return chromeos::PowerPolicyController::REASON_OTHER;
34 }
35
36 } // namespace
37
19 class PowerSaveBlockerImpl::Delegate 38 class PowerSaveBlockerImpl::Delegate
20 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { 39 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> {
21 public: 40 public:
22 Delegate(PowerSaveBlockerType type, const std::string& reason) 41 Delegate(PowerSaveBlockerType type,
23 : type_(type), 42 Reason reason,
24 reason_(reason), 43 const std::string& description)
25 block_id_(0) {} 44 : type_(type), reason_(reason), description_(description), block_id_(0) {}
26 45
27 void ApplyBlock() { 46 void ApplyBlock() {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
29 if (!chromeos::PowerPolicyController::IsInitialized()) 48 if (!chromeos::PowerPolicyController::IsInitialized())
30 return; 49 return;
31 50
32 auto* controller = chromeos::PowerPolicyController::Get(); 51 auto* controller = chromeos::PowerPolicyController::Get();
33 switch (type_) { 52 switch (type_) {
34 case kPowerSaveBlockPreventAppSuspension: 53 case kPowerSaveBlockPreventAppSuspension:
35 block_id_ = controller->AddSystemWakeLock(reason_); 54 block_id_ = controller->AddSystemWakeLock(GetWakeLockReason(reason_),
55 description_);
36 break; 56 break;
37 case kPowerSaveBlockPreventDisplaySleep: 57 case kPowerSaveBlockPreventDisplaySleep:
38 block_id_ = controller->AddScreenWakeLock(reason_); 58 block_id_ = controller->AddScreenWakeLock(GetWakeLockReason(reason_),
59 description_);
39 break; 60 break;
40 default: 61 default:
41 NOTREACHED() << "Unhandled block type " << type_; 62 NOTREACHED() << "Unhandled block type " << type_;
42 } 63 }
43 } 64 }
44 65
45 void RemoveBlock() { 66 void RemoveBlock() {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
47 if (!chromeos::PowerPolicyController::IsInitialized()) 68 if (!chromeos::PowerPolicyController::IsInitialized())
48 return; 69 return;
49 70
50 chromeos::PowerPolicyController::Get()->RemoveWakeLock(block_id_); 71 chromeos::PowerPolicyController::Get()->RemoveWakeLock(block_id_);
51 } 72 }
52 73
53 private: 74 private:
54 friend class base::RefCountedThreadSafe<Delegate>; 75 friend class base::RefCountedThreadSafe<Delegate>;
55 virtual ~Delegate() {} 76 virtual ~Delegate() {}
56 77
57 PowerSaveBlockerType type_; 78 PowerSaveBlockerType type_;
58 std::string reason_; 79 Reason reason_;
80 std::string description_;
59 81
60 // ID corresponding to the block request in PowerPolicyController. 82 // ID corresponding to the block request in PowerPolicyController.
61 int block_id_; 83 int block_id_;
62 84
63 DISALLOW_COPY_AND_ASSIGN(Delegate); 85 DISALLOW_COPY_AND_ASSIGN(Delegate);
64 }; 86 };
65 87
66 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type, 88 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type,
67 const std::string& reason) 89 Reason reason,
68 : delegate_(new Delegate(type, reason)) { 90 const std::string& description)
91 : delegate_(new Delegate(type, reason, description)) {
69 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 92 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
70 base::Bind(&Delegate::ApplyBlock, delegate_)); 93 base::Bind(&Delegate::ApplyBlock, delegate_));
71 } 94 }
72 95
73 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { 96 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() {
74 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 97 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
75 base::Bind(&Delegate::RemoveBlock, delegate_)); 98 base::Bind(&Delegate::RemoveBlock, delegate_));
76 } 99 }
77 100
78 } // namespace content 101 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/power_save_blocker_android.cc ('k') | content/browser/power_save_blocker_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698