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..59751b1ae5ca6585b76046d7f27bbc9bb987e50d |
| --- /dev/null |
| +++ b/base/process/process_handle.cc |
| @@ -0,0 +1,40 @@ |
| +// 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 <stdint.h> |
| + |
| +#include "base/logging.h" |
| +#include "base/process/process_handle.h" |
| + |
| +namespace base { |
| + |
| +namespace { |
| +uint32_t g_unique_id = kInvalidUniqueId; |
| + |
| +#if DCHECK_IS_ON() |
| +// The process which set |g_unique_id|. |
| +uint32_t g_procid; |
| +#endif |
| +} // namespace |
| + |
| +uint32_t GetUniqueIdForProcess() { |
| + if (g_unique_id == kInvalidUniqueId) { |
| + 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
|
| + } |
| + |
| + // 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_t>(GetCurrentProcId()), g_procid); |
| + return g_unique_id; |
| +} |
| + |
| +void SetUniqueIdForProcess(uint32_t unique_id) { |
| + 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.
|
| +#if DCHECK_IS_ON() |
| + g_procid = static_cast<uint32_t>(GetCurrentProcId()); |
| +#endif |
| +} |
| + |
| +} // namespace base |