summaryrefslogtreecommitdiffstats
path: root/net/quic/crypto/properties_based_quic_server_info.cc
blob: 708f44a4f4a1246554dc9d05676a9c3e837b1e69 (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
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2015 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/quic/crypto/properties_based_quic_server_info.h"

#include "base/base64.h"
#include "net/base/net_errors.h"
#include "net/http/http_server_properties.h"

using std::string;

namespace net {

PropertiesBasedQuicServerInfo::PropertiesBasedQuicServerInfo(
    const QuicServerId& server_id,
    base::WeakPtr<HttpServerProperties> http_server_properties)
    : QuicServerInfo(server_id),
      http_server_properties_(http_server_properties) {
  DCHECK(http_server_properties_);
}

PropertiesBasedQuicServerInfo::~PropertiesBasedQuicServerInfo() {}

void PropertiesBasedQuicServerInfo::Start() {}

int PropertiesBasedQuicServerInfo::WaitForDataReady(
    const CompletionCallback& callback) {
  const string* data = http_server_properties_->GetQuicServerInfo(server_id_);
  string decoded;
  if (!data || !base::Base64Decode(*data, &decoded) || !Parse(decoded)) {
    return ERR_FAILED;
  }
  return OK;
}

void PropertiesBasedQuicServerInfo::ResetWaitForDataReadyCallback() {}

void PropertiesBasedQuicServerInfo::CancelWaitForDataReadyCallback() {}

bool PropertiesBasedQuicServerInfo::IsDataReady() {
  return true;
}

bool PropertiesBasedQuicServerInfo::IsReadyToPersist() {
  return true;
}

void PropertiesBasedQuicServerInfo::Persist() {
  string encoded;
  base::Base64Encode(Serialize(), &encoded);
  http_server_properties_->SetQuicServerInfo(server_id_, encoded);
}

void PropertiesBasedQuicServerInfo::OnExternalCacheHit() {}

PropertiesBasedQuicServerInfoFactory::PropertiesBasedQuicServerInfoFactory(
    base::WeakPtr<HttpServerProperties> http_server_properties)
    : http_server_properties_(http_server_properties) {}

PropertiesBasedQuicServerInfoFactory::~PropertiesBasedQuicServerInfoFactory() {}

QuicServerInfo* PropertiesBasedQuicServerInfoFactory::GetForServer(
    const QuicServerId& server_id) {
  return new PropertiesBasedQuicServerInfo(server_id, http_server_properties_);
}

}  // namespace net