[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 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/net_log_parameters.h" |
| 6 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | be528af | 2013-06-11 07:39:48 | [diff] [blame] | 11 | #include "base/strings/string_number_conversions.h" |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 12 | #include "base/values.h" |
| 13 | #include "net/base/net_errors.h" |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 14 | #include "net/disk_cache/disk_cache.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 15 | #include "net/log/net_log_capture_mode.h" |
| 16 | #include "net/log/net_log_source.h" |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 17 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 18 | namespace { |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 19 | |
Oscar Johansson | b052f39 | 2018-07-02 13:50:07 | [diff] [blame] | 20 | std::unique_ptr<base::Value> NetLogParametersEntryCreationCallback( |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 21 | const disk_cache::Entry* entry, |
| 22 | bool created, |
eroman | 001c374 | 2015-04-23 03:11:17 | [diff] [blame] | 23 | net::NetLogCaptureMode /* capture_mode */) { |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 24 | std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 25 | dict->SetString("key", entry->GetKey()); |
| 26 | dict->SetBoolean("created", created); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 27 | return std::move(dict); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 28 | } |
| 29 | |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 30 | std::unique_ptr<base::Value> NetLogReadWriteDataCallback( |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 31 | int index, |
| 32 | int offset, |
| 33 | int buf_len, |
| 34 | bool truncate, |
eroman | 001c374 | 2015-04-23 03:11:17 | [diff] [blame] | 35 | net::NetLogCaptureMode /* capture_mode */) { |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 36 | std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 37 | dict->SetInteger("index", index); |
| 38 | dict->SetInteger("offset", offset); |
| 39 | dict->SetInteger("buf_len", buf_len); |
| 40 | if (truncate) |
| 41 | dict->SetBoolean("truncate", truncate); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 42 | return std::move(dict); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 43 | } |
| 44 | |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 45 | std::unique_ptr<base::Value> NetLogReadWriteCompleteCallback( |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 46 | int bytes_copied, |
eroman | 001c374 | 2015-04-23 03:11:17 | [diff] [blame] | 47 | net::NetLogCaptureMode /* capture_mode */) { |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 48 | DCHECK_NE(bytes_copied, net::ERR_IO_PENDING); |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 49 | std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 50 | if (bytes_copied < 0) { |
| 51 | dict->SetInteger("net_error", bytes_copied); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 52 | } else { |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 53 | dict->SetInteger("bytes_copied", bytes_copied); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 54 | } |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 55 | return std::move(dict); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 56 | } |
| 57 | |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 58 | std::unique_ptr<base::Value> NetLogSparseOperationCallback( |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 59 | int64_t offset, |
ttuttle | 1eba472 | 2015-11-06 22:35:36 | [diff] [blame] | 60 | int buf_len, |
eroman | 001c374 | 2015-04-23 03:11:17 | [diff] [blame] | 61 | net::NetLogCaptureMode /* capture_mode */) { |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 62 | std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 63 | // Values can only be created with at most 32-bit integers. Using a string |
| 64 | // instead circumvents that restriction. |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 65 | dict->SetString("offset", base::Int64ToString(offset)); |
ttuttle | 1eba472 | 2015-11-06 22:35:36 | [diff] [blame] | 66 | dict->SetInteger("buf_len", buf_len); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 67 | return std::move(dict); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 68 | } |
| 69 | |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 70 | std::unique_ptr<base::Value> NetLogSparseReadWriteCallback( |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 71 | const net::NetLogSource& source, |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 72 | int child_len, |
eroman | 001c374 | 2015-04-23 03:11:17 | [diff] [blame] | 73 | net::NetLogCaptureMode /* capture_mode */) { |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 74 | std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
estade | 5e5529d | 2015-05-21 20:59:11 | [diff] [blame] | 75 | source.AddToEventParameters(dict.get()); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 76 | dict->SetInteger("child_len", child_len); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 77 | return std::move(dict); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 78 | } |
| 79 | |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 80 | std::unique_ptr<base::Value> NetLogGetAvailableRangeResultCallback( |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 81 | int64_t start, |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 82 | int result, |
eroman | 001c374 | 2015-04-23 03:11:17 | [diff] [blame] | 83 | net::NetLogCaptureMode /* capture_mode */) { |
danakj | d04b92d | 2016-04-16 01:16:49 | [diff] [blame] | 84 | std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 85 | if (result > 0) { |
| 86 | dict->SetInteger("length", result); |
| 87 | dict->SetString("start", base::Int64ToString(start)); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 88 | } else { |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 89 | dict->SetInteger("net_error", result); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 90 | } |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 91 | return std::move(dict); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 92 | } |
| 93 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 94 | } // namespace |
| 95 | |
| 96 | namespace disk_cache { |
| 97 | |
Oscar Johansson | b052f39 | 2018-07-02 13:50:07 | [diff] [blame] | 98 | net::NetLogParametersCallback CreateNetLogParametersEntryCreationCallback( |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 99 | const Entry* entry, |
| 100 | bool created) { |
| 101 | DCHECK(entry); |
Oscar Johansson | b052f39 | 2018-07-02 13:50:07 | [diff] [blame] | 102 | return base::Bind(&NetLogParametersEntryCreationCallback, entry, created); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 103 | } |
| 104 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 105 | net::NetLogParametersCallback CreateNetLogReadWriteDataCallback(int index, |
| 106 | int offset, |
| 107 | int buf_len, |
| 108 | bool truncate) { |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 109 | return base::Bind(&NetLogReadWriteDataCallback, |
| 110 | index, offset, buf_len, truncate); |
| 111 | } |
| 112 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 113 | net::NetLogParametersCallback CreateNetLogReadWriteCompleteCallback( |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 114 | int bytes_copied) { |
| 115 | return base::Bind(&NetLogReadWriteCompleteCallback, bytes_copied); |
| 116 | } |
| 117 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 118 | net::NetLogParametersCallback CreateNetLogSparseOperationCallback( |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 119 | int64_t offset, |
ttuttle | 1eba472 | 2015-11-06 22:35:36 | [diff] [blame] | 120 | int buf_len) { |
| 121 | return base::Bind(&NetLogSparseOperationCallback, offset, buf_len); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 122 | } |
| 123 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 124 | net::NetLogParametersCallback CreateNetLogSparseReadWriteCallback( |
| 125 | const net::NetLogSource& source, |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 126 | int child_len) { |
| 127 | return base::Bind(&NetLogSparseReadWriteCallback, source, child_len); |
| 128 | } |
| 129 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 130 | net::NetLogParametersCallback CreateNetLogGetAvailableRangeResultCallback( |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 131 | int64_t start, |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame] | 132 | int result) { |
| 133 | return base::Bind(&NetLogGetAvailableRangeResultCallback, start, result); |
| 134 | } |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 135 | |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 136 | } // namespace disk_cache |