| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/browser_watcher/exit_code_watcher_win.h" | 5 #include "components/browser_watcher/exit_code_watcher_win.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
| 9 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 10 #include "base/win/registry.h" | 12 #include "base/win/registry.h" |
| 11 | 13 |
| 12 namespace browser_watcher { | 14 namespace browser_watcher { |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 base::string16 GetValueName(const base::Time creation_time, | 18 base::string16 GetValueName(const base::Time creation_time, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 43 | 45 |
| 44 FILETIME creation_time = {}; | 46 FILETIME creation_time = {}; |
| 45 FILETIME dummy = {}; | 47 FILETIME dummy = {}; |
| 46 if (!::GetProcessTimes(process.Handle(), &creation_time, &dummy, &dummy, | 48 if (!::GetProcessTimes(process.Handle(), &creation_time, &dummy, &dummy, |
| 47 &dummy)) { | 49 &dummy)) { |
| 48 PLOG(ERROR) << "Invalid parent handle, can't get parent process times."; | 50 PLOG(ERROR) << "Invalid parent handle, can't get parent process times."; |
| 49 return false; | 51 return false; |
| 50 } | 52 } |
| 51 | 53 |
| 52 // Success, take ownership of the process. | 54 // Success, take ownership of the process. |
| 53 process_ = process.Pass(); | 55 process_ = std::move(process); |
| 54 process_creation_time_ = base::Time::FromFileTime(creation_time); | 56 process_creation_time_ = base::Time::FromFileTime(creation_time); |
| 55 | 57 |
| 56 // Start by writing the value STILL_ACTIVE to registry, to allow detection | 58 // Start by writing the value STILL_ACTIVE to registry, to allow detection |
| 57 // of the case where the watcher itself is somehow terminated before it can | 59 // of the case where the watcher itself is somehow terminated before it can |
| 58 // write the process' actual exit code. | 60 // write the process' actual exit code. |
| 59 return WriteProcessExitCode(STILL_ACTIVE); | 61 return WriteProcessExitCode(STILL_ACTIVE); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void ExitCodeWatcher::WaitForExit() { | 64 void ExitCodeWatcher::WaitForExit() { |
| 63 if (!process_.WaitForExit(&exit_code_)) { | 65 if (!process_.WaitForExit(&exit_code_)) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 78 ULONG result = key.WriteValue(value_name.c_str(), exit_code); | 80 ULONG result = key.WriteValue(value_name.c_str(), exit_code); |
| 79 if (result != ERROR_SUCCESS) { | 81 if (result != ERROR_SUCCESS) { |
| 80 LOG(ERROR) << "Unable to write to registry, error " << result; | 82 LOG(ERROR) << "Unable to write to registry, error " << result; |
| 81 return false; | 83 return false; |
| 82 } | 84 } |
| 83 | 85 |
| 84 return true; | 86 return true; |
| 85 } | 87 } |
| 86 | 88 |
| 87 } // namespace browser_watcher | 89 } // namespace browser_watcher |
| OLD | NEW |