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

Side by Side Diff: remoting/host/linux/certificate_watcher.h

Issue 1838313002: Restart the host when the third party auth certificate changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback from sergeyu@ Created 4 years, 8 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
(Empty)
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
5 #ifndef REMOTING_HOST_LINUX_CERTIFICATE_WATCHER_H_
6 #define REMOTING_HOST_LINUX_CERTIFICATE_WATCHER_H_
7
8 #include "base/files/file_path.h"
9 #include "base/files/file_path_watcher.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/timer/timer.h"
14 #include "remoting/base/auto_thread_task_runner.h"
15 #include "remoting/host/host_status_monitor.h"
16 #include "remoting/host/host_status_observer.h"
17
18 namespace remoting {
19
20 // This class watches the cert database and kills the host when a change of the
21 // database is detected. The runner script will restart the host when the host
22 // is killed then the new host will capture any new changes of the database.
23 //
24 // Acceptable false positives will be caused by desktop sessions and other
25 // external programs.
26 //
27 // Implements HostStatusObserver to defer restart action when the host is
28 // connected to a client.
29 class CertificateWatcher : public remoting::HostStatusObserver {
30 public:
31 // |restart_action| will be run on |network_runner|, which should be on the
32 // thread that the HostStatusObserver functions get called.
33 CertificateWatcher(const base::Closure& restart_action,
34 scoped_refptr<base::SingleThreadTaskRunner> network_runner,
35 scoped_refptr<base::SingleThreadTaskRunner> io_runner);
36
37 ~CertificateWatcher() override;
38
39 // Starts watching file changes on file thread and calling restart on
40 // network thread if necessary.
41 // Note that this function is asynchronous and checking Started() right after
42 // calling Start() may always return false.
43 void Start();
44
45 // Returns true if the watcher has started.
46 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.
47
48 // Sets the monitor to observe connection/disconnection events to toggle
49 // the inhibit mode.
50 // Adds |this| as an observer to the monitor if it is not null.
51 // Removes |this| as an observer from the old monitor if it is not null.
52 void SetMonitor(base::WeakPtr<HostStatusMonitor> monitor);
53
54 // HostStatusObserver interface.
55 void OnClientConnected(const std::string& jid) override;
56 void OnClientDisconnected(const std::string& jid) override;
57
58 // Will only work before the watcher starts.
59 void SetDelayForTests(const base::TimeDelta& delay);
60 void SetWatchPathForTests(const base::FilePath& watch_path);
61
62 private:
63 // Callback passed to |file_watcher_|.
64 void OnCertDirectoryChanged(const base::FilePath& path, bool error);
65
66 // Called by |restart_timer_| when it's time to reset the host.
67 // It will defer restart if |inhibit_restart_scheduled_| flag is set to true.
68 void OnTimer();
69
70 void StartWatcherOnIo();
71 void StartTimerOnNetwork();
72
73 // Reference to the monitor
74 base::WeakPtr<HostStatusMonitor> monitor_;
75
76 // Called when a restart is scheduled.
77 base::Closure restart_action_;
78
79 // The runner that runs the timer.
80 scoped_refptr<base::SingleThreadTaskRunner> network_runner_;
81
82 // The runner that runs the file watcher.
83 scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
84
85 bool inhibit_mode_ = false;
86
87 bool restart_pending_ = false;
88
89 // Path of the certificate files/directories.
90 base::FilePath cert_watch_path_;
91
92 // The file watcher to watch changes inside the certificate folder.
93 scoped_ptr<base::FilePathWatcher> file_watcher_;
94
95 // The time to wait to restart when it is scheduled.
96 base::TimeDelta delay_;
97
98 // Timer to delay the restart action.
99 scoped_ptr<base::DelayTimer> restart_timer_;
100
101 DISALLOW_COPY_AND_ASSIGN(CertificateWatcher);
102 };
103
104 } // namespace remoting
105
106 #endif // REMOTING_HOST_LINUX_CERTIFICATE_WATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698