properties_based_quic_server_info.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "net/quic/properties_based_quic_server_info.h"
  5. #include "base/base64.h"
  6. #include "base/metrics/histogram_macros.h"
  7. #include "net/base/net_errors.h"
  8. #include "net/http/http_server_properties.h"
  9. using std::string;
  10. namespace {
  11. void RecordQuicServerInfoFailure(net::QuicServerInfo::FailureReason failure) {
  12. UMA_HISTOGRAM_ENUMERATION(
  13. "Net.QuicDiskCache.FailureReason.PropertiesBasedCache", failure,
  14. net::QuicServerInfo::NUM_OF_FAILURES);
  15. }
  16. } // namespace
  17. namespace net {
  18. PropertiesBasedQuicServerInfo::PropertiesBasedQuicServerInfo(
  19. const quic::QuicServerId& server_id,
  20. const NetworkIsolationKey& network_isolation_key,
  21. HttpServerProperties* http_server_properties)
  22. : QuicServerInfo(server_id),
  23. network_isolation_key_(network_isolation_key),
  24. http_server_properties_(http_server_properties) {
  25. DCHECK(http_server_properties_);
  26. }
  27. PropertiesBasedQuicServerInfo::~PropertiesBasedQuicServerInfo() = default;
  28. bool PropertiesBasedQuicServerInfo::Load() {
  29. const string* data = http_server_properties_->GetQuicServerInfo(
  30. server_id_, network_isolation_key_);
  31. string decoded;
  32. if (!data) {
  33. RecordQuicServerInfoFailure(PARSE_NO_DATA_FAILURE);
  34. return false;
  35. }
  36. if (!base::Base64Decode(*data, &decoded)) {
  37. RecordQuicServerInfoFailure(PARSE_DATA_DECODE_FAILURE);
  38. return false;
  39. }
  40. if (!Parse(decoded)) {
  41. RecordQuicServerInfoFailure(PARSE_FAILURE);
  42. return false;
  43. }
  44. return true;
  45. }
  46. void PropertiesBasedQuicServerInfo::Persist() {
  47. string encoded;
  48. base::Base64Encode(Serialize(), &encoded);
  49. http_server_properties_->SetQuicServerInfo(server_id_, network_isolation_key_,
  50. encoded);
  51. }
  52. } // namespace net