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
3 // found in the LICENSE file.
5 #include "net/disk_cache/net_log_parameters.h"
7 #include "base/logging.h"
8 #include "base/string_number_conversions.h"
9 #include "base/values.h"
10 #include "net/base/net_errors.h"
12 namespace disk_cache
{
14 EntryCreationParameters::EntryCreationParameters(
15 const std::string
& key
, bool created
)
16 : key_(key
), created_(created
) {
19 Value
* EntryCreationParameters::ToValue() const {
20 DictionaryValue
* dict
= new DictionaryValue();
21 dict
->SetString("key", key_
);
22 dict
->SetBoolean("created", created_
);
26 ReadWriteDataParameters::ReadWriteDataParameters(
27 int index
, int offset
, int buf_len
, bool truncate
)
28 : index_(index
), offset_(offset
), buf_len_(buf_len
), truncate_(truncate
) {
31 Value
* ReadWriteDataParameters::ToValue() const {
32 DictionaryValue
* dict
= new DictionaryValue();
33 dict
->SetInteger("index", index_
);
34 dict
->SetInteger("offset", offset_
);
35 dict
->SetInteger("buf_len", buf_len_
);
37 dict
->SetBoolean("truncate", truncate_
);
42 // NetLog parameters logged when non-sparse reads and writes complete.
43 ReadWriteCompleteParameters::ReadWriteCompleteParameters(int bytes_copied
)
44 : bytes_copied_(bytes_copied
) {
47 Value
* ReadWriteCompleteParameters::ToValue() const {
48 DCHECK_NE(bytes_copied_
, net::ERR_IO_PENDING
);
49 DictionaryValue
* dict
= new DictionaryValue();
50 if (bytes_copied_
< 0) {
51 dict
->SetInteger("net_error", bytes_copied_
);
53 dict
->SetInteger("bytes_copied", bytes_copied_
);
58 SparseOperationParameters::SparseOperationParameters(
59 int64 offset
, int buff_len
)
60 : offset_(offset
), buff_len_(buff_len
) {
63 Value
* SparseOperationParameters::ToValue() const {
64 DictionaryValue
* dict
= new DictionaryValue();
65 // Values can only be created with at most 32-bit integers. Using a string
66 // instead circumvents that restriction.
67 dict
->SetString("offset", base::Int64ToString(offset_
));
68 dict
->SetInteger("buff_len", buff_len_
);
72 SparseReadWriteParameters::SparseReadWriteParameters(
73 const net::NetLog::Source
& source
, int child_len
)
74 : source_(source
), child_len_(child_len
) {
77 Value
* SparseReadWriteParameters::ToValue() const {
78 DictionaryValue
* dict
= new DictionaryValue();
79 dict
->Set("source_dependency", source_
.ToValue());
80 dict
->SetInteger("child_len", child_len_
);
84 GetAvailableRangeResultParameters::GetAvailableRangeResultParameters(
85 int64 start
, int result
)
86 : start_(start
), result_(result
) {
89 Value
* GetAvailableRangeResultParameters::ToValue() const {
90 DictionaryValue
* dict
= new DictionaryValue();
92 dict
->SetInteger("length", result_
);
93 dict
->SetString("start", base::Int64ToString(start_
));
95 dict
->SetInteger("net_error", result_
);
100 } // namespace disk_cache