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
3 // found in the LICENSE file.
5 #include "net/disk_cache/net_log_parameters.h"
8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h"
11 #include "net/base/net_errors.h"
12 #include "net/disk_cache/disk_cache.h"
16 scoped_ptr
<base::Value
> NetLogEntryCreationCallback(
17 const disk_cache::Entry
* entry
,
19 net::NetLogCaptureMode
/* capture_mode */) {
20 scoped_ptr
<base::DictionaryValue
> dict(new base::DictionaryValue());
21 dict
->SetString("key", entry
->GetKey());
22 dict
->SetBoolean("created", created
);
26 scoped_ptr
<base::Value
> NetLogReadWriteDataCallback(
31 net::NetLogCaptureMode
/* capture_mode */) {
32 scoped_ptr
<base::DictionaryValue
> dict(new base::DictionaryValue());
33 dict
->SetInteger("index", index
);
34 dict
->SetInteger("offset", offset
);
35 dict
->SetInteger("buf_len", buf_len
);
37 dict
->SetBoolean("truncate", truncate
);
41 scoped_ptr
<base::Value
> NetLogReadWriteCompleteCallback(
43 net::NetLogCaptureMode
/* capture_mode */) {
44 DCHECK_NE(bytes_copied
, net::ERR_IO_PENDING
);
45 scoped_ptr
<base::DictionaryValue
> dict(new base::DictionaryValue());
46 if (bytes_copied
< 0) {
47 dict
->SetInteger("net_error", bytes_copied
);
49 dict
->SetInteger("bytes_copied", bytes_copied
);
54 scoped_ptr
<base::Value
> NetLogSparseOperationCallback(
57 net::NetLogCaptureMode
/* capture_mode */) {
58 scoped_ptr
<base::DictionaryValue
> dict(new base::DictionaryValue());
59 // Values can only be created with at most 32-bit integers. Using a string
60 // instead circumvents that restriction.
61 dict
->SetString("offset", base::Int64ToString(offset
));
62 dict
->SetInteger("buff_len", buff_len
);
66 scoped_ptr
<base::Value
> NetLogSparseReadWriteCallback(
67 const net::NetLog::Source
& source
,
69 net::NetLogCaptureMode
/* capture_mode */) {
70 scoped_ptr
<base::DictionaryValue
> dict(new base::DictionaryValue());
71 source
.AddToEventParameters(dict
.get());
72 dict
->SetInteger("child_len", child_len
);
76 scoped_ptr
<base::Value
> NetLogGetAvailableRangeResultCallback(
79 net::NetLogCaptureMode
/* capture_mode */) {
80 scoped_ptr
<base::DictionaryValue
> dict(new base::DictionaryValue());
82 dict
->SetInteger("length", result
);
83 dict
->SetString("start", base::Int64ToString(start
));
85 dict
->SetInteger("net_error", result
);
92 namespace disk_cache
{
94 net::NetLog::ParametersCallback
CreateNetLogEntryCreationCallback(
98 return base::Bind(&NetLogEntryCreationCallback
, entry
, created
);
101 net::NetLog::ParametersCallback
CreateNetLogReadWriteDataCallback(
106 return base::Bind(&NetLogReadWriteDataCallback
,
107 index
, offset
, buf_len
, truncate
);
110 net::NetLog::ParametersCallback
CreateNetLogReadWriteCompleteCallback(
112 return base::Bind(&NetLogReadWriteCompleteCallback
, bytes_copied
);
115 net::NetLog::ParametersCallback
CreateNetLogSparseOperationCallback(
118 return base::Bind(&NetLogSparseOperationCallback
, offset
, buff_len
);
121 net::NetLog::ParametersCallback
CreateNetLogSparseReadWriteCallback(
122 const net::NetLog::Source
& source
,
124 return base::Bind(&NetLogSparseReadWriteCallback
, source
, child_len
);
127 net::NetLog::ParametersCallback
CreateNetLogGetAvailableRangeResultCallback(
130 return base::Bind(&NetLogGetAvailableRangeResultCallback
, start
, result
);
133 } // namespace disk_cache