| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 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/core/crypto/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 RecordQuicServerInfoStatus( | |
| 17 net::QuicServerInfo::QuicServerInfoAPICall call) { | |
| 18 UMA_HISTOGRAM_ENUMERATION( | |
| 19 "Net.QuicDiskCache.APICall.PropertiesBasedCache", call, | |
| 20 net::QuicServerInfo::QUIC_SERVER_INFO_NUM_OF_API_CALLS); | |
| 21 } | |
| 22 | |
| 23 void RecordQuicServerInfoFailure(net::QuicServerInfo::FailureReason failure) { | |
| 24 UMA_HISTOGRAM_ENUMERATION( | |
| 25 "Net.QuicDiskCache.FailureReason.PropertiesBasedCache", failure, | |
| 26 net::QuicServerInfo::NUM_OF_FAILURES); | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 namespace net { | |
| 32 | |
| 33 PropertiesBasedQuicServerInfo::PropertiesBasedQuicServerInfo( | |
| 34 const QuicServerId& server_id, | |
| 35 HttpServerProperties* http_server_properties) | |
| 36 : QuicServerInfo(server_id), | |
| 37 http_server_properties_(http_server_properties) { | |
| 38 DCHECK(http_server_properties_); | |
| 39 } | |
| 40 | |
| 41 PropertiesBasedQuicServerInfo::~PropertiesBasedQuicServerInfo() {} | |
| 42 | |
| 43 void PropertiesBasedQuicServerInfo::Start() { | |
| 44 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_START); | |
| 45 } | |
| 46 | |
| 47 int PropertiesBasedQuicServerInfo::WaitForDataReady( | |
| 48 const CompletionCallback& callback) { | |
| 49 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_WAIT_FOR_DATA_READY); | |
| 50 const string* data = http_server_properties_->GetQuicServerInfo(server_id_); | |
| 51 string decoded; | |
| 52 if (!data) { | |
| 53 RecordQuicServerInfoFailure(PARSE_NO_DATA_FAILURE); | |
| 54 return ERR_FAILED; | |
| 55 } | |
| 56 if (!base::Base64Decode(*data, &decoded)) { | |
| 57 RecordQuicServerInfoFailure(PARSE_DATA_DECODE_FAILURE); | |
| 58 return ERR_FAILED; | |
| 59 } | |
| 60 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_PARSE); | |
| 61 if (!Parse(decoded)) { | |
| 62 RecordQuicServerInfoFailure(PARSE_FAILURE); | |
| 63 return ERR_FAILED; | |
| 64 } | |
| 65 return OK; | |
| 66 } | |
| 67 | |
| 68 void PropertiesBasedQuicServerInfo::ResetWaitForDataReadyCallback() { | |
| 69 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_RESET_WAIT_FOR_DATA_READY); | |
| 70 } | |
| 71 | |
| 72 void PropertiesBasedQuicServerInfo::CancelWaitForDataReadyCallback() { | |
| 73 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_WAIT_FOR_DATA_READY_CANCEL); | |
| 74 } | |
| 75 | |
| 76 bool PropertiesBasedQuicServerInfo::IsDataReady() { | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 bool PropertiesBasedQuicServerInfo::IsReadyToPersist() { | |
| 81 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_READY_TO_PERSIST); | |
| 82 return true; | |
| 83 } | |
| 84 | |
| 85 void PropertiesBasedQuicServerInfo::Persist() { | |
| 86 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_PERSIST); | |
| 87 string encoded; | |
| 88 base::Base64Encode(Serialize(), &encoded); | |
| 89 http_server_properties_->SetQuicServerInfo(server_id_, encoded); | |
| 90 } | |
| 91 | |
| 92 void PropertiesBasedQuicServerInfo::OnExternalCacheHit() { | |
| 93 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_EXTERNAL_CACHE_HIT); | |
| 94 } | |
| 95 | |
| 96 PropertiesBasedQuicServerInfoFactory::PropertiesBasedQuicServerInfoFactory( | |
| 97 HttpServerProperties* http_server_properties) | |
| 98 : http_server_properties_(http_server_properties) {} | |
| 99 | |
| 100 PropertiesBasedQuicServerInfoFactory::~PropertiesBasedQuicServerInfoFactory() {} | |
| 101 | |
| 102 QuicServerInfo* PropertiesBasedQuicServerInfoFactory::GetForServer( | |
| 103 const QuicServerId& server_id) { | |
| 104 return new PropertiesBasedQuicServerInfo(server_id, http_server_properties_); | |
| 105 } | |
| 106 | |
| 107 } // namespace net | |
| OLD | NEW |