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

Side by Side Diff: base/process/process_handle.cc

Issue 1186873006: Add Get/SetUniqueIdForProcess. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use uint32_t, prettify comments Created 5 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdint.h>
6
7 #include "base/logging.h"
8 #include "base/process/process_handle.h"
9
10 namespace base {
11
12 namespace {
13 uint32_t g_unique_id = kInvalidUniqueId;
14
15 #if DCHECK_IS_ON()
16 // The process which set |g_unique_id|.
17 uint32_t g_procid;
18 #endif
19 } // namespace
20
21 uint32_t GetUniqueIdForProcess() {
22 if (g_unique_id == kInvalidUniqueId) {
23 return static_cast<uint32_t>(GetCurrentProcId());
danakj 2015/08/05 19:52:26 Is this branch basically for the browser process/o
rickyz (no longer on Chrome) 2015/08/13 23:16:55 Yeah, I think it ends up being just the browser pr
danakj 2015/09/15 18:36:32 This still really bothers me :/ It feels very uncl
24 }
25
26 // Make sure we are the same process that set |g_procid|. This check may have
27 // false negatives (if a process ID was reused) but should have no false
28 // positives.
29 DCHECK_EQ(static_cast<uint32_t>(GetCurrentProcId()), g_procid);
30 return g_unique_id;
31 }
32
33 void SetUniqueIdForProcess(uint32_t unique_id) {
34 g_unique_id = unique_id;
danakj 2015/08/05 19:52:26 can you DCHECK_GT(unique_id, 0) ?
rickyz (no longer on Chrome) 2015/08/13 23:16:55 Done.
35 #if DCHECK_IS_ON()
36 g_procid = static_cast<uint32_t>(GetCurrentProcId());
37 #endif
38 }
39
40 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698