Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/disk_cache/net_log_parameters.h" | 5 #include "net/disk_cache/net_log_parameters.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/disk_cache/disk_cache.h" | |
| 11 | 13 |
| 12 namespace disk_cache { | 14 namespace { |
| 13 | 15 |
| 14 EntryCreationParameters::EntryCreationParameters( | 16 Value* NetLogEntryCreationCallback(const disk_cache::Entry* entry, |
| 15 const std::string& key, | 17 bool created, |
| 16 bool created) | 18 net::NetLog::LogLevel /* log_level */) { |
| 17 : key_(key), | |
| 18 created_(created) { | |
| 19 } | |
| 20 | |
| 21 Value* EntryCreationParameters::ToValue() const { | |
| 22 DictionaryValue* dict = new DictionaryValue(); | 19 DictionaryValue* dict = new DictionaryValue(); |
| 23 dict->SetString("key", key_); | 20 dict->SetString("key", entry->GetKey()); |
| 24 dict->SetBoolean("created", created_); | 21 dict->SetBoolean("created", created); |
| 25 return dict; | 22 return dict; |
| 26 } | 23 } |
| 27 | 24 |
| 28 EntryCreationParameters::~EntryCreationParameters() {} | 25 Value* NetLogReadWriteDataCallback(int index, |
| 29 | 26 int offset, |
| 30 ReadWriteDataParameters::ReadWriteDataParameters( | 27 int buf_len, |
| 31 int index, | 28 bool truncate, |
| 32 int offset, | 29 net::NetLog::LogLevel /* log_level */) { |
| 33 int buf_len, | |
| 34 bool truncate) | |
| 35 : index_(index), | |
| 36 offset_(offset), | |
| 37 buf_len_(buf_len), | |
| 38 truncate_(truncate) { | |
| 39 } | |
| 40 | |
| 41 Value* ReadWriteDataParameters::ToValue() const { | |
| 42 DictionaryValue* dict = new DictionaryValue(); | 30 DictionaryValue* dict = new DictionaryValue(); |
| 43 dict->SetInteger("index", index_); | 31 dict->SetInteger("index", index); |
| 44 dict->SetInteger("offset", offset_); | 32 dict->SetInteger("offset", offset); |
| 45 dict->SetInteger("buf_len", buf_len_); | 33 dict->SetInteger("buf_len", buf_len); |
| 46 if (truncate_) | 34 if (truncate) |
| 47 dict->SetBoolean("truncate", truncate_); | 35 dict->SetBoolean("truncate", truncate); |
| 48 return dict; | 36 return dict; |
| 49 } | 37 } |
| 50 | 38 |
| 51 ReadWriteDataParameters::~ReadWriteDataParameters() {} | 39 Value* NetLogReadWriteCompleteCallback(int bytes_copied, |
| 52 | 40 net::NetLog::LogLevel /* log_level */) { |
| 53 // NetLog parameters logged when non-sparse reads and writes complete. | 41 DCHECK_NE(bytes_copied, net::ERR_IO_PENDING); |
| 54 ReadWriteCompleteParameters::ReadWriteCompleteParameters(int bytes_copied) | |
| 55 : bytes_copied_(bytes_copied) { | |
| 56 } | |
| 57 | |
| 58 Value* ReadWriteCompleteParameters::ToValue() const { | |
| 59 DCHECK_NE(bytes_copied_, net::ERR_IO_PENDING); | |
| 60 DictionaryValue* dict = new DictionaryValue(); | 42 DictionaryValue* dict = new DictionaryValue(); |
| 61 if (bytes_copied_ < 0) { | 43 if (bytes_copied < 0) { |
| 62 dict->SetInteger("net_error", bytes_copied_); | 44 dict->SetInteger("net_error", bytes_copied); |
| 63 } else { | 45 } else { |
| 64 dict->SetInteger("bytes_copied", bytes_copied_); | 46 dict->SetInteger("bytes_copied", bytes_copied); |
| 65 } | 47 } |
| 66 return dict; | 48 return dict; |
| 67 } | 49 } |
| 68 | 50 |
| 69 ReadWriteCompleteParameters::~ReadWriteCompleteParameters() {} | 51 Value* NetLogSparseOperationCallback(int64 offset, |
| 70 | 52 int buff_len, |
| 71 SparseOperationParameters::SparseOperationParameters( | 53 net::NetLog::LogLevel /* log_level */) { |
| 72 int64 offset, | |
| 73 int buff_len) | |
| 74 : offset_(offset), | |
| 75 buff_len_(buff_len) { | |
| 76 } | |
| 77 | |
| 78 Value* SparseOperationParameters::ToValue() const { | |
| 79 DictionaryValue* dict = new DictionaryValue(); | 54 DictionaryValue* dict = new DictionaryValue(); |
| 80 // Values can only be created with at most 32-bit integers. Using a string | 55 // Values can only be created with at most 32-bit integers. Using a string |
| 81 // instead circumvents that restriction. | 56 // instead circumvents that restriction. |
| 82 dict->SetString("offset", base::Int64ToString(offset_)); | 57 dict->SetString("offset", base::Int64ToString(offset)); |
| 83 dict->SetInteger("buff_len", buff_len_); | 58 dict->SetInteger("buff_len", buff_len); |
| 84 return dict; | 59 return dict; |
| 85 } | 60 } |
| 86 | 61 |
| 87 SparseOperationParameters::~SparseOperationParameters() {} | 62 Value* NetLogSparseReadWriteCallback(const net::NetLog::Source& source, |
| 88 | 63 int child_len, |
| 89 SparseReadWriteParameters::SparseReadWriteParameters( | 64 net::NetLog::LogLevel /* log_level */) { |
| 90 const net::NetLog::Source& source, | |
| 91 int child_len) | |
| 92 : source_(source), | |
| 93 child_len_(child_len) { | |
| 94 } | |
| 95 | |
| 96 Value* SparseReadWriteParameters::ToValue() const { | |
| 97 DictionaryValue* dict = new DictionaryValue(); | 65 DictionaryValue* dict = new DictionaryValue(); |
| 98 dict->Set("source_dependency", source_.ToValue()); | 66 source.AddToEventParameters(dict); |
| 99 dict->SetInteger("child_len", child_len_); | 67 dict->SetInteger("child_len", child_len); |
| 100 return dict; | 68 return dict; |
| 101 } | 69 } |
| 102 | 70 |
| 103 SparseReadWriteParameters::~SparseReadWriteParameters() {} | 71 Value* NetLogGetAvailableRangeResultCallback( |
| 104 | |
| 105 GetAvailableRangeResultParameters::GetAvailableRangeResultParameters( | |
| 106 int64 start, | 72 int64 start, |
| 107 int result) | 73 int result, |
| 108 : start_(start), | 74 net::NetLog::LogLevel /* log_level */) { |
| 109 result_(result) { | |
| 110 } | |
| 111 | |
| 112 Value* GetAvailableRangeResultParameters::ToValue() const { | |
| 113 DictionaryValue* dict = new DictionaryValue(); | 75 DictionaryValue* dict = new DictionaryValue(); |
| 114 if (result_ > 0) { | 76 if (result > 0) { |
| 115 dict->SetInteger("length", result_); | 77 dict->SetInteger("length", result); |
| 116 dict->SetString("start", base::Int64ToString(start_)); | 78 dict->SetString("start", base::Int64ToString(start)); |
| 117 } else { | 79 } else { |
| 118 dict->SetInteger("net_error", result_); | 80 dict->SetInteger("net_error", result); |
| 119 } | 81 } |
| 120 return dict; | 82 return dict; |
| 121 } | 83 } |
| 122 | 84 |
| 123 GetAvailableRangeResultParameters::~GetAvailableRangeResultParameters() {} | 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 } | |
| 124 | 127 |
| 125 } // namespace disk_cache | 128 } // namespace disk_cache |
|
eroman
2012/06/12 16:54:07
I wonder why disk_cache isn't inside of the net::
mmenke
2012/06/12 16:59:09
I don't think I've seen any nested namespaces used
| |
| OLD | NEW |