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

Unified Diff: base/process/process_handle.cc

Issue 1186873006: Add Get/SetUniqueIdForProcess. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: base/process/process_handle.cc
diff --git a/base/process/process_handle.cc b/base/process/process_handle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c4de20a2f0e9630ef5f589b096e0a56d7d9182ac
--- /dev/null
+++ b/base/process/process_handle.cc
@@ -0,0 +1,41 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/process/process_handle.h"
+
+namespace base {
+
+namespace {
+uint32 g_unique_id = kInvalidUniqueId;
+
+#ifndef NDEBUG
+// The process which set g_unique_id.
+uint32 g_procid;
+#endif
+} // namespace
+
+uint32 GetUniqueIdForProcess() {
+ if (g_unique_id == kInvalidUniqueId) {
+ return static_cast<uint32>(GetCurrentProcId());
danakj 2015/06/17 17:17:16 Should SetUniqueId(GetCurrentProcId()) here so we
rickyz (no longer on Chrome) 2015/06/17 19:53:41 If we call SetUniqueIdForProcess here, then GetUni
+ }
+
+#ifndef NDEBUG
willchan no longer on Chromium 2015/06/17 01:51:44 Why bother with NDEBUG if using DCHECK_EQ? Is ther
rickyz (no longer on Chrome) 2015/06/17 03:04:06 I kept the explicit ifndef because I saw that ther
danakj 2015/06/17 17:09:53 It avoids unused variable warnings when compiled o
danakj 2015/06/17 17:17:16 You can guard all your NDEBUG code with #if DCHECK
rickyz (no longer on Chrome) 2015/06/17 19:53:41 Ah, good point.
+ // Make sure we are the same process that set g_procid. This check may have
+ // false negatives (if a process ID was reused) but should have no false
+ // positives.
+ DCHECK_EQ(static_cast<uint32>(GetCurrentProcId()), g_procid);
+#endif
+ return g_unique_id;
+}
+
+void SetUniqueIdForProcess(uint32 unique_id) {
+ g_unique_id = unique_id;
willchan no longer on Chromium 2015/06/17 01:51:45 This shouldn't be set twice, right? I wonder if it
rickyz (no longer on Chrome) 2015/06/17 03:04:05 In practice, this really shouldn't be set twice -
+#ifndef NDEBUG
+ g_procid = static_cast<uint32>(GetCurrentProcId());
danakj 2015/06/17 17:17:16 How useful is this if GetCurrentProcId() is always
rickyz (no longer on Chrome) 2015/06/17 19:53:41 GetCurrentProcId is only 1 in processes which are
+#endif
+}
+
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698