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.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/debug/activity_tracker.h" | |
9 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
10 #include "base/files/file.h" | 11 #include "base/files/file.h" |
11 #include "base/metrics/persistent_memory_allocator.h" | 12 #include "base/metrics/persistent_memory_allocator.h" |
12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
13 #include "base/process/process.h" | 14 #include "base/process/process.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "components/browser_watcher/features.h" | 17 #include "components/browser_watcher/features.h" |
17 | 18 |
18 namespace browser_watcher { | 19 namespace browser_watcher { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
23 #if defined(OS_WIN) | |
22 bool GetCreationTime(const base::Process& process, base::Time* time) { | 24 bool GetCreationTime(const base::Process& process, base::Time* time) { |
bcwhite
2016/12/05 17:20:57
Are these really windows-only?
manzagop (departed)
2016/12/06 20:35:08
The current implementation is, because it relies o
| |
23 DCHECK(time); | 25 DCHECK(time); |
24 | 26 |
25 FILETIME creation_time = {}; | 27 FILETIME creation_time = {}; |
26 FILETIME ignore1 = {}; | 28 FILETIME ignore1 = {}; |
27 FILETIME ignore2 = {}; | 29 FILETIME ignore2 = {}; |
28 FILETIME ignore3 = {}; | 30 FILETIME ignore3 = {}; |
29 if (!::GetProcessTimes(process.Handle(), &creation_time, &ignore1, &ignore2, | 31 if (!::GetProcessTimes(process.Handle(), &creation_time, &ignore1, &ignore2, |
30 &ignore3)) { | 32 &ignore3)) { |
31 return false; | 33 return false; |
32 } | 34 } |
33 *time = base::Time::FromFileTime(creation_time); | 35 *time = base::Time::FromFileTime(creation_time); |
34 return true; | 36 return true; |
35 } | 37 } |
38 #endif // defined(OS_WIN) | |
36 | 39 |
37 } // namespace | 40 } // namespace |
38 | 41 |
42 #if defined(OS_WIN) | |
43 | |
39 base::FilePath GetStabilityDir(const base::FilePath& user_data_dir) { | 44 base::FilePath GetStabilityDir(const base::FilePath& user_data_dir) { |
40 return user_data_dir.AppendASCII("Stability"); | 45 return user_data_dir.AppendASCII("Stability"); |
41 } | 46 } |
42 | 47 |
43 bool GetStabilityFileForProcess(const base::Process& process, | 48 bool GetStabilityFileForProcess(const base::Process& process, |
44 const base::FilePath& user_data_dir, | 49 const base::FilePath& user_data_dir, |
45 base::FilePath* file_path) { | 50 base::FilePath* file_path) { |
46 DCHECK(file_path); | 51 DCHECK(file_path); |
47 base::FilePath stability_dir = GetStabilityDir(user_data_dir); | 52 base::FilePath stability_dir = GetStabilityDir(user_data_dir); |
48 | 53 |
(...skipping 28 matching lines...) Expand all Loading... | |
77 return; | 82 return; |
78 } | 83 } |
79 | 84 |
80 // Open (with delete) and then immediately close the file by going out of | 85 // 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 | 86 // scope. This should cause the stability debugging file to be deleted prior |
82 // to the next execution. | 87 // to the next execution. |
83 base::File file(stability_file, base::File::FLAG_OPEN | | 88 base::File file(stability_file, base::File::FLAG_OPEN | |
84 base::File::FLAG_READ | | 89 base::File::FLAG_READ | |
85 base::File::FLAG_DELETE_ON_CLOSE); | 90 base::File::FLAG_DELETE_ON_CLOSE); |
86 } | 91 } |
92 #endif // defined(OS_WIN) | |
93 | |
94 void SetStabilityDataInt(base::StringPiece name, int64_t value) { | |
95 base::debug::GlobalActivityTracker* global_tracker = | |
96 base::debug::GlobalActivityTracker::Get(); | |
97 if (!global_tracker) | |
98 return; // Activity tracking isn't enabled. | |
99 | |
100 global_tracker->user_data().SetInt(name, value); | |
101 } | |
87 | 102 |
88 } // namespace browser_watcher | 103 } // namespace browser_watcher |
OLD | NEW |