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"
8 #include "base/strings/string_util.h"
9 #include "net/ssl/server_bound_cert_service.h"
15 GURL
GetCanonicalOrigin(const GURL
& url
) {
17 ServerBoundCertService::GetDomainForHost(url
.host());
18 DCHECK(!domain
.empty());
19 if (domain
== url
.host())
20 return url
.GetOrigin();
21 return GURL(url
.scheme() + "://" + domain
+ ":" + url
.port());
26 const size_t SpdyCredentialState::kDefaultNumSlots
= 8;
27 const size_t SpdyCredentialState::kNoEntry
= 0;
29 SpdyCredentialState::SpdyCredentialState(size_t num_slots
)
33 SpdyCredentialState::~SpdyCredentialState() {}
35 bool SpdyCredentialState::HasCredential(const GURL
& origin
) const {
36 return FindCredentialSlot(origin
) != kNoEntry
;
39 size_t SpdyCredentialState::SetHasCredential(const GURL
& origin
) {
40 size_t i
= FindCredentialSlot(origin
);
43 // Add the new entry at the next index following the index of the last
44 // entry added, or at index 0 if the last added index is the last index.
45 if (last_added_
+ 1 == slots_
.size()) {
50 slots_
[last_added_
] = GetCanonicalOrigin(origin
);
51 return last_added_
+ 1;
54 size_t SpdyCredentialState::FindCredentialSlot(const GURL
& origin
) const {
55 GURL url
= GetCanonicalOrigin(origin
);
56 for (size_t i
= 0; i
< slots_
.size(); i
++) {
63 void SpdyCredentialState::Resize(size_t size
) {
65 if (last_added_
>= slots_
.size())
66 last_added_
= slots_
.size() - 1;