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

Unified Diff: content/browser/renderer_host/routing_id_issuer.cc

Issue 643733002: Add RoutingIDIssuer to ensure the correctness of ID to be routed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Nasko's points. Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/routing_id_issuer.cc
diff --git a/content/browser/renderer_host/routing_id_issuer.cc b/content/browser/renderer_host/routing_id_issuer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..538fa6cf46871c5fe9de36878701efc01c75f1ac
--- /dev/null
+++ b/content/browser/renderer_host/routing_id_issuer.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 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 "content/browser/renderer_host/routing_id_issuer.h"
+
+namespace content {
+
+namespace {
+
+const int kManglerBits = 3;
+const int kIDBits = 31 - kManglerBits;
+const int kManglerWrap = 1 << kManglerBits;
+const int kManglerMask = kManglerWrap - 1;
+const int kIDWrap = 1 << kIDBits;
+const int kIDMask = kIDWrap - 1;
+
+base::StaticAtomicSequenceNumber g_manglerSequence;
nasko 2014/10/13 22:40:02 nit: let's make this one static, as it isn't used
Hajime Morrita 2014/10/13 23:39:17 Done.
+int g_disablingIDManglingCount = 0;
+
+int GetNextMangler() {
+ return g_manglerSequence.GetNext() % kManglerWrap;
+}
+
+} // namespace
+
+scoped_ptr<RoutingIDIssuer> RoutingIDIssuer::Create() {
+ if (0 < g_disablingIDManglingCount)
+ return make_scoped_ptr(new RoutingIDIssuer(0));
+
+ DCHECK(0 == g_disablingIDManglingCount);
+ return make_scoped_ptr(new RoutingIDIssuer(GetNextMangler()));
+}
+
+scoped_ptr<RoutingIDIssuer> RoutingIDIssuer::CreateWithMangler(int mangler) {
+ return make_scoped_ptr(new RoutingIDIssuer(mangler));
+}
+
+RoutingIDIssuer::RoutingIDIssuer(int mangler) : mangler_(mangler) {
+ DCHECK(0 <= mangler_ && mangler_ < kManglerWrap) << mangler_
+ << ">=" << kManglerWrap;
+}
+
+int RoutingIDIssuer::IssueNext() {
+ return (mangler_ << kIDBits) | ((next_.GetNext() + 1) & kIDMask);
+}
+
+bool RoutingIDIssuer::IsProbablyValid(int issued_id) const {
+ return mangler_ == ((issued_id >> kIDBits) & kManglerMask);
+}
+
+void RoutingIDIssuer::DisableIDMangling() {
+ g_disablingIDManglingCount++;
+}
+
+void RoutingIDIssuer::EnableIDMangling() {
+ g_disablingIDManglingCount--;
+ DCHECK(0 <= g_disablingIDManglingCount);
+}
+
+} // namespace content
« no previous file with comments | « content/browser/renderer_host/routing_id_issuer.h ('k') | content/browser/renderer_host/routing_id_issuer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698