Chromium Code Reviews| 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; |
|
nasko
2014/10/13 21:04:01
nit: I'll name the *Bit variables as *Bits, as it
Hajime Morrita
2014/10/13 22:23:54
Done.
|
| +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; |
|
nasko
2014/10/13 21:04:01
Shouldn't this be an atomic type?
Hajime Morrita
2014/10/13 22:23:54
I thought this is OK as it is called only from UI
|
| +int g_disablingIDManglingCount = 0; |
| + |
| +int GetNextMangler() { |
| + ++g_manglerSequence; |
| + g_manglerSequence = g_manglerSequence % kManglerWrap; |
| + 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); |
| +} |
| + |
| +bool RoutingIDIssuer::IsProbablyValid(int issued_id) const { |
| + return mangler_ == ((issued_id >> kIDBit) & kManglerMask); |
| +} |
| + |
| +void RoutingIDIssuer::StartDisablingIDMangling() { |
| + g_disablingIDManglingCount++; |
| +} |
| + |
| +void RoutingIDIssuer::StopDisablingIDMangling() { |
| + g_disablingIDManglingCount--; |
| + DCHECK(0 <= g_disablingIDManglingCount); |
| +} |
| + |
| +} // namespace content |