[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 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 7 | #include "base/bind.h" |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 8 | #include "base/logging.h" |
| 9 | #include "base/string_number_conversions.h" |
| 10 | #include "base/values.h" |
| 11 | #include "net/base/net_errors.h" |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 12 | #include "net/disk_cache/disk_cache.h" |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 13 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 14 | namespace { |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 15 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 16 | Value* NetLogEntryCreationCallback(const disk_cache::Entry* entry, |
| 17 | bool created, |
| 18 | net::NetLog::LogLevel /* log_level */) { |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 19 | DictionaryValue* dict = new DictionaryValue(); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 20 | dict->SetString("key", entry->GetKey()); |
| 21 | dict->SetBoolean("created", created); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 22 | return dict; |
| 23 | } |
| 24 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 25 | Value* NetLogReadWriteDataCallback(int index, |
| 26 | int offset, |
| 27 | int buf_len, |
| 28 | bool truncate, |
| 29 | net::NetLog::LogLevel /* log_level */) { |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 30 | DictionaryValue* dict = new DictionaryValue(); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 31 | dict->SetInteger("index", index); |
| 32 | dict->SetInteger("offset", offset); |
| 33 | dict->SetInteger("buf_len", buf_len); |
| 34 | if (truncate) |
| 35 | dict->SetBoolean("truncate", truncate); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 36 | return dict; |
| 37 | } |
| 38 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 39 | Value* NetLogReadWriteCompleteCallback(int bytes_copied, |
| 40 | net::NetLog::LogLevel /* log_level */) { |
| 41 | DCHECK_NE(bytes_copied, net::ERR_IO_PENDING); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 42 | DictionaryValue* dict = new DictionaryValue(); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 43 | if (bytes_copied < 0) { |
| 44 | dict->SetInteger("net_error", bytes_copied); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 45 | } else { |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 46 | dict->SetInteger("bytes_copied", bytes_copied); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 47 | } |
| 48 | return dict; |
| 49 | } |
| 50 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 51 | Value* NetLogSparseOperationCallback(int64 offset, |
| 52 | int buff_len, |
| 53 | net::NetLog::LogLevel /* log_level */) { |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 54 | DictionaryValue* dict = new DictionaryValue(); |
| 55 | // Values can only be created with at most 32-bit integers. Using a string |
| 56 | // instead circumvents that restriction. |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 57 | dict->SetString("offset", base::Int64ToString(offset)); |
| 58 | dict->SetInteger("buff_len", buff_len); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 59 | return dict; |
| 60 | } |
| 61 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 62 | Value* NetLogSparseReadWriteCallback(const net::NetLog::Source& source, |
| 63 | int child_len, |
| 64 | net::NetLog::LogLevel /* log_level */) { |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 65 | DictionaryValue* dict = new DictionaryValue(); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 66 | source.AddToEventParameters(dict); |
| 67 | dict->SetInteger("child_len", child_len); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 68 | return dict; |
| 69 | } |
| 70 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 71 | Value* NetLogGetAvailableRangeResultCallback( |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 72 | int64 start, |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 73 | int result, |
| 74 | net::NetLog::LogLevel /* log_level */) { |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 75 | DictionaryValue* dict = new DictionaryValue(); |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 76 | if (result > 0) { |
| 77 | dict->SetInteger("length", result); |
| 78 | dict->SetString("start", base::Int64ToString(start)); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 79 | } else { |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 80 | dict->SetInteger("net_error", result); |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 81 | } |
| 82 | return dict; |
| 83 | } |
| 84 | |
[email protected] | 8cab8a8 | 2012-06-12 19:07:09 | [diff] [blame^] | 85 | } // namespace |
| 86 | |
| 87 | namespace disk_cache { |
| 88 | |
| 89 | net::NetLog::ParametersCallback CreateNetLogEntryCreationCallback( |
| 90 | const Entry* entry, |
| 91 | bool created) { |
| 92 | DCHECK(entry); |
| 93 | return base::Bind(&NetLogEntryCreationCallback, entry, created); |
| 94 | } |
| 95 | |
| 96 | net::NetLog::ParametersCallback CreateNetLogReadWriteDataCallback( |
| 97 | int index, |
| 98 | int offset, |
| 99 | int buf_len, |
| 100 | bool truncate) { |
| 101 | return base::Bind(&NetLogReadWriteDataCallback, |
| 102 | index, offset, buf_len, truncate); |
| 103 | } |
| 104 | |
| 105 | net::NetLog::ParametersCallback CreateNetLogReadWriteCompleteCallback( |
| 106 | int bytes_copied) { |
| 107 | return base::Bind(&NetLogReadWriteCompleteCallback, bytes_copied); |
| 108 | } |
| 109 | |
| 110 | net::NetLog::ParametersCallback CreateNetLogSparseOperationCallback( |
| 111 | int64 offset, |
| 112 | int buff_len) { |
| 113 | return base::Bind(&NetLogSparseOperationCallback, offset, buff_len); |
| 114 | } |
| 115 | |
| 116 | net::NetLog::ParametersCallback CreateNetLogSparseReadWriteCallback( |
| 117 | const net::NetLog::Source& source, |
| 118 | int child_len) { |
| 119 | return base::Bind(&NetLogSparseReadWriteCallback, source, child_len); |
| 120 | } |
| 121 | |
| 122 | net::NetLog::ParametersCallback CreateNetLogGetAvailableRangeResultCallback( |
| 123 | int64 start, |
| 124 | int result) { |
| 125 | return base::Bind(&NetLogGetAvailableRangeResultCallback, start, result); |
| 126 | } |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 127 | |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 128 | } // namespace disk_cache |