Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
|
Sergey Ulanov
2016/03/30 21:02:45
remove this empty line
Yuwei
2016/03/31 17:40:04
Done.
| |
| 15 #include "remoting/base/auto_thread_task_runner.h" | |
| 16 #include "remoting/host/host_status_monitor.h" | |
| 17 #include "remoting/host/host_status_observer.h" | |
| 18 | |
| 19 namespace remoting { | |
| 20 | |
| 21 // This class watches the NSS database and kills the host when a change of the | |
| 22 // database is detected. The runner script will restart the host when the host | |
| 23 // is killed then the new host will capture any new changes of the database. | |
| 24 // | |
| 25 // Acceptable false positives will be caused by desktop sessions and other | |
| 26 // external programs. | |
| 27 // | |
| 28 // Implements HostStatusObserver to defer restart action when the host is | |
| 29 // connected to a client. | |
| 30 class CertificateWatcher : public remoting::HostStatusObserver { | |
| 31 public: | |
| 32 CertificateWatcher(int delay, const base::Closure& restart_action); | |
| 33 CertificateWatcher(int delay, | |
|
Sergey Ulanov
2016/03/30 21:02:45
Does the delay really need to be passed to the con
Yuwei
2016/03/30 21:37:00
So may just have a constant inside the Certificate
Yuwei
2016/03/31 17:40:04
Done.
| |
| 34 const base::Closure& restart_action, | |
| 35 const base::Closure& restart_deferred_action, | |
|
Sergey Ulanov
2016/03/30 21:02:45
This parameter is used only for tests. Do you real
Yuwei
2016/03/30 21:37:00
In fact this constructor is basically for tests on
| |
| 36 const base::FilePath& watch_path); | |
|
Sergey Ulanov
2016/03/30 21:02:45
This argument is used for tests only. Replace it w
Yuwei
2016/03/30 21:37:00
okay
Yuwei
2016/03/31 17:40:04
Done.
| |
| 37 | |
| 38 // Constructs watcher with given impl. Will take ownership. | |
| 39 ~CertificateWatcher() override; | |
| 40 | |
| 41 | |
|
Sergey Ulanov
2016/03/30 21:02:45
remove extra empty lines
| |
| 42 | |
| 43 // Starts at current thread. | |
| 44 // Add itself to the monitor as an observer if the monitor is not null. | |
| 45 void Start(base::WeakPtr<HostStatusMonitor> monitor); | |
| 46 | |
| 47 // Starts on specified thread | |
| 48 void StartOn(scoped_refptr<AutoThreadTaskRunner> runner, | |
|
Sergey Ulanov
2016/03/30 21:02:45
Why do you need this method?
Yuwei
2016/03/30 21:37:00
For most of the cases you can simply run watcher o
Yuwei
2016/03/31 17:40:05
Removed
| |
| 49 base::WeakPtr<HostStatusMonitor> monitor); | |
| 50 | |
| 51 void Stop(); | |
| 52 | |
| 53 // Marks inhibit_restart_scheduled_ flag without calling the restart action | |
| 54 void Inhibit(); | |
| 55 | |
| 56 // Leaves inhibit mode and schedule restart action if | |
| 57 // inhibit_restart_scheduled_ is marked in previous inhibit mode. | |
| 58 void Uninhibit(); | |
|
Sergey Ulanov
2016/03/30 21:02:45
Do you still need this?
Yuwei
2016/03/30 21:37:00
Basically only observer's functions are calling th
Yuwei
2016/03/31 17:40:05
Changed to SetInhibit()
| |
| 59 | |
| 60 // HostStatusObserver interface: | |
|
Sergey Ulanov
2016/03/30 21:02:45
s/:/./
Yuwei
2016/03/31 17:40:05
Done.
| |
| 61 | |
| 62 // inhibits CertificateWatcher when the client connects | |
|
Sergey Ulanov
2016/03/30 21:02:45
Don't need comments for interface overrides..
Yuwei
2016/03/31 17:40:04
Done.
| |
| 63 void OnClientConnected(const std::string& jid) override; | |
| 64 | |
| 65 // uninhibits CertificateWatcher when the client disconnects | |
| 66 void OnClientDisconnected(const std::string& jid) override; | |
| 67 | |
| 68 private: | |
| 69 bool inhibit_mode_ = false; | |
| 70 | |
| 71 // true if a restart is scheduled in inhibit mode. | |
| 72 bool inhibit_restart_scheduled_ = false; | |
| 73 | |
| 74 // The time to wait to restart when it is scheduled. | |
| 75 int delay_; | |
|
Sergey Ulanov
2016/03/30 21:02:45
Use base::TimeDelta for time-delta values.
Yuwei
2016/03/31 17:40:04
Done.
| |
| 76 | |
| 77 // reference to the monitor | |
| 78 base::WeakPtr<HostStatusMonitor> monitor_; | |
|
Sergey Ulanov
2016/03/30 21:02:45
Move this and all other values passed to the const
Yuwei
2016/03/31 17:40:04
Done.
| |
| 79 | |
| 80 // called when a restart is scheduled. | |
| 81 base::Closure restart_action_; | |
| 82 | |
| 83 // called when the certificate is updated during inhibit mode. | |
| 84 // This is just for notification and it shouldn't restart the host. | |
| 85 base::Closure restart_deferred_action_; | |
| 86 | |
| 87 // The file watcher to watch the certificate. | |
|
Sergey Ulanov
2016/03/30 21:02:45
the watcher watches certs directory, which may con
Yuwei
2016/03/31 17:40:04
Changed comments...
| |
| 88 scoped_ptr<base::FilePathWatcher> file_watcher_; | |
| 89 | |
| 90 // Timer to delay the restart action. | |
| 91 scoped_ptr<base::DelayTimer> restart_timer_; | |
| 92 | |
| 93 // path of the NSS files/directories. | |
| 94 base::FilePath nss_watch_path_; | |
|
Sergey Ulanov
2016/03/30 21:02:44
Move this above the |file_watcher_|, so the order
Yuwei
2016/03/31 17:40:04
Done.
| |
| 95 | |
| 96 // called when the certificate get updated. | |
|
Sergey Ulanov
2016/03/30 21:02:45
nit: Suggest rewarding: "Callback passed to |file_
Yuwei
2016/03/31 17:40:04
Done.
| |
| 97 void OnNSSUpdate(const base::FilePath& path, bool error); | |
|
Sergey Ulanov
2016/03/30 21:02:45
Functions should be defined before data memebers:
Sergey Ulanov
2016/03/30 21:02:45
Suggest renaming to OnCertDirectoryChanged(). "NSS
Yuwei
2016/03/31 17:40:05
Done.
| |
| 98 | |
| 99 // called when the timer ticks. | |
|
Sergey Ulanov
2016/03/30 21:02:45
This comment doesn't add anything. Maybe reword it
Yuwei
2016/03/31 17:40:04
Done.
| |
| 100 void OnTimer(); | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(CertificateWatcher); | |
| 103 }; | |
| 104 | |
| 105 } // namespace remoting | |
| 106 | |
| 107 #endif // REMOTING_HOST_LINUX_CERTIFICATE_WATCHER_H_ | |
| OLD | NEW |