| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/core/crypto/properties_based_quic_server_info.h" | 5 #include "net/quic/core/crypto/properties_based_quic_server_info.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/metrics/histogram_macros.h" |
| 8 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 9 #include "net/http/http_server_properties.h" | 10 #include "net/http/http_server_properties.h" |
| 10 | 11 |
| 11 using std::string; | 12 using std::string; |
| 12 | 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 |
| 13 namespace net { | 31 namespace net { |
| 14 | 32 |
| 15 PropertiesBasedQuicServerInfo::PropertiesBasedQuicServerInfo( | 33 PropertiesBasedQuicServerInfo::PropertiesBasedQuicServerInfo( |
| 16 const QuicServerId& server_id, | 34 const QuicServerId& server_id, |
| 17 HttpServerProperties* http_server_properties) | 35 HttpServerProperties* http_server_properties) |
| 18 : QuicServerInfo(server_id), | 36 : QuicServerInfo(server_id), |
| 19 http_server_properties_(http_server_properties) { | 37 http_server_properties_(http_server_properties) { |
| 20 DCHECK(http_server_properties_); | 38 DCHECK(http_server_properties_); |
| 21 } | 39 } |
| 22 | 40 |
| 23 PropertiesBasedQuicServerInfo::~PropertiesBasedQuicServerInfo() {} | 41 PropertiesBasedQuicServerInfo::~PropertiesBasedQuicServerInfo() {} |
| 24 | 42 |
| 25 void PropertiesBasedQuicServerInfo::Start() {} | 43 void PropertiesBasedQuicServerInfo::Start() { |
| 44 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_START); |
| 45 } |
| 26 | 46 |
| 27 int PropertiesBasedQuicServerInfo::WaitForDataReady( | 47 int PropertiesBasedQuicServerInfo::WaitForDataReady( |
| 28 const CompletionCallback& callback) { | 48 const CompletionCallback& callback) { |
| 49 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_WAIT_FOR_DATA_READY); |
| 29 const string* data = http_server_properties_->GetQuicServerInfo(server_id_); | 50 const string* data = http_server_properties_->GetQuicServerInfo(server_id_); |
| 30 string decoded; | 51 string decoded; |
| 31 if (!data || !base::Base64Decode(*data, &decoded) || !Parse(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); |
| 32 return ERR_FAILED; | 63 return ERR_FAILED; |
| 33 } | 64 } |
| 34 return OK; | 65 return OK; |
| 35 } | 66 } |
| 36 | 67 |
| 37 void PropertiesBasedQuicServerInfo::ResetWaitForDataReadyCallback() {} | 68 void PropertiesBasedQuicServerInfo::ResetWaitForDataReadyCallback() { |
| 69 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_RESET_WAIT_FOR_DATA_READY); |
| 70 } |
| 38 | 71 |
| 39 void PropertiesBasedQuicServerInfo::CancelWaitForDataReadyCallback() {} | 72 void PropertiesBasedQuicServerInfo::CancelWaitForDataReadyCallback() { |
| 73 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_WAIT_FOR_DATA_READY_CANCEL); |
| 74 } |
| 40 | 75 |
| 41 bool PropertiesBasedQuicServerInfo::IsDataReady() { | 76 bool PropertiesBasedQuicServerInfo::IsDataReady() { |
| 42 return true; | 77 return true; |
| 43 } | 78 } |
| 44 | 79 |
| 45 bool PropertiesBasedQuicServerInfo::IsReadyToPersist() { | 80 bool PropertiesBasedQuicServerInfo::IsReadyToPersist() { |
| 81 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_READY_TO_PERSIST); |
| 46 return true; | 82 return true; |
| 47 } | 83 } |
| 48 | 84 |
| 49 void PropertiesBasedQuicServerInfo::Persist() { | 85 void PropertiesBasedQuicServerInfo::Persist() { |
| 86 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_PERSIST); |
| 50 string encoded; | 87 string encoded; |
| 51 base::Base64Encode(Serialize(), &encoded); | 88 base::Base64Encode(Serialize(), &encoded); |
| 52 http_server_properties_->SetQuicServerInfo(server_id_, encoded); | 89 http_server_properties_->SetQuicServerInfo(server_id_, encoded); |
| 53 } | 90 } |
| 54 | 91 |
| 55 void PropertiesBasedQuicServerInfo::OnExternalCacheHit() {} | 92 void PropertiesBasedQuicServerInfo::OnExternalCacheHit() { |
| 93 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_EXTERNAL_CACHE_HIT); |
| 94 } |
| 56 | 95 |
| 57 PropertiesBasedQuicServerInfoFactory::PropertiesBasedQuicServerInfoFactory( | 96 PropertiesBasedQuicServerInfoFactory::PropertiesBasedQuicServerInfoFactory( |
| 58 HttpServerProperties* http_server_properties) | 97 HttpServerProperties* http_server_properties) |
| 59 : http_server_properties_(http_server_properties) {} | 98 : http_server_properties_(http_server_properties) {} |
| 60 | 99 |
| 61 PropertiesBasedQuicServerInfoFactory::~PropertiesBasedQuicServerInfoFactory() {} | 100 PropertiesBasedQuicServerInfoFactory::~PropertiesBasedQuicServerInfoFactory() {} |
| 62 | 101 |
| 63 QuicServerInfo* PropertiesBasedQuicServerInfoFactory::GetForServer( | 102 QuicServerInfo* PropertiesBasedQuicServerInfoFactory::GetForServer( |
| 64 const QuicServerId& server_id) { | 103 const QuicServerId& server_id) { |
| 65 return new PropertiesBasedQuicServerInfo(server_id, http_server_properties_); | 104 return new PropertiesBasedQuicServerInfo(server_id, http_server_properties_); |
| 66 } | 105 } |
| 67 | 106 |
| 68 } // namespace net | 107 } // namespace net |
| OLD | NEW |