chromeos: bluetooth: add BluetoothInputClient
[chromium-blink-merge.git] / net / spdy / spdy_credential_state.cc
blob038ae383c034afeeb53b978d373df9536b69852e
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.
5 #include "net/spdy/spdy_credential_state.h"
7 #include "base/logging.h"
9 namespace net {
11 const size_t SpdyCredentialState::kDefaultNumSlots = 8;
12 const size_t SpdyCredentialState::kNoEntry = -1;
14 SpdyCredentialState::SpdyCredentialState(size_t num_slots)
15 : slots_(num_slots),
16 last_added_(-1) {}
18 SpdyCredentialState::~SpdyCredentialState() {}
20 bool SpdyCredentialState::HasCredential(const HostPortPair& origin) const {
21 return FindPosition(origin) != kNoEntry;
24 size_t SpdyCredentialState::SetHasCredential(const HostPortPair& origin) {
25 size_t i = FindPosition(origin);
26 if (i != kNoEntry)
27 return i;
28 // Add the new entry at the next index following the index of the last
29 // entry added, or at index 0 if the last added index is the last index.
30 if (last_added_ + 1 == slots_.size()) {
31 last_added_ = 0;
32 } else {
33 last_added_++;
35 slots_[last_added_] = origin;
36 return last_added_;
39 size_t SpdyCredentialState::FindPosition(const HostPortPair& origin) const {
40 for (size_t i = 0; i < slots_.size(); i++) {
41 if (slots_[i].Equals(origin))
42 return i;
44 return kNoEntry;
47 void SpdyCredentialState::Resize(size_t size) {
48 slots_.resize(size);
49 if (last_added_ >= slots_.size())
50 last_added_ = slots_.size() - 1;
53 } // namespace net