Pass CreateDirectory errors up to IndexedDB.
[chromium-blink-merge.git] / net / spdy / spdy_credential_state.cc
blob4549b3727f3f056732d6e28b17dec5d5bcf1fe23
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"
11 namespace net {
13 namespace {
15 GURL GetCanonicalOrigin(const GURL& url) {
16 std::string domain =
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());
24 } // namespace
26 const size_t SpdyCredentialState::kDefaultNumSlots = 8;
27 const size_t SpdyCredentialState::kNoEntry = 0;
29 SpdyCredentialState::SpdyCredentialState(size_t num_slots)
30 : slots_(num_slots),
31 last_added_(-1) {}
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);
41 if (i != kNoEntry)
42 return i;
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()) {
46 last_added_ = 0;
47 } else {
48 last_added_++;
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++) {
57 if (url == slots_[i])
58 return i + 1;
60 return kNoEntry;
63 void SpdyCredentialState::Resize(size_t size) {
64 slots_.resize(size);
65 if (last_added_ >= slots_.size())
66 last_added_ = slots_.size() - 1;
69 } // namespace net