simple_net_log_parameters.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2013 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/disk_cache/simple/simple_net_log_parameters.h"
  5. #include <utility>
  6. #include "base/bind.h"
  7. #include "base/check.h"
  8. #include "base/compiler_specific.h"
  9. #include "base/format_macros.h"
  10. #include "base/strings/stringprintf.h"
  11. #include "base/values.h"
  12. #include "net/base/net_errors.h"
  13. #include "net/disk_cache/simple/simple_entry_impl.h"
  14. #include "net/log/net_log_capture_mode.h"
  15. namespace {
  16. base::Value NetLogSimpleEntryConstructionParams(
  17. const disk_cache::SimpleEntryImpl* entry) {
  18. base::Value::Dict dict;
  19. dict.Set("entry_hash",
  20. base::StringPrintf("%#016" PRIx64, entry->entry_hash()));
  21. return base::Value(std::move(dict));
  22. }
  23. base::Value NetLogSimpleEntryCreationParams(
  24. const disk_cache::SimpleEntryImpl* entry,
  25. int net_error) {
  26. base::Value::Dict dict;
  27. dict.Set("net_error", net_error);
  28. if (net_error == net::OK)
  29. dict.Set("key", entry->key());
  30. return base::Value(std::move(dict));
  31. }
  32. } // namespace
  33. namespace disk_cache {
  34. void NetLogSimpleEntryConstruction(const net::NetLogWithSource& net_log,
  35. net::NetLogEventType type,
  36. net::NetLogEventPhase phase,
  37. const SimpleEntryImpl* entry) {
  38. DCHECK(entry);
  39. net_log.AddEntry(type, phase,
  40. [&] { return NetLogSimpleEntryConstructionParams(entry); });
  41. }
  42. void NetLogSimpleEntryCreation(const net::NetLogWithSource& net_log,
  43. net::NetLogEventType type,
  44. net::NetLogEventPhase phase,
  45. const SimpleEntryImpl* entry,
  46. int net_error) {
  47. DCHECK(entry);
  48. net_log.AddEntry(type, phase, [&] {
  49. return NetLogSimpleEntryCreationParams(entry, net_error);
  50. });
  51. }
  52. } // namespace disk_cache