Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: components/browser_watcher/watcher_metrics_provider_win.cc

Issue 868543002: Move OpenProcessHandle to Process::Open. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/perf/perf_test.cc ('k') | sandbox/linux/services/unix_domain_socket_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_handle.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 void CompileAsserts() {
(...skipping 22 matching lines...) Expand all
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.
54 base::ProcessHandle process = base::kNullProcessHandle; 54 base::Process process =
55 if (base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { 55 base::Process::Open(static_cast<base::ProcessId>(pid));
56 base::CloseProcessHandle(process); 56 if (process.IsValid()) {
57
58 // The fact that it was possible to open the process says it's live. 57 // The fact that it was possible to open the process says it's live.
59 return false; 58 return false;
60 } 59 }
61 60
62 return true; 61 return true;
63 } 62 }
64 63
65 void RecordExitCodes(const base::string16& registry_path) { 64 void RecordExitCodes(const base::string16& registry_path) {
66 base::win::RegKey regkey(HKEY_CURRENT_USER, 65 base::win::RegKey regkey(HKEY_CURRENT_USER,
67 registry_path.c_str(), 66 registry_path.c_str(),
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // user account, there's a small race that will double-report the exit codes 232 // user account, there's a small race that will double-report the exit codes
234 // from both/multiple instances. This ought to be vanishingly rare and will 233 // from both/multiple instances. This ought to be vanishingly rare and will
235 // only manifest as low-level "random" noise. To work around this it would be 234 // only manifest as low-level "random" noise. To work around this it would be
236 // necessary to implement some form of global locking, which is not worth it 235 // necessary to implement some form of global locking, which is not worth it
237 // here. 236 // here.
238 RecordExitCodes(registry_path_); 237 RecordExitCodes(registry_path_);
239 MaybeRecordExitFunnels(registry_path_, report_exit_funnels_); 238 MaybeRecordExitFunnels(registry_path_, report_exit_funnels_);
240 } 239 }
241 240
242 } // namespace browser_watcher 241 } // namespace browser_watcher
OLDNEW
« no previous file with comments | « chrome/test/perf/perf_test.cc ('k') | sandbox/linux/services/unix_domain_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698