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/watcher_metrics_provider_win.h" | 5 #include "components/browser_watcher/watcher_metrics_provider_win.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
11 #include "base/process/process.h" | 11 #include "base/process/process.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/win/registry.h" | 15 #include "base/win/registry.h" |
16 | 16 |
17 namespace browser_watcher { | 17 namespace browser_watcher { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 void CompileAsserts() { | 21 // Process ID APIs on Windows talk in DWORDs, whereas for string formatting |
22 // Process ID APIs on Windows talk in DWORDs, whereas for string formatting | 22 // and parsing, this code uses int. In practice there are no process IDs with |
23 // and parsing, this code uses int. In practice there are no process IDs with | 23 // the high bit set on Windows, so there's no danger of overflow if this is |
24 // the high bit set on Windows, so there's no danger of overflow if this is | 24 // done consistently. |
25 // done consistently. | 25 static_assert(sizeof(DWORD) == sizeof(int), |
26 static_assert(sizeof(DWORD) == sizeof(int), | 26 "process ids are expected to be no larger than int"); |
27 "process ids are expected to be no larger than int"); | |
28 } | |
29 | 27 |
30 // This function does soft matching on the PID recorded in the key only. | 28 // This function does soft matching on the PID recorded in the key only. |
31 // Due to PID reuse, the possibility exists that the process that's now live | 29 // Due to PID reuse, the possibility exists that the process that's now live |
32 // with the given PID is not the same process the data was recorded for. | 30 // with the given PID is not the same process the data was recorded for. |
33 // This doesn't matter for the purpose, as eventually the data will be | 31 // This doesn't matter for the purpose, as eventually the data will be |
34 // scavenged and reported. | 32 // scavenged and reported. |
35 bool IsDeadProcess(base::StringPiece16 key_or_value_name) { | 33 bool IsDeadProcess(base::StringPiece16 key_or_value_name) { |
36 // Truncate the input string to the first occurrence of '-', if one exists. | 34 // Truncate the input string to the first occurrence of '-', if one exists. |
37 size_t num_end = key_or_value_name.find(L'-'); | 35 size_t num_end = key_or_value_name.find(L'-'); |
38 if (num_end != base::StringPiece16::npos) | 36 if (num_end != base::StringPiece16::npos) |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // user account, there's a small race that will double-report the exit codes | 230 // user account, there's a small race that will double-report the exit codes |
233 // from both/multiple instances. This ought to be vanishingly rare and will | 231 // from both/multiple instances. This ought to be vanishingly rare and will |
234 // only manifest as low-level "random" noise. To work around this it would be | 232 // only manifest as low-level "random" noise. To work around this it would be |
235 // necessary to implement some form of global locking, which is not worth it | 233 // necessary to implement some form of global locking, which is not worth it |
236 // here. | 234 // here. |
237 RecordExitCodes(registry_path_); | 235 RecordExitCodes(registry_path_); |
238 MaybeRecordExitFunnels(registry_path_, report_exit_funnels_); | 236 MaybeRecordExitFunnels(registry_path_, report_exit_funnels_); |
239 } | 237 } |
240 | 238 |
241 } // namespace browser_watcher | 239 } // namespace browser_watcher |
OLD | NEW |