• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "net/quic/properties_based_quic_server_info.h"
6 
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"
11 
12 using std::string;
13 
14 namespace {
15 
RecordQuicServerInfoFailure(net::QuicServerInfo::FailureReason failure)16 void RecordQuicServerInfoFailure(net::QuicServerInfo::FailureReason failure) {
17   UMA_HISTOGRAM_ENUMERATION(
18       "Net.QuicDiskCache.FailureReason.PropertiesBasedCache", failure,
19       net::QuicServerInfo::NUM_OF_FAILURES);
20 }
21 
22 }  // namespace
23 
24 namespace net {
25 
PropertiesBasedQuicServerInfo(const quic::QuicServerId & server_id,PrivacyMode privacy_mode,const NetworkAnonymizationKey & network_anonymization_key,HttpServerProperties * http_server_properties)26 PropertiesBasedQuicServerInfo::PropertiesBasedQuicServerInfo(
27     const quic::QuicServerId& server_id,
28     PrivacyMode privacy_mode,
29     const NetworkAnonymizationKey& network_anonymization_key,
30     HttpServerProperties* http_server_properties)
31     : QuicServerInfo(server_id),
32       privacy_mode_(privacy_mode),
33       network_anonymization_key_(network_anonymization_key),
34       http_server_properties_(http_server_properties) {
35   DCHECK(http_server_properties_);
36 }
37 
38 PropertiesBasedQuicServerInfo::~PropertiesBasedQuicServerInfo() = default;
39 
Load()40 bool PropertiesBasedQuicServerInfo::Load() {
41   const string* data = http_server_properties_->GetQuicServerInfo(
42       server_id_, privacy_mode_, network_anonymization_key_);
43   string decoded;
44   if (!data) {
45     RecordQuicServerInfoFailure(PARSE_NO_DATA_FAILURE);
46     return false;
47   }
48   if (!base::Base64Decode(*data, &decoded)) {
49     RecordQuicServerInfoFailure(PARSE_DATA_DECODE_FAILURE);
50     return false;
51   }
52   if (!Parse(decoded)) {
53     RecordQuicServerInfoFailure(PARSE_FAILURE);
54     return false;
55   }
56   return true;
57 }
58 
Persist()59 void PropertiesBasedQuicServerInfo::Persist() {
60   string encoded = base::Base64Encode(Serialize());
61   http_server_properties_->SetQuicServerInfo(
62       server_id_, privacy_mode_, network_anonymization_key_, encoded);
63 }
64 
65 }  // namespace net
66