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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // done consistently. | 25 // done consistently. |
26 COMPILE_ASSERT(sizeof(DWORD) == sizeof(int), | 26 COMPILE_ASSERT(sizeof(DWORD) == sizeof(int), |
27 process_ids_have_outgrown_an_int); | 27 process_ids_have_outgrown_an_int); |
28 } | 28 } |
29 | 29 |
30 // This function does soft matching on the PID recorded in the key only. | 30 // 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 | 31 // 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. | 32 // 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 | 33 // This doesn't matter for the purpose, as eventually the data will be |
34 // scavenged and reported. | 34 // scavenged and reported. |
35 bool IsDeadProcess(base::StringPiece16 key_name) { | 35 bool IsDeadProcess(base::StringPiece16 key_or_value_name) { |
36 // Truncate the input string to the first occurrence of '-', if one exists. | 36 // Truncate the input string to the first occurrence of '-', if one exists. |
37 size_t num_end = key_name.find(L'-'); | 37 size_t num_end = key_or_value_name.find(L'-'); |
38 if (num_end != base::StringPiece16::npos) | 38 if (num_end != base::StringPiece16::npos) |
39 key_name = key_name.substr(0, num_end); | 39 key_or_value_name = key_or_value_name.substr(0, num_end); |
40 | 40 |
41 // Convert to the numeric PID. | 41 // Convert to the numeric PID. |
42 int pid = 0; | 42 int pid = 0; |
43 if (!base::StringToInt(key_name, &pid) || pid == 0) | 43 if (!base::StringToInt(key_or_value_name, &pid) || pid == 0) |
44 return true; | 44 return true; |
45 | 45 |
46 // This is a very inexpensive check for the common case of our own PID. | 46 // This is a very inexpensive check for the common case of our own PID. |
47 if (static_cast<base::ProcessId>(pid) == base::GetCurrentProcId()) | 47 if (static_cast<base::ProcessId>(pid) == base::GetCurrentProcId()) |
48 return false; | 48 return false; |
49 | 49 |
50 // The process is not our own - see whether a process with this PID exists. | 50 // The process is not our own - see whether a process with this PID exists. |
51 // This is more expensive than the above check, but should also be very rare, | 51 // This is more expensive than the above check, but should also be very rare, |
52 // as this only happens more than once for a given PID if a user is running | 52 // as this only happens more than once for a given PID if a user is running |
53 // multiple Chrome instances concurrently. | 53 // multiple Chrome instances concurrently. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 base::win::RegKey key(HKEY_CURRENT_USER, | 187 base::win::RegKey key(HKEY_CURRENT_USER, |
188 registry_path.c_str(), | 188 registry_path.c_str(), |
189 KEY_QUERY_VALUE); | 189 KEY_QUERY_VALUE); |
190 if (!key.Valid()) { | 190 if (!key.Valid()) { |
191 LOG(ERROR) << "Failed to open " << registry_path << " for writing."; | 191 LOG(ERROR) << "Failed to open " << registry_path << " for writing."; |
192 return; | 192 return; |
193 } | 193 } |
194 | 194 |
195 std::vector<base::string16> to_delete; | 195 std::vector<base::string16> to_delete; |
196 for (; it.Valid(); ++it) { | 196 for (; it.Valid(); ++it) { |
197 RecordSingleExitFunnel(&key, it.Name()); | 197 // Defer reporting on still-live processes. |
198 to_delete.push_back(it.Name()); | 198 if (IsDeadProcess(it.Name())) { |
| 199 RecordSingleExitFunnel(&key, it.Name()); |
| 200 to_delete.push_back(it.Name()); |
| 201 } |
199 } | 202 } |
200 | 203 |
201 for (size_t i = 0; i < to_delete.size(); ++i) { | 204 for (size_t i = 0; i < to_delete.size(); ++i) { |
202 LONG res = key.DeleteEmptyKey(to_delete[i].c_str()); | 205 LONG res = key.DeleteEmptyKey(to_delete[i].c_str()); |
203 if (res != ERROR_SUCCESS) | 206 if (res != ERROR_SUCCESS) |
204 LOG(ERROR) << "Failed to delete key " << to_delete[i]; | 207 LOG(ERROR) << "Failed to delete key " << to_delete[i]; |
205 } | 208 } |
206 } | 209 } |
207 | 210 |
208 } // namespace | 211 } // namespace |
(...skipping 16 matching lines...) Expand all Loading... |
225 // user account, there's a small race that will double-report the exit codes | 228 // user account, there's a small race that will double-report the exit codes |
226 // from both/multiple instances. This ought to be vanishingly rare and will | 229 // from both/multiple instances. This ought to be vanishingly rare and will |
227 // only manifest as low-level "random" noise. To work around this it would be | 230 // only manifest as low-level "random" noise. To work around this it would be |
228 // necessary to implement some form of global locking, which is not worth it | 231 // necessary to implement some form of global locking, which is not worth it |
229 // here. | 232 // here. |
230 RecordExitCodes(registry_path_); | 233 RecordExitCodes(registry_path_); |
231 RecordExitFunnels(registry_path_); | 234 RecordExitFunnels(registry_path_); |
232 } | 235 } |
233 | 236 |
234 } // namespace browser_watcher | 237 } // namespace browser_watcher |
OLD | NEW |