Chromium Code Reviews| Index: remoting/host/linux/certificate_watcher.h |
| diff --git a/remoting/host/linux/certificate_watcher.h b/remoting/host/linux/certificate_watcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..20bd7c82ea7a917e9cb6b78caf9b92f968016411 |
| --- /dev/null |
| +++ b/remoting/host/linux/certificate_watcher.h |
| @@ -0,0 +1,106 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef REMOTING_HOST_LINUX_CERTIFICATE_WATCHER_H_ |
| +#define REMOTING_HOST_LINUX_CERTIFICATE_WATCHER_H_ |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/files/file_path_watcher.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/timer/timer.h" |
| +#include "remoting/base/auto_thread_task_runner.h" |
| +#include "remoting/host/host_status_monitor.h" |
| +#include "remoting/host/host_status_observer.h" |
| + |
| +namespace remoting { |
| + |
| +// This class watches the cert database and kills the host when a change of the |
| +// database is detected. The runner script will restart the host when the host |
| +// is killed then the new host will capture any new changes of the database. |
| +// |
| +// Acceptable false positives will be caused by desktop sessions and other |
| +// external programs. |
| +// |
| +// Implements HostStatusObserver to defer restart action when the host is |
| +// connected to a client. |
| +class CertificateWatcher : public remoting::HostStatusObserver { |
| + public: |
| + // |restart_action| will be run on |network_runner|, which should be on the |
| + // thread that the HostStatusObserver functions get called. |
| + CertificateWatcher(const base::Closure& restart_action, |
| + scoped_refptr<base::SingleThreadTaskRunner> network_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> io_runner); |
| + |
| + ~CertificateWatcher() override; |
| + |
| + // Starts watching file changes on file thread and calling restart on |
| + // network thread if necessary. |
| + // Note that this function is asynchronous and checking Started() right after |
| + // calling Start() may always return false. |
| + void Start(); |
| + |
| + // Returns true if the watcher has started. |
| + bool Started() const; |
|
Sergey Ulanov
2016/04/04 19:29:37
call it is_started()
Yuwei
2016/04/04 21:40:24
Is it Chromium's convention to name getters using
Sergey Ulanov
2016/04/04 21:44:38
See https://google.github.io/styleguide/cppguide.h
Yuwei
2016/04/04 23:42:25
Done.
|
| + |
| + // Sets the monitor to observe connection/disconnection events to toggle |
| + // the inhibit mode. |
| + // Adds |this| as an observer to the monitor if it is not null. |
| + // Removes |this| as an observer from the old monitor if it is not null. |
| + void SetMonitor(base::WeakPtr<HostStatusMonitor> monitor); |
| + |
| + // HostStatusObserver interface. |
| + void OnClientConnected(const std::string& jid) override; |
| + void OnClientDisconnected(const std::string& jid) override; |
| + |
| + // Will only work before the watcher starts. |
| + void SetDelayForTests(const base::TimeDelta& delay); |
| + void SetWatchPathForTests(const base::FilePath& watch_path); |
| + |
| + private: |
| + // Callback passed to |file_watcher_|. |
| + void OnCertDirectoryChanged(const base::FilePath& path, bool error); |
| + |
| + // Called by |restart_timer_| when it's time to reset the host. |
| + // It will defer restart if |inhibit_restart_scheduled_| flag is set to true. |
| + void OnTimer(); |
| + |
| + void StartWatcherOnIo(); |
| + void StartTimerOnNetwork(); |
| + |
| + // Reference to the monitor |
| + base::WeakPtr<HostStatusMonitor> monitor_; |
| + |
| + // Called when a restart is scheduled. |
| + base::Closure restart_action_; |
| + |
| + // The runner that runs the timer. |
| + scoped_refptr<base::SingleThreadTaskRunner> network_runner_; |
| + |
| + // The runner that runs the file watcher. |
| + scoped_refptr<base::SingleThreadTaskRunner> io_runner_; |
| + |
| + bool inhibit_mode_ = false; |
| + |
| + bool restart_pending_ = false; |
| + |
| + // Path of the certificate files/directories. |
| + base::FilePath cert_watch_path_; |
| + |
| + // The file watcher to watch changes inside the certificate folder. |
| + scoped_ptr<base::FilePathWatcher> file_watcher_; |
| + |
| + // The time to wait to restart when it is scheduled. |
| + base::TimeDelta delay_; |
| + |
| + // Timer to delay the restart action. |
| + scoped_ptr<base::DelayTimer> restart_timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CertificateWatcher); |
| +}; |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_HOST_LINUX_CERTIFICATE_WATCHER_H_ |