blob: b3601d2c8bf535ccb6ae187fac34db268a61b3c5 [file] [log] [blame]
siggic0d0a0e2014-11-17 23:29:191// Copyright (c) 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.
siggi420541c2014-11-18 23:16:324#ifndef COMPONENTS_BROWSER_WATCHER_EXIT_CODE_WATCHER_WIN_H_
5#define COMPONENTS_BROWSER_WATCHER_EXIT_CODE_WATCHER_WIN_H_
siggic0d0a0e2014-11-17 23:29:196
7#include "base/macros.h"
siggi581938f2014-12-18 21:17:158#include "base/process/process.h"
Chris Davis2e8cc3af2020-02-06 21:40:329#include "base/threading/thread.h"
siggic0d0a0e2014-11-17 23:29:1910
siggic0d0a0e2014-11-17 23:29:1911namespace browser_watcher {
12
Chris Davis2e8cc3af2020-02-06 21:40:3213// Watches for the exit code of a process and records
siggic0d0a0e2014-11-17 23:29:1914class ExitCodeWatcher {
15 public:
Chris Davis2e8cc3af2020-02-06 21:40:3216 ExitCodeWatcher();
siggic0d0a0e2014-11-17 23:29:1917 ~ExitCodeWatcher();
18
erikwright7c4a4262015-01-09 18:32:3319 // This function expects |process| to be open with sufficient privilege to
20 // wait and retrieve the process exit code.
siggic0d0a0e2014-11-17 23:29:1921 // It checks the handle for validity and takes ownership of it.
erikwright7c4a4262015-01-09 18:32:3322 bool Initialize(base::Process process);
siggic0d0a0e2014-11-17 23:29:1923
Chris Davis2e8cc3af2020-02-06 21:40:3224 bool StartWatching();
siggic0d0a0e2014-11-17 23:29:1925
siggi581938f2014-12-18 21:17:1526 const base::Process& process() const { return process_; }
siggid497a1a2014-12-19 15:20:5127 int exit_code() const { return exit_code_; }
siggic0d0a0e2014-11-17 23:29:1928
29 private:
30 // Writes |exit_code| to registry, returns true on success.
31 bool WriteProcessExitCode(int exit_code);
32
Chris Davis2e8cc3af2020-02-06 21:40:3233 // Waits for the process to exit and records its exit code in registry.
34 // This is a blocking call.
35 void WaitForExit();
siggic0d0a0e2014-11-17 23:29:1936
siggid497a1a2014-12-19 15:20:5137 // Watched process and its creation time.
siggi581938f2014-12-18 21:17:1538 base::Process process_;
Chris Davis2e8cc3af2020-02-06 21:40:3239
40 // The thread that runs WaitForExit().
41 base::Thread background_thread_;
siggic0d0a0e2014-11-17 23:29:1942
siggid497a1a2014-12-19 15:20:5143 // The exit code of the watched process. Valid after WaitForExit.
44 int exit_code_;
45
siggic0d0a0e2014-11-17 23:29:1946 DISALLOW_COPY_AND_ASSIGN(ExitCodeWatcher);
47};
48
49} // namespace browser_watcher
50
siggi420541c2014-11-18 23:16:3251#endif // COMPONENTS_BROWSER_WATCHER_EXIT_CODE_WATCHER_WIN_H_