Chromium Code Reviews| 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..3ec91175614cb62fab30f88038dde7059f141615 |
| --- /dev/null |
| +++ b/base/process/process_handle.cc |
| @@ -0,0 +1,39 @@ |
| +// 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; |
| + |
| +#if DCHECK_IS_ON() |
| +// 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.
|
| +uint32 g_procid; |
| +#endif |
| +} // namespace |
| + |
| +uint32 GetUniqueIdForProcess() { |
| + if (g_unique_id == kInvalidUniqueId) { |
| + return static_cast<uint32>(GetCurrentProcId()); |
| + } |
| + |
| + // 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); |
| + return g_unique_id; |
| +} |
| + |
| +void SetUniqueIdForProcess(uint32 unique_id) { |
| + g_unique_id = unique_id; |
| +#if DCHECK_IS_ON() |
| + g_procid = static_cast<uint32>(GetCurrentProcId()); |
| +#endif |
| +} |
| + |
| +} // namespace base |