Add IS_TIZEN_DA to fix build break in standard build.
[platform/framework/web/chromium-efl.git] / net / quic / properties_based_quic_server_info.cc
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
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
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_);
34 }
35
36 PropertiesBasedQuicServerInfo::~PropertiesBasedQuicServerInfo() = default;
37
38 bool PropertiesBasedQuicServerInfo::Load() {
39   const string* data = http_server_properties_->GetQuicServerInfo(
40       server_id_, network_anonymization_key_);
41   string decoded;
42   if (!data) {
43     RecordQuicServerInfoFailure(PARSE_NO_DATA_FAILURE);
44     return false;
45   }
46   if (!base::Base64Decode(*data, &decoded)) {
47     RecordQuicServerInfoFailure(PARSE_DATA_DECODE_FAILURE);
48     return false;
49   }
50   if (!Parse(decoded)) {
51     RecordQuicServerInfoFailure(PARSE_FAILURE);
52     return false;
53   }
54   return true;
55 }
56
57 void PropertiesBasedQuicServerInfo::Persist() {
58   string encoded;
59   base::Base64Encode(Serialize(), &encoded);
60   http_server_properties_->SetQuicServerInfo(
61       server_id_, network_anonymization_key_, encoded);
62 }
63
64 }  // namespace net