Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/basictypes.h" | |
| 6 #include "base/logging.h" | |
| 7 #include "base/process/process_handle.h" | |
| 8 | |
| 9 namespace base { | |
| 10 | |
| 11 namespace { | |
| 12 uint32 g_unique_id = kInvalidUniqueId; | |
| 13 | |
| 14 #if DCHECK_IS_ON() | |
| 15 // The process which set g_unique_id. | |
|
Lei Zhang
2015/07/28 21:54:23
Please refer to variables are |foo|. Ditto below.
rickyz (no longer on Chrome)
2015/07/28 22:39:37
Done.
| |
| 16 uint32 g_procid; | |
| 17 #endif | |
| 18 } // namespace | |
| 19 | |
| 20 uint32 GetUniqueIdForProcess() { | |
| 21 if (g_unique_id == kInvalidUniqueId) { | |
| 22 return static_cast<uint32>(GetCurrentProcId()); | |
| 23 } | |
| 24 | |
| 25 // Make sure we are the same process that set g_procid. This check may have | |
| 26 // false negatives (if a process ID was reused) but should have no false | |
| 27 // positives. | |
| 28 DCHECK_EQ(static_cast<uint32>(GetCurrentProcId()), g_procid); | |
| 29 return g_unique_id; | |
| 30 } | |
| 31 | |
| 32 void SetUniqueIdForProcess(uint32 unique_id) { | |
| 33 g_unique_id = unique_id; | |
| 34 #if DCHECK_IS_ON() | |
| 35 g_procid = static_cast<uint32>(GetCurrentProcId()); | |
| 36 #endif | |
| 37 } | |
| 38 | |
| 39 } // namespace base | |
| OLD | NEW |