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

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: Updated ToT again 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..435871249015de591ee28d13021944b0029f1d4b
--- /dev/null
+++ b/content/browser/renderer_host/routing_id_issuer.cc
@@ -0,0 +1,63 @@
+// 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 kManglerBit = 3;
+const int kIDBit = 31 - kManglerBit;
+const int kManglerWrap = 1 << kManglerBit;
+const int kManglerMask = kManglerWrap - 1;
+const int kIDWrap = 1 << kIDBit;
+const int kIDMask = kIDWrap - 1;
+
+int g_manglerSequence = 0;
ncarter (slow) 2014/10/13 22:51:33 Agree with nasko; this should probably be a Static
Hajime Morrita 2014/10/13 23:39:17 Done.
+int g_disablingIDManglingCount = 0;
+
+int GetNextMangler() {
+ ++g_manglerSequence;
+ g_manglerSequence = g_manglerSequence % kManglerWrap;
ncarter (slow) 2014/10/13 22:51:33 You might want to consider skipping mangler ID's o
Hajime Morrita 2014/10/13 23:39:17 Makes sense. Changed to always return non-zero man
+ return g_manglerSequence;
+}
+
+} // 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_ << kIDBit) | ((next_.GetNext() + 1) & kIDMask);
ncarter (slow) 2014/10/13 22:51:33 I had an idea for a sort of different algorithm he
Hajime Morrita 2014/10/13 23:39:17 Thanks for the suggestion! I'd rather avoid using
+}
+
+bool RoutingIDIssuer::IsProbablyValid(int issued_id) const {
+ return mangler_ == ((issued_id >> kIDBit) & kManglerMask);
ncarter (slow) 2014/10/13 22:51:33 can't issued_id be a negative value? If so then th
Hajime Morrita 2014/10/13 23:39:17 Oops. Fixing.
+}
+
+void RoutingIDIssuer::StartDisablingIDMangling() {
+ g_disablingIDManglingCount++;
+}
+
+void RoutingIDIssuer::StopDisablingIDMangling() {
+ 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