OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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_SHUTDOWN_WATCHDOG_H_ |
| 6 #define REMOTING_HOST_SHUTDOWN_WATCHDOG_H_ |
| 7 |
| 8 #include "base/synchronization/lock.h" |
| 9 #include "base/threading/watchdog.h" |
| 10 |
| 11 namespace remoting { |
| 12 |
| 13 // This implements a watchdog timer that ensures the host process eventually |
| 14 // terminates, even if some threads are blocked or being kept alive for |
| 15 // some reason. This is not expected to trigger if host shutdown is working |
| 16 // correctly (on a normally loaded system). The triggering of the alarm |
| 17 // indicates a sign of trouble, and so the Alarm() method will log some |
| 18 // diagnostic information before shutting down the process. |
| 19 class ShutdownWatchdog : public base::Watchdog { |
| 20 public: |
| 21 // Creates a watchdog that waits for |duration| (after the watchdog is |
| 22 // armed) before shutting down the process. |
| 23 explicit ShutdownWatchdog(const base::TimeDelta& duration); |
| 24 |
| 25 // This method should be called to set the process's exit-code before arming |
| 26 // the watchdog. Otherwise an exit-code of 0 is assumed. |
| 27 void SetExitCode(int exit_code); |
| 28 |
| 29 void Alarm() override; |
| 30 |
| 31 private: |
| 32 int exit_code_; |
| 33 |
| 34 // Protects |exit_code_|, since Alarm() gets called on a separate thread. |
| 35 base::Lock lock_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(ShutdownWatchdog); |
| 38 }; |
| 39 |
| 40 } // namespace remoting |
| 41 |
| 42 #endif // REMOTING_HOST_SHUTDOWN_WATCHDOG_H_ |
OLD | NEW |