Chromium Code Reviews| Index: components/browser_watcher/stability_paths.cc |
| diff --git a/components/browser_watcher/stability_paths.cc b/components/browser_watcher/stability_paths.cc |
| index 66805fa67d12381e81386de3e803adc59aa35f28..b7a12393089ab30300c09e2f678d5129751676c5 100644 |
| --- a/components/browser_watcher/stability_paths.cc |
| +++ b/components/browser_watcher/stability_paths.cc |
| @@ -8,10 +8,15 @@ |
| #include <windows.h> |
| #endif // defined(OS_WIN) |
| +#include <memory> |
| #include <string> |
| +#include <utility> |
| +#include "base/debug/activity_tracker.h" |
| #include "base/feature_list.h" |
| #include "base/files/file.h" |
| +#include "base/files/memory_mapped_file.h" |
| +#include "base/metrics/histogram_macros.h" |
| #include "base/metrics/persistent_memory_allocator.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/time/time.h" |
| @@ -22,6 +27,11 @@ |
| #include "third_party/crashpad/crashpad/util/win/time.h" |
| namespace browser_watcher { |
| + |
| +using base::FilePersistentMemoryAllocator; |
| +using base::MemoryMappedFile; |
| +using base::PersistentMemoryAllocator; |
| + |
| namespace { |
| bool GetCreationTime(const base::Process& process, FILETIME* creation_time) { |
| @@ -30,6 +40,22 @@ bool GetCreationTime(const base::Process& process, FILETIME* creation_time) { |
| &ignore) != 0; |
| } |
| +bool SetPmaFileDeleted(const base::FilePath& file_path) { |
| + // Map the file read-write so it can guarantee consistency between |
| + // the analyzer and any trackers that may still be active. |
| + std::unique_ptr<MemoryMappedFile> mmfile(new MemoryMappedFile()); |
| + mmfile->Initialize(file_path, MemoryMappedFile::READ_WRITE); |
| + if (!mmfile->IsValid()) |
| + return false; |
| + if (!FilePersistentMemoryAllocator::IsFileAcceptable(*mmfile, true)) |
| + return false; |
| + std::unique_ptr<FilePersistentMemoryAllocator> allocator( |
| + new FilePersistentMemoryAllocator(std::move(mmfile), 0, 0, |
| + base::StringPiece(), true)); |
| + allocator->SetMemoryState(PersistentMemoryAllocator::MEMORY_DELETED); |
| + return true; |
| +} |
| + |
| } // namespace |
| base::FilePath GetStabilityDir(const base::FilePath& user_data_dir) { |
| @@ -72,25 +98,33 @@ base::FilePath::StringType GetStabilityFilePattern() { |
| base::PersistentMemoryAllocator::kFileExtension; |
| } |
| -void MarkStabilityFileForDeletion(const base::FilePath& user_data_dir) { |
| - if (!base::FeatureList::IsEnabled( |
| - browser_watcher::kStabilityDebuggingFeature)) { |
| - return; |
| - } |
| +void MarkOwnStabilityFileDeleted(const base::FilePath& user_data_dir) { |
| + base::debug::GlobalActivityTracker* global_tracker = |
| + base::debug::GlobalActivityTracker::Get(); |
| + if (!global_tracker) |
| + return; // No stability instrumentation. |
| + |
| + global_tracker->MarkDeleted(); |
| + // Open (with delete) and then immediately close the file by going out of |
| + // scope. This should cause the stability debugging file to be deleted prior |
| + // to the next execution. |
| base::FilePath stability_file; |
| if (!GetStabilityFileForProcess(base::Process::Current(), user_data_dir, |
| &stability_file)) { |
| - // TODO(manzagop): add a metric for this. |
| - return; |
| + return; // TODO(manzagop): add a metric for this. |
| } |
| + base::File deleter(stability_file, base::File::FLAG_OPEN | |
| + base::File::FLAG_READ | |
| + base::File::FLAG_DELETE_ON_CLOSE); |
| +} |
| - // Open (with delete) and then immediately close the file by going out of |
| - // scope. This should cause the stability debugging file to be deleted prior |
| - // to the next execution. |
| - base::File file(stability_file, base::File::FLAG_OPEN | |
| - base::File::FLAG_READ | |
| - base::File::FLAG_DELETE_ON_CLOSE); |
| +void MarkStabilityFileDeleted(const base::FilePath& file_path) { |
| + bool success = SetPmaFileDeleted(file_path); |
| + UMA_HISTOGRAM_BOOLEAN("ActivityTracker.Record.SetPmaDeletedSuccess", success); |
|
Sigurður Ásgeirsson
2017/05/30 16:51:18
Yeah, this looks like another event count - I thin
|
| + |
| + base::File deleter(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ | |
| + base::File::FLAG_DELETE_ON_CLOSE); |
| } |
| } // namespace browser_watcher |