| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 | 11 |
| 12 namespace disk_cache { | 12 namespace disk_cache { |
| 13 | 13 |
| 14 EntryCreationParameters::EntryCreationParameters( | 14 EntryCreationParameters::EntryCreationParameters( |
| 15 const std::string& key, bool created) | 15 const std::string& key, bool created) |
| 16 : key_(key), created_(created) { | 16 : key_(key), created_(created) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 EntryCreationParameters::~EntryCreationParameters() {} |
| 20 |
| 19 Value* EntryCreationParameters::ToValue() const { | 21 Value* EntryCreationParameters::ToValue() const { |
| 20 DictionaryValue* dict = new DictionaryValue(); | 22 DictionaryValue* dict = new DictionaryValue(); |
| 21 dict->SetString("key", key_); | 23 dict->SetString("key", key_); |
| 22 dict->SetBoolean("created", created_); | 24 dict->SetBoolean("created", created_); |
| 23 return dict; | 25 return dict; |
| 24 } | 26 } |
| 25 | 27 |
| 26 ReadWriteDataParameters::ReadWriteDataParameters( | 28 ReadWriteDataParameters::ReadWriteDataParameters( |
| 27 int index, int offset, int buf_len, bool truncate) | 29 int index, int offset, int buf_len, bool truncate) |
| 28 : index_(index), offset_(offset), buf_len_(buf_len), truncate_(truncate) { | 30 : index_(index), offset_(offset), buf_len_(buf_len), truncate_(truncate) { |
| 29 } | 31 } |
| 30 | 32 |
| 33 ReadWriteDataParameters::~ReadWriteDataParameters() {} |
| 34 |
| 31 Value* ReadWriteDataParameters::ToValue() const { | 35 Value* ReadWriteDataParameters::ToValue() const { |
| 32 DictionaryValue* dict = new DictionaryValue(); | 36 DictionaryValue* dict = new DictionaryValue(); |
| 33 dict->SetInteger("index", index_); | 37 dict->SetInteger("index", index_); |
| 34 dict->SetInteger("offset", offset_); | 38 dict->SetInteger("offset", offset_); |
| 35 dict->SetInteger("buf_len", buf_len_); | 39 dict->SetInteger("buf_len", buf_len_); |
| 36 if (truncate_) | 40 if (truncate_) |
| 37 dict->SetBoolean("truncate", truncate_); | 41 dict->SetBoolean("truncate", truncate_); |
| 38 return dict; | 42 return dict; |
| 39 } | 43 } |
| 40 | 44 |
| 41 | |
| 42 // NetLog parameters logged when non-sparse reads and writes complete. | 45 // NetLog parameters logged when non-sparse reads and writes complete. |
| 43 ReadWriteCompleteParameters::ReadWriteCompleteParameters(int bytes_copied) | 46 ReadWriteCompleteParameters::ReadWriteCompleteParameters(int bytes_copied) |
| 44 : bytes_copied_(bytes_copied) { | 47 : bytes_copied_(bytes_copied) { |
| 45 } | 48 } |
| 46 | 49 |
| 50 ReadWriteCompleteParameters::~ReadWriteCompleteParameters() {} |
| 51 |
| 47 Value* ReadWriteCompleteParameters::ToValue() const { | 52 Value* ReadWriteCompleteParameters::ToValue() const { |
| 48 DCHECK_NE(bytes_copied_, net::ERR_IO_PENDING); | 53 DCHECK_NE(bytes_copied_, net::ERR_IO_PENDING); |
| 49 DictionaryValue* dict = new DictionaryValue(); | 54 DictionaryValue* dict = new DictionaryValue(); |
| 50 if (bytes_copied_ < 0) { | 55 if (bytes_copied_ < 0) { |
| 51 dict->SetInteger("net_error", bytes_copied_); | 56 dict->SetInteger("net_error", bytes_copied_); |
| 52 } else { | 57 } else { |
| 53 dict->SetInteger("bytes_copied", bytes_copied_); | 58 dict->SetInteger("bytes_copied", bytes_copied_); |
| 54 } | 59 } |
| 55 return dict; | 60 return dict; |
| 56 } | 61 } |
| 57 | 62 |
| 58 SparseOperationParameters::SparseOperationParameters( | 63 SparseOperationParameters::SparseOperationParameters( |
| 59 int64 offset, int buff_len) | 64 int64 offset, int buff_len) |
| 60 : offset_(offset), buff_len_(buff_len) { | 65 : offset_(offset), buff_len_(buff_len) { |
| 61 } | 66 } |
| 62 | 67 |
| 68 SparseOperationParameters::~SparseOperationParameters() {} |
| 69 |
| 63 Value* SparseOperationParameters::ToValue() const { | 70 Value* SparseOperationParameters::ToValue() const { |
| 64 DictionaryValue* dict = new DictionaryValue(); | 71 DictionaryValue* dict = new DictionaryValue(); |
| 65 // Values can only be created with at most 32-bit integers. Using a string | 72 // Values can only be created with at most 32-bit integers. Using a string |
| 66 // instead circumvents that restriction. | 73 // instead circumvents that restriction. |
| 67 dict->SetString("offset", base::Int64ToString(offset_)); | 74 dict->SetString("offset", base::Int64ToString(offset_)); |
| 68 dict->SetInteger("buff_len", buff_len_); | 75 dict->SetInteger("buff_len", buff_len_); |
| 69 return dict; | 76 return dict; |
| 70 } | 77 } |
| 71 | 78 |
| 72 SparseReadWriteParameters::SparseReadWriteParameters( | 79 SparseReadWriteParameters::SparseReadWriteParameters( |
| 73 const net::NetLog::Source& source, int child_len) | 80 const net::NetLog::Source& source, int child_len) |
| 74 : source_(source), child_len_(child_len) { | 81 : source_(source), child_len_(child_len) { |
| 75 } | 82 } |
| 76 | 83 |
| 84 SparseReadWriteParameters::~SparseReadWriteParameters() {} |
| 85 |
| 77 Value* SparseReadWriteParameters::ToValue() const { | 86 Value* SparseReadWriteParameters::ToValue() const { |
| 78 DictionaryValue* dict = new DictionaryValue(); | 87 DictionaryValue* dict = new DictionaryValue(); |
| 79 dict->Set("source_dependency", source_.ToValue()); | 88 dict->Set("source_dependency", source_.ToValue()); |
| 80 dict->SetInteger("child_len", child_len_); | 89 dict->SetInteger("child_len", child_len_); |
| 81 return dict; | 90 return dict; |
| 82 } | 91 } |
| 83 | 92 |
| 84 GetAvailableRangeResultParameters::GetAvailableRangeResultParameters( | 93 GetAvailableRangeResultParameters::GetAvailableRangeResultParameters( |
| 85 int64 start, int result) | 94 int64 start, int result) |
| 86 : start_(start), result_(result) { | 95 : start_(start), result_(result) { |
| 87 } | 96 } |
| 88 | 97 |
| 98 GetAvailableRangeResultParameters::~GetAvailableRangeResultParameters() {} |
| 99 |
| 89 Value* GetAvailableRangeResultParameters::ToValue() const { | 100 Value* GetAvailableRangeResultParameters::ToValue() const { |
| 90 DictionaryValue* dict = new DictionaryValue(); | 101 DictionaryValue* dict = new DictionaryValue(); |
| 91 if (result_ > 0) { | 102 if (result_ > 0) { |
| 92 dict->SetInteger("length", result_); | 103 dict->SetInteger("length", result_); |
| 93 dict->SetString("start", base::Int64ToString(start_)); | 104 dict->SetString("start", base::Int64ToString(start_)); |
| 94 } else { | 105 } else { |
| 95 dict->SetInteger("net_error", result_); | 106 dict->SetInteger("net_error", result_); |
| 96 } | 107 } |
| 97 return dict; | 108 return dict; |
| 98 } | 109 } |
| 99 | 110 |
| 100 } // namespace disk_cache | 111 } // namespace disk_cache |
| OLD | NEW |