Index: third_party/WebKit/Source/platform/instrumentation/inspector/PlatformIdentifiersFactory.cpp |
diff --git a/third_party/WebKit/Source/platform/instrumentation/inspector/PlatformIdentifiersFactory.cpp b/third_party/WebKit/Source/platform/instrumentation/inspector/PlatformIdentifiersFactory.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4d5daf95cc5e59b3ea90fc2631f88b4d8b7a8073 |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/instrumentation/inspector/PlatformIdentifiersFactory.cpp |
@@ -0,0 +1,57 @@ |
+// Copyright 2017 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 "platform/instrumentation/inspector/PlatformIdentifiersFactory.h" |
+ |
+#include "public/platform/Platform.h" |
+#include "wtf/Assertions.h" |
+#include "wtf/text/StringBuilder.h" |
+ |
+namespace blink { |
+ |
+namespace { |
+ |
+volatile int s_lastUsedIdentifier = 0; |
+ |
+} // namespace |
+ |
+// static |
+String PlatformIdentifiersFactory::createIdentifier() { |
+ int identifier = atomicIncrement(&s_lastUsedIdentifier); |
+ return addProcessIdPrefixTo(identifier); |
+} |
+ |
+// static |
+String PlatformIdentifiersFactory::requestId(unsigned long identifier) { |
+ return identifier ? addProcessIdPrefixTo(identifier) : String(); |
+} |
+ |
+// static |
+String PlatformIdentifiersFactory::addProcessIdPrefixTo(int id) { |
+ DEFINE_THREAD_SAFE_STATIC_LOCAL( |
+ uint32_t, s_processId, |
+ new uint32_t(Platform::current()->getUniqueIdForProcess())); |
+ |
+ StringBuilder builder; |
+ |
+ builder.appendNumber(s_processId); |
+ builder.append('.'); |
+ builder.appendNumber(id); |
+ |
+ return builder.toString(); |
+} |
+ |
+// static |
+int PlatformIdentifiersFactory::removeProcessIdPrefixFrom(const String& id, |
+ bool* ok) { |
+ size_t dotIndex = id.find('.'); |
+ |
+ if (dotIndex == kNotFound) { |
+ *ok = false; |
+ return 0; |
+ } |
+ return id.substring(dotIndex + 1).toInt(ok); |
+} |
+ |
+} // namespace blink |