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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/routing_id_issuer.h"
6
7 namespace content {
8
9 namespace {
10
11 const int kManglerBit = 3;
12 const int kIDBit = 31 - kManglerBit;
13 const int kManglerWrap = 1 << kManglerBit;
14 const int kManglerMask = kManglerWrap - 1;
15 const int kIDWrap = 1 << kIDBit;
16 const int kIDMask = kIDWrap - 1;
17
18 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.
19 int g_disablingIDManglingCount = 0;
20
21 int GetNextMangler() {
22 ++g_manglerSequence;
23 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
24 return g_manglerSequence;
25 }
26
27 } // namespace
28
29 scoped_ptr<RoutingIDIssuer> RoutingIDIssuer::Create() {
30 if (0 < g_disablingIDManglingCount)
31 return make_scoped_ptr(new RoutingIDIssuer(0));
32
33 DCHECK(0 == g_disablingIDManglingCount);
34 return make_scoped_ptr(new RoutingIDIssuer(GetNextMangler()));
35 }
36
37 scoped_ptr<RoutingIDIssuer> RoutingIDIssuer::CreateWithMangler(int mangler) {
38 return make_scoped_ptr(new RoutingIDIssuer(mangler));
39 }
40
41 RoutingIDIssuer::RoutingIDIssuer(int mangler) : mangler_(mangler) {
42 DCHECK(0 <= mangler_ && mangler_ < kManglerWrap) << mangler_
43 << ">=" << kManglerWrap;
44 }
45
46 int RoutingIDIssuer::IssueNext() {
47 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
48 }
49
50 bool RoutingIDIssuer::IsProbablyValid(int issued_id) const {
51 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.
52 }
53
54 void RoutingIDIssuer::StartDisablingIDMangling() {
55 g_disablingIDManglingCount++;
56 }
57
58 void RoutingIDIssuer::StopDisablingIDMangling() {
59 g_disablingIDManglingCount--;
60 DCHECK(0 <= g_disablingIDManglingCount);
61 }
62
63 } // namespace content
OLDNEW
« 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