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 "device/power_save_blocker/power_save_blocker_impl.h" | 5 #include "device/power_save_blocker/power_save_blocker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.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 | 15 |
(...skipping 11 matching lines...) Expand all Loading... |
27 case PowerSaveBlocker::kReasonVideoPlayback: | 27 case PowerSaveBlocker::kReasonVideoPlayback: |
28 return chromeos::PowerPolicyController::REASON_VIDEO_PLAYBACK; | 28 return chromeos::PowerPolicyController::REASON_VIDEO_PLAYBACK; |
29 case PowerSaveBlocker::kReasonOther: | 29 case PowerSaveBlocker::kReasonOther: |
30 return chromeos::PowerPolicyController::REASON_OTHER; | 30 return chromeos::PowerPolicyController::REASON_OTHER; |
31 } | 31 } |
32 return chromeos::PowerPolicyController::REASON_OTHER; | 32 return chromeos::PowerPolicyController::REASON_OTHER; |
33 } | 33 } |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 class PowerSaveBlockerImpl::Delegate | 37 class PowerSaveBlocker::Delegate |
38 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { | 38 : public base::RefCountedThreadSafe<PowerSaveBlocker::Delegate> { |
39 public: | 39 public: |
40 Delegate(PowerSaveBlockerType type, | 40 Delegate(PowerSaveBlockerType type, |
41 Reason reason, | 41 Reason reason, |
42 const std::string& description, | 42 const std::string& description, |
43 scoped_refptr<base::SequencedTaskRunner> ui_task_runner) | 43 scoped_refptr<base::SequencedTaskRunner> ui_task_runner) |
44 : type_(type), | 44 : type_(type), |
45 reason_(reason), | 45 reason_(reason), |
46 description_(description), | 46 description_(description), |
47 block_id_(0), | 47 block_id_(0), |
48 ui_task_runner_(ui_task_runner) {} | 48 ui_task_runner_(ui_task_runner) {} |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 std::string description_; | 84 std::string description_; |
85 | 85 |
86 // ID corresponding to the block request in PowerPolicyController. | 86 // ID corresponding to the block request in PowerPolicyController. |
87 int block_id_; | 87 int block_id_; |
88 | 88 |
89 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 89 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
90 | 90 |
91 DISALLOW_COPY_AND_ASSIGN(Delegate); | 91 DISALLOW_COPY_AND_ASSIGN(Delegate); |
92 }; | 92 }; |
93 | 93 |
94 PowerSaveBlockerImpl::PowerSaveBlockerImpl( | 94 PowerSaveBlocker::PowerSaveBlocker( |
95 PowerSaveBlockerType type, | 95 PowerSaveBlockerType type, |
96 Reason reason, | 96 Reason reason, |
97 const std::string& description, | 97 const std::string& description, |
98 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 98 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
99 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) | 99 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) |
100 : delegate_(new Delegate(type, reason, description, ui_task_runner)), | 100 : delegate_(new Delegate(type, reason, description, ui_task_runner)), |
101 ui_task_runner_(ui_task_runner), | 101 ui_task_runner_(ui_task_runner), |
102 blocking_task_runner_(blocking_task_runner) { | 102 blocking_task_runner_(blocking_task_runner) { |
103 ui_task_runner_->PostTask(FROM_HERE, | 103 ui_task_runner_->PostTask(FROM_HERE, |
104 base::Bind(&Delegate::ApplyBlock, delegate_)); | 104 base::Bind(&Delegate::ApplyBlock, delegate_)); |
105 } | 105 } |
106 | 106 |
107 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { | 107 PowerSaveBlocker::~PowerSaveBlocker() { |
108 ui_task_runner_->PostTask(FROM_HERE, | 108 ui_task_runner_->PostTask(FROM_HERE, |
109 base::Bind(&Delegate::RemoveBlock, delegate_)); | 109 base::Bind(&Delegate::RemoveBlock, delegate_)); |
110 } | 110 } |
111 | 111 |
112 } // namespace device | 112 } // namespace device |
OLD | NEW |