diff options
author | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
---|---|---|
committer | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
commit | 679147eead574d186ebf3069647b4c23e8ccace6 (patch) | |
tree | fc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/net/spdy/spdy_credential_state.cc | |
download | qtwebengine-chromium-679147eead574d186ebf3069647b4c23e8ccace6.tar.gz |
Initial import.
Diffstat (limited to 'chromium/net/spdy/spdy_credential_state.cc')
-rw-r--r-- | chromium/net/spdy/spdy_credential_state.cc | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/chromium/net/spdy/spdy_credential_state.cc b/chromium/net/spdy/spdy_credential_state.cc new file mode 100644 index 00000000000..4549b3727f3 --- /dev/null +++ b/chromium/net/spdy/spdy_credential_state.cc @@ -0,0 +1,69 @@ +// 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 "net/spdy/spdy_credential_state.h" + +#include "base/logging.h" +#include "base/strings/string_util.h" +#include "net/ssl/server_bound_cert_service.h" + +namespace net { + +namespace { + +GURL GetCanonicalOrigin(const GURL& url) { + std::string domain = + ServerBoundCertService::GetDomainForHost(url.host()); + DCHECK(!domain.empty()); + if (domain == url.host()) + return url.GetOrigin(); + return GURL(url.scheme() + "://" + domain + ":" + url.port()); +} + +} // namespace + +const size_t SpdyCredentialState::kDefaultNumSlots = 8; +const size_t SpdyCredentialState::kNoEntry = 0; + +SpdyCredentialState::SpdyCredentialState(size_t num_slots) + : slots_(num_slots), + last_added_(-1) {} + +SpdyCredentialState::~SpdyCredentialState() {} + +bool SpdyCredentialState::HasCredential(const GURL& origin) const { + return FindCredentialSlot(origin) != kNoEntry; +} + +size_t SpdyCredentialState::SetHasCredential(const GURL& origin) { + size_t i = FindCredentialSlot(origin); + if (i != kNoEntry) + return i; + // Add the new entry at the next index following the index of the last + // entry added, or at index 0 if the last added index is the last index. + if (last_added_ + 1 == slots_.size()) { + last_added_ = 0; + } else { + last_added_++; + } + slots_[last_added_] = GetCanonicalOrigin(origin); + return last_added_ + 1; +} + +size_t SpdyCredentialState::FindCredentialSlot(const GURL& origin) const { + GURL url = GetCanonicalOrigin(origin); + for (size_t i = 0; i < slots_.size(); i++) { + if (url == slots_[i]) + return i + 1; + } + return kNoEntry; +} + +void SpdyCredentialState::Resize(size_t size) { + slots_.resize(size); + if (last_added_ >= slots_.size()) + last_added_ = slots_.size() - 1; +} + +} // namespace net |