zijiehe | 726a662 | 2016-07-15 21:44:27 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Lei Zhang | 8232b34 | 2021-04-21 20:15:36 | [diff] [blame] | 5 | #ifndef REMOTING_HOST_HOST_POWER_SAVE_BLOCKER_H_ |
| 6 | #define REMOTING_HOST_HOST_POWER_SAVE_BLOCKER_H_ |
zijiehe | 726a662 | 2016-07-15 21:44:27 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/memory/ref_counted.h" |
| 12 | #include "base/memory/weak_ptr.h" |
zijiehe | 726a662 | 2016-07-15 21:44:27 | [diff] [blame] | 13 | #include "remoting/host/host_status_observer.h" |
Ke He | ad4bdd4 | 2017-07-13 01:48:19 | [diff] [blame] | 14 | #include "services/device/wake_lock/power_save_blocker/power_save_blocker.h" |
zijiehe | 726a662 | 2016-07-15 21:44:27 | [diff] [blame] | 15 | |
| 16 | namespace base { |
| 17 | |
| 18 | class SingleThreadTaskRunner; |
| 19 | |
| 20 | } // namespace base |
| 21 | |
| 22 | namespace remoting { |
| 23 | |
zijiehe | 726a662 | 2016-07-15 21:44:27 | [diff] [blame] | 24 | class HostStatusMonitor; |
| 25 | |
| 26 | // A HostStatusObserver to block screen saver from taking effect during the |
| 27 | // lifetime of a remoting connection. |
| 28 | class HostPowerSaveBlocker : public HostStatusObserver { |
| 29 | public: |
| 30 | HostPowerSaveBlocker( |
Sergey Ulanov | cc04df9 | 2017-07-07 18:33:41 | [diff] [blame] | 31 | scoped_refptr<HostStatusMonitor> monitor, |
zijiehe | 726a662 | 2016-07-15 21:44:27 | [diff] [blame] | 32 | const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 33 | const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner); |
| 34 | |
| 35 | ~HostPowerSaveBlocker() override; |
| 36 | |
| 37 | void OnClientConnected(const std::string& jid) override; |
| 38 | void OnClientDisconnected(const std::string& jid) override; |
| 39 | |
| 40 | private: |
| 41 | friend class HostPowerSaveBlockerTest; |
| 42 | |
Sergey Ulanov | cc04df9 | 2017-07-07 18:33:41 | [diff] [blame] | 43 | scoped_refptr<HostStatusMonitor> monitor_; |
| 44 | |
zijiehe | 726a662 | 2016-07-15 21:44:27 | [diff] [blame] | 45 | scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 46 | scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
Daniel Erat | c2e8ef036 | 2017-11-04 01:06:13 | [diff] [blame] | 47 | |
| 48 | // The remoting host doesn't have access to the service manager, so it |
| 49 | // instantiates device::PowerSaveBlocker directly: https://crbug.com/689423 |
zijiehe | 726a662 | 2016-07-15 21:44:27 | [diff] [blame] | 50 | std::unique_ptr<device::PowerSaveBlocker> blocker_; |
| 51 | }; |
| 52 | |
| 53 | } // namespace remoting |
| 54 | |
Lei Zhang | 8232b34 | 2021-04-21 20:15:36 | [diff] [blame] | 55 | #endif // REMOTING_HOST_HOST_POWER_SAVE_BLOCKER_H_ |