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"
11 const size_t SpdyCredentialState::kDefaultNumSlots
= 8;
12 const size_t SpdyCredentialState::kNoEntry
= -1;
14 SpdyCredentialState::SpdyCredentialState(size_t num_slots
)
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
);
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()) {
35 slots_
[last_added_
] = origin
;
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
))
47 void SpdyCredentialState::Resize(size_t size
) {
49 if (last_added_
>= slots_
.size())
50 last_added_
= slots_
.size() - 1;