blob: 6b971305bf54f9be960b767d4e27e3e50443cf0a [file] [log] [blame]
[email protected]a9813302012-04-28 09:29:281// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]9eb8cdf2011-03-17 18:53:022// 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/net_log_parameters.h"
6
dchengc7eeda422015-12-26 03:56:487#include <utility>
8
[email protected]8cab8a82012-06-12 19:07:099#include "base/bind.h"
[email protected]9eb8cdf2011-03-17 18:53:0210#include "base/logging.h"
[email protected]be528af2013-06-11 07:39:4811#include "base/strings/string_number_conversions.h"
[email protected]9eb8cdf2011-03-17 18:53:0212#include "base/values.h"
13#include "net/base/net_errors.h"
[email protected]8cab8a82012-06-12 19:07:0914#include "net/disk_cache/disk_cache.h"
mikecironef22f9812016-10-04 03:40:1915#include "net/log/net_log_capture_mode.h"
16#include "net/log/net_log_source.h"
[email protected]9eb8cdf2011-03-17 18:53:0217
[email protected]8cab8a82012-06-12 19:07:0918namespace {
[email protected]9eb8cdf2011-03-17 18:53:0219
Oscar Johanssonb052f392018-07-02 13:50:0720std::unique_ptr<base::Value> NetLogParametersEntryCreationCallback(
[email protected]ea5ef4c2013-06-13 22:50:2721 const disk_cache::Entry* entry,
22 bool created,
eroman001c3742015-04-23 03:11:1723 net::NetLogCaptureMode /* capture_mode */) {
danakjd04b92d2016-04-16 01:16:4924 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
[email protected]8cab8a82012-06-12 19:07:0925 dict->SetString("key", entry->GetKey());
26 dict->SetBoolean("created", created);
dchengc7eeda422015-12-26 03:56:4827 return std::move(dict);
[email protected]9eb8cdf2011-03-17 18:53:0228}
29
danakjd04b92d2016-04-16 01:16:4930std::unique_ptr<base::Value> NetLogReadWriteDataCallback(
[email protected]ea5ef4c2013-06-13 22:50:2731 int index,
32 int offset,
33 int buf_len,
34 bool truncate,
eroman001c3742015-04-23 03:11:1735 net::NetLogCaptureMode /* capture_mode */) {
danakjd04b92d2016-04-16 01:16:4936 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
[email protected]8cab8a82012-06-12 19:07:0937 dict->SetInteger("index", index);
38 dict->SetInteger("offset", offset);
39 dict->SetInteger("buf_len", buf_len);
40 if (truncate)
41 dict->SetBoolean("truncate", truncate);
dchengc7eeda422015-12-26 03:56:4842 return std::move(dict);
[email protected]9eb8cdf2011-03-17 18:53:0243}
44
danakjd04b92d2016-04-16 01:16:4945std::unique_ptr<base::Value> NetLogReadWriteCompleteCallback(
[email protected]ea5ef4c2013-06-13 22:50:2746 int bytes_copied,
eroman001c3742015-04-23 03:11:1747 net::NetLogCaptureMode /* capture_mode */) {
[email protected]8cab8a82012-06-12 19:07:0948 DCHECK_NE(bytes_copied, net::ERR_IO_PENDING);
danakjd04b92d2016-04-16 01:16:4949 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
[email protected]8cab8a82012-06-12 19:07:0950 if (bytes_copied < 0) {
51 dict->SetInteger("net_error", bytes_copied);
[email protected]9eb8cdf2011-03-17 18:53:0252 } else {
[email protected]8cab8a82012-06-12 19:07:0953 dict->SetInteger("bytes_copied", bytes_copied);
[email protected]9eb8cdf2011-03-17 18:53:0254 }
dchengc7eeda422015-12-26 03:56:4855 return std::move(dict);
[email protected]9eb8cdf2011-03-17 18:53:0256}
57
danakjd04b92d2016-04-16 01:16:4958std::unique_ptr<base::Value> NetLogSparseOperationCallback(
Avi Drissman13fc8932015-12-20 04:40:4659 int64_t offset,
ttuttle1eba4722015-11-06 22:35:3660 int buf_len,
eroman001c3742015-04-23 03:11:1761 net::NetLogCaptureMode /* capture_mode */) {
danakjd04b92d2016-04-16 01:16:4962 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
[email protected]9eb8cdf2011-03-17 18:53:0263 // Values can only be created with at most 32-bit integers. Using a string
64 // instead circumvents that restriction.
[email protected]8cab8a82012-06-12 19:07:0965 dict->SetString("offset", base::Int64ToString(offset));
ttuttle1eba4722015-11-06 22:35:3666 dict->SetInteger("buf_len", buf_len);
dchengc7eeda422015-12-26 03:56:4867 return std::move(dict);
[email protected]9eb8cdf2011-03-17 18:53:0268}
69
danakjd04b92d2016-04-16 01:16:4970std::unique_ptr<base::Value> NetLogSparseReadWriteCallback(
mikecironef22f9812016-10-04 03:40:1971 const net::NetLogSource& source,
[email protected]ea5ef4c2013-06-13 22:50:2772 int child_len,
eroman001c3742015-04-23 03:11:1773 net::NetLogCaptureMode /* capture_mode */) {
danakjd04b92d2016-04-16 01:16:4974 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
estade5e5529d2015-05-21 20:59:1175 source.AddToEventParameters(dict.get());
[email protected]8cab8a82012-06-12 19:07:0976 dict->SetInteger("child_len", child_len);
dchengc7eeda422015-12-26 03:56:4877 return std::move(dict);
[email protected]9eb8cdf2011-03-17 18:53:0278}
79
danakjd04b92d2016-04-16 01:16:4980std::unique_ptr<base::Value> NetLogGetAvailableRangeResultCallback(
Avi Drissman13fc8932015-12-20 04:40:4681 int64_t start,
[email protected]8cab8a82012-06-12 19:07:0982 int result,
eroman001c3742015-04-23 03:11:1783 net::NetLogCaptureMode /* capture_mode */) {
danakjd04b92d2016-04-16 01:16:4984 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
[email protected]8cab8a82012-06-12 19:07:0985 if (result > 0) {
86 dict->SetInteger("length", result);
87 dict->SetString("start", base::Int64ToString(start));
[email protected]9eb8cdf2011-03-17 18:53:0288 } else {
[email protected]8cab8a82012-06-12 19:07:0989 dict->SetInteger("net_error", result);
[email protected]9eb8cdf2011-03-17 18:53:0290 }
dchengc7eeda422015-12-26 03:56:4891 return std::move(dict);
[email protected]9eb8cdf2011-03-17 18:53:0292}
93
[email protected]8cab8a82012-06-12 19:07:0994} // namespace
95
96namespace disk_cache {
97
Oscar Johanssonb052f392018-07-02 13:50:0798net::NetLogParametersCallback CreateNetLogParametersEntryCreationCallback(
[email protected]8cab8a82012-06-12 19:07:0999 const Entry* entry,
100 bool created) {
101 DCHECK(entry);
Oscar Johanssonb052f392018-07-02 13:50:07102 return base::Bind(&NetLogParametersEntryCreationCallback, entry, created);
[email protected]8cab8a82012-06-12 19:07:09103}
104
mikecironef22f9812016-10-04 03:40:19105net::NetLogParametersCallback CreateNetLogReadWriteDataCallback(int index,
106 int offset,
107 int buf_len,
108 bool truncate) {
[email protected]8cab8a82012-06-12 19:07:09109 return base::Bind(&NetLogReadWriteDataCallback,
110 index, offset, buf_len, truncate);
111}
112
mikecironef22f9812016-10-04 03:40:19113net::NetLogParametersCallback CreateNetLogReadWriteCompleteCallback(
[email protected]8cab8a82012-06-12 19:07:09114 int bytes_copied) {
115 return base::Bind(&NetLogReadWriteCompleteCallback, bytes_copied);
116}
117
mikecironef22f9812016-10-04 03:40:19118net::NetLogParametersCallback CreateNetLogSparseOperationCallback(
Avi Drissman13fc8932015-12-20 04:40:46119 int64_t offset,
ttuttle1eba4722015-11-06 22:35:36120 int buf_len) {
121 return base::Bind(&NetLogSparseOperationCallback, offset, buf_len);
[email protected]8cab8a82012-06-12 19:07:09122}
123
mikecironef22f9812016-10-04 03:40:19124net::NetLogParametersCallback CreateNetLogSparseReadWriteCallback(
125 const net::NetLogSource& source,
[email protected]8cab8a82012-06-12 19:07:09126 int child_len) {
127 return base::Bind(&NetLogSparseReadWriteCallback, source, child_len);
128}
129
mikecironef22f9812016-10-04 03:40:19130net::NetLogParametersCallback CreateNetLogGetAvailableRangeResultCallback(
Avi Drissman13fc8932015-12-20 04:40:46131 int64_t start,
[email protected]8cab8a82012-06-12 19:07:09132 int result) {
133 return base::Bind(&NetLogGetAvailableRangeResultCallback, start, result);
134}
[email protected]a9813302012-04-28 09:29:28135
[email protected]9eb8cdf2011-03-17 18:53:02136} // namespace disk_cache