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

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: Reviewer's Feedback 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/host/host_status_monitor.h"
15 #include "remoting/host/host_status_observer.h"
16
17 namespace remoting {
18
19 // This class watches the cert database and kills the host when a change of the
Sergey Ulanov 2016/04/06 21:04:06 Suggest rewording the first sentence: // This cla
Yuwei 2016/04/07 00:35:41 Done.
20 // database is detected. The runner script will restart the host when the host
21 // is killed then the new host will capture any new changes of the database.
22 //
23 // Acceptable false positives will be caused by desktop sessions and other
24 // external programs.
25 //
26 // Implements HostStatusObserver to defer restart action when the host is
27 // connected to a client.
28 class CertificateWatcher : public remoting::HostStatusObserver {
29 public:
30 CertificateWatcher(
31 const base::Closure& restart_action,
32 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
33
34 // The message loop of io_task_runner MUST be running after the destructor is
35 // called, otherwise there will be memory leaks.
36 ~CertificateWatcher() override;
37
38 // Starts watching file changes
39 // calling |restart_action_| when the host need to restart.
40 void Start();
41
42 // Sets the monitor to observe connection/disconnection events to toggle
43 // the inhibit mode. Should be called after the watcher starts.
44 // Adds |this| as an observer to the monitor.
45 // Removes |this| as an observer from the old monitor if it is not null.
46 void SetMonitor(base::WeakPtr<HostStatusMonitor> monitor);
47
48 // HostStatusObserver interface.
49 void OnClientConnected(const std::string& jid) override;
50 void OnClientDisconnected(const std::string& jid) override;
51
52 // Will only work before the watcher starts.
53 void SetDelayForTests(const base::TimeDelta& delay);
54 void SetWatchPathForTests(const base::FilePath& watch_path);
55
56 private:
57 // Returns true if the watcher has started.
58 bool is_started() const;
59
60 // Callback passed to |file_watcher_|. Runs in IO thread.
61 static void OnCertDirectoryChanged(
62 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
63 base::WeakPtr<CertificateWatcher> watcher_, const base::FilePath& path,
64 bool error);
65
66 // Runs in the caller's thread.
67 void DirectoryChanged(const base::FilePath& path, bool error);
68
69 // Called by |restart_timer_| when it's time to reset the host.
70 // It will defer restart if |inhibit_restart_scheduled_| flag is set to true.
71 void OnTimer();
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 everything other than the file watcher.
80 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
81
82 // The runner that runs the file watcher.
83 scoped_refptr<base::SingleThreadTaskRunner> io_task_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 base::WeakPtrFactory<CertificateWatcher> weak_factory_;
102
103 DISALLOW_COPY_AND_ASSIGN(CertificateWatcher);
104 };
105
106 } // namespace remoting
107
108 #endif // REMOTING_HOST_LINUX_CERTIFICATE_WATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698