summaryrefslogtreecommitdiffstats
path: root/net/spdy/spdy_credential_state.h
blob: 1460eacc00c754188d78c0df0509a33d7e39b114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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.

#ifndef NET_SPDY_SPDY_CREDENTIAL_STATE_H_
#define NET_SPDY_SPDY_CREDENTIAL_STATE_H_

#include <vector>

#include "googleurl/src/gurl.h"
#include "net/base/net_export.h"

namespace net {

// A class for tracking the credentials associated with a SPDY session.
class NET_EXPORT_PRIVATE SpdyCredentialState {
 public:
  explicit SpdyCredentialState(size_t num_slots);
  ~SpdyCredentialState();

  // Changes the number of credentials being tracked.  If the new size is
  // larger, then empty slots will be added to the end.  If the new size is
  // smaller than the current size, then the extra slots will be truncated
  // from the end.
  void Resize(size_t size);

  // Returns the one-based index in |slots_| for |url| or kNoEntry, if no entry
  // for |url| exists.
  size_t FindCredentialSlot(const GURL& url) const;

  // Returns true if there is a credential associated with |url|.
  bool HasCredential(const GURL& url) const;

  // Adds the new credentials to be associated with all origins matching
  // |url|.  If there is space, then it will add in the first available
  // position.  Otherwise, an existing credential will be evicted.  Returns
  // the slot in which this domain was added.
  size_t SetHasCredential(const GURL& url);

  // This value is defined as the default initial value in the SPDY spec unless
  // otherwise negotiated via SETTINGS.
  static const size_t kDefaultNumSlots;

  // Sentinel value to be returned by FindCredentialSlot when no entry exists.
  static const size_t kNoEntry;

 private:
  // Vector of origins that have credentials.
  std::vector<GURL> slots_;
  // Index of the last origin added to |slots_|.
  size_t last_added_;
};

}  // namespace net

#endif  // NET_SPDY_SPDY_CREDENTIAL_STATE_H_