Index: components/browser_watcher/stability_paths.cc |
diff --git a/components/browser_watcher/stability_paths.cc b/components/browser_watcher/stability_paths.cc |
index d8764166752db72ebbdf472b75f8e16f2be03889..66805fa67d12381e81386de3e803adc59aa35f28 100644 |
--- a/components/browser_watcher/stability_paths.cc |
+++ b/components/browser_watcher/stability_paths.cc |
@@ -4,6 +4,10 @@ |
#include "components/browser_watcher/stability_paths.h" |
+#if defined(OS_WIN) |
+#include <windows.h> |
+#endif // defined(OS_WIN) |
+ |
#include <string> |
#include "base/feature_list.h" |
@@ -15,22 +19,15 @@ |
#if defined(OS_WIN) |
+#include "third_party/crashpad/crashpad/util/win/time.h" |
+ |
namespace browser_watcher { |
namespace { |
-bool GetCreationTime(const base::Process& process, base::Time* time) { |
- DCHECK(time); |
- |
- FILETIME creation_time = {}; |
- FILETIME ignore1 = {}; |
- FILETIME ignore2 = {}; |
- FILETIME ignore3 = {}; |
- if (!::GetProcessTimes(process.Handle(), &creation_time, &ignore1, &ignore2, |
- &ignore3)) { |
- return false; |
- } |
- *time = base::Time::FromFileTime(creation_time); |
- return true; |
+bool GetCreationTime(const base::Process& process, FILETIME* creation_time) { |
+ FILETIME ignore; |
+ return ::GetProcessTimes(process.Handle(), creation_time, &ignore, &ignore, |
+ &ignore) != 0; |
} |
} // namespace |
@@ -39,22 +36,34 @@ base::FilePath GetStabilityDir(const base::FilePath& user_data_dir) { |
return user_data_dir.AppendASCII("Stability"); |
} |
+base::FilePath GetStabilityFileForProcess(base::ProcessId pid, |
+ timeval creation_time, |
+ const base::FilePath& user_data_dir) { |
+ base::FilePath stability_dir = GetStabilityDir(user_data_dir); |
+ |
+ constexpr uint64_t kMicrosecondsPerSecond = static_cast<uint64_t>(1E6); |
+ int64_t creation_time_us = |
+ creation_time.tv_sec * kMicrosecondsPerSecond + creation_time.tv_usec; |
+ |
+ std::string file_name = base::StringPrintf("%u-%lld", pid, creation_time_us); |
+ return stability_dir.AppendASCII(file_name).AddExtension( |
+ base::PersistentMemoryAllocator::kFileExtension); |
+} |
+ |
bool GetStabilityFileForProcess(const base::Process& process, |
const base::FilePath& user_data_dir, |
base::FilePath* file_path) { |
DCHECK(file_path); |
- base::FilePath stability_dir = GetStabilityDir(user_data_dir); |
- // Build the name using the pid and creation time. On windows, this is unique |
- // even after the process exits. |
- base::Time creation_time; |
+ FILETIME creation_time; |
if (!GetCreationTime(process, &creation_time)) |
return false; |
- std::string file_name = |
- base::StringPrintf("%u-%llu", process.Pid(), creation_time.ToJavaTime()); |
- *file_path = stability_dir.AppendASCII(file_name).AddExtension( |
- base::PersistentMemoryAllocator::kFileExtension); |
+ // We rely on Crashpad's conversion to ensure the resulting filename is the |
+ // same as on crash, when the creation time is obtained via Crashpad. |
+ *file_path = GetStabilityFileForProcess( |
+ process.Pid(), crashpad::FiletimeToTimevalEpoch(creation_time), |
+ user_data_dir); |
return true; |
} |