| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/stability_debugging_win.h" | 5 #include "components/browser_watcher/stability_debugging_win.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/feature_list.h" |
| 10 #include "base/files/file.h" |
| 9 #include "base/metrics/persistent_memory_allocator.h" | 11 #include "base/metrics/persistent_memory_allocator.h" |
| 10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/process/process.h" |
| 11 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 12 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "components/browser_watcher/features.h" |
| 13 | 17 |
| 14 namespace browser_watcher { | 18 namespace browser_watcher { |
| 15 | 19 |
| 16 namespace { | 20 namespace { |
| 17 | 21 |
| 18 bool GetCreationTime(const base::Process& process, base::Time* time) { | 22 bool GetCreationTime(const base::Process& process, base::Time* time) { |
| 19 DCHECK(time); | 23 DCHECK(time); |
| 20 | 24 |
| 21 FILETIME creation_time = {}; | 25 FILETIME creation_time = {}; |
| 22 FILETIME ignore1 = {}; | 26 FILETIME ignore1 = {}; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 53 *file_path = stability_dir.AppendASCII(file_name).AddExtension( | 57 *file_path = stability_dir.AppendASCII(file_name).AddExtension( |
| 54 base::PersistentMemoryAllocator::kFileExtension); | 58 base::PersistentMemoryAllocator::kFileExtension); |
| 55 return true; | 59 return true; |
| 56 } | 60 } |
| 57 | 61 |
| 58 base::FilePath::StringType GetStabilityFilePattern() { | 62 base::FilePath::StringType GetStabilityFilePattern() { |
| 59 return base::FilePath::StringType(FILE_PATH_LITERAL("*-*")) + | 63 return base::FilePath::StringType(FILE_PATH_LITERAL("*-*")) + |
| 60 base::PersistentMemoryAllocator::kFileExtension; | 64 base::PersistentMemoryAllocator::kFileExtension; |
| 61 } | 65 } |
| 62 | 66 |
| 67 void MarkStabilityFileForDeletion(const base::FilePath& user_data_dir) { |
| 68 if (!base::FeatureList::IsEnabled( |
| 69 browser_watcher::kStabilityDebuggingFeature)) { |
| 70 return; |
| 71 } |
| 72 |
| 73 base::FilePath stability_file; |
| 74 if (!GetStabilityFileForProcess(base::Process::Current(), user_data_dir, |
| 75 &stability_file)) { |
| 76 // TODO(manzagop): add a metric for this. |
| 77 return; |
| 78 } |
| 79 |
| 80 // Open (with delete) and then immediately close the file by going out of |
| 81 // scope. This should cause the stability debugging file to be deleted prior |
| 82 // to the next execution. |
| 83 base::File file(stability_file, base::File::FLAG_OPEN | |
| 84 base::File::FLAG_READ | |
| 85 base::File::FLAG_DELETE_ON_CLOSE); |
| 86 } |
| 87 |
| 63 } // namespace browser_watcher | 88 } // namespace browser_watcher |
| OLD | NEW |