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