1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #ifndef CHROME_APP_EXIT_CODE_WATCHER_WIN_H_
5 #define CHROME_APP_EXIT_CODE_WATCHER_WIN_H_
7 #include "base/process/process.h"
8 #include "base/threading/thread.h"
9 #include "base/win/scoped_handle.h"
11 // Watches for the exit code of a process and records
12 class ExitCodeWatcher {
16 ExitCodeWatcher(const ExitCodeWatcher&) = delete;
17 ExitCodeWatcher& operator=(const ExitCodeWatcher&) = delete;
21 // This function expects |process| to be open with sufficient privilege to
22 // wait and retrieve the process exit code.
23 // It checks the handle for validity and takes ownership of it.
24 bool Initialize(base::Process process);
30 const base::Process& process() const { return process_; }
31 int ExitCodeForTesting() const { return exit_code_; }
34 // Waits for the process to exit and records its exit code in a histogram.
35 // This is a blocking call.
38 // Watched process and its creation time.
39 base::Process process_;
41 // The thread that runs WaitForExit().
42 base::Thread background_thread_;
44 // The exit code of the watched process. Valid after WaitForExit.
47 // Event handle to use to stop exit watcher thread
48 base::win::ScopedHandle stop_watching_handle_;
51 #endif // CHROME_APP_EXIT_CODE_WATCHER_WIN_H_