1 // Copyright 2015 The Chromium Authors
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/quic/properties_based_quic_server_info.h"
7 #include "base/base64.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "net/base/net_errors.h"
10 #include "net/http/http_server_properties.h"
16 void RecordQuicServerInfoFailure(net::QuicServerInfo::FailureReason failure) {
17 UMA_HISTOGRAM_ENUMERATION(
18 "Net.QuicDiskCache.FailureReason.PropertiesBasedCache", failure,
19 net::QuicServerInfo::NUM_OF_FAILURES);
26 PropertiesBasedQuicServerInfo::PropertiesBasedQuicServerInfo(
27 const quic::QuicServerId& server_id,
28 const NetworkAnonymizationKey& network_anonymization_key,
29 HttpServerProperties* http_server_properties)
30 : QuicServerInfo(server_id),
31 network_anonymization_key_(network_anonymization_key),
32 http_server_properties_(http_server_properties) {
33 DCHECK(http_server_properties_);
36 PropertiesBasedQuicServerInfo::~PropertiesBasedQuicServerInfo() = default;
38 bool PropertiesBasedQuicServerInfo::Load() {
39 const string* data = http_server_properties_->GetQuicServerInfo(
40 server_id_, network_anonymization_key_);
43 RecordQuicServerInfoFailure(PARSE_NO_DATA_FAILURE);
46 if (!base::Base64Decode(*data, &decoded)) {
47 RecordQuicServerInfoFailure(PARSE_DATA_DECODE_FAILURE);
50 if (!Parse(decoded)) {
51 RecordQuicServerInfoFailure(PARSE_FAILURE);
57 void PropertiesBasedQuicServerInfo::Persist() {
59 base::Base64Encode(Serialize(), &encoded);
60 http_server_properties_->SetQuicServerInfo(
61 server_id_, network_anonymization_key_, encoded);