blob: dcf18d6c16ce14195be2cd1e8e5109a44447a0ce [file] [log] [blame]
[email protected]a9813302012-04-28 09:29:281// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]9eb8cdf2011-03-17 18:53:022// 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]8cab8a82012-06-12 19:07:097#include "base/bind.h"
[email protected]9eb8cdf2011-03-17 18:53:028#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]8cab8a82012-06-12 19:07:0912#include "net/disk_cache/disk_cache.h"
[email protected]9eb8cdf2011-03-17 18:53:0213
[email protected]8cab8a82012-06-12 19:07:0914namespace {
[email protected]9eb8cdf2011-03-17 18:53:0215
[email protected]8cab8a82012-06-12 19:07:0916Value* NetLogEntryCreationCallback(const disk_cache::Entry* entry,
17 bool created,
18 net::NetLog::LogLevel /* log_level */) {
[email protected]9eb8cdf2011-03-17 18:53:0219 DictionaryValue* dict = new DictionaryValue();
[email protected]8cab8a82012-06-12 19:07:0920 dict->SetString("key", entry->GetKey());
21 dict->SetBoolean("created", created);
[email protected]9eb8cdf2011-03-17 18:53:0222 return dict;
23}
24
[email protected]8cab8a82012-06-12 19:07:0925Value* NetLogReadWriteDataCallback(int index,
26 int offset,
27 int buf_len,
28 bool truncate,
29 net::NetLog::LogLevel /* log_level */) {
[email protected]9eb8cdf2011-03-17 18:53:0230 DictionaryValue* dict = new DictionaryValue();
[email protected]8cab8a82012-06-12 19:07:0931 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]9eb8cdf2011-03-17 18:53:0236 return dict;
37}
38
[email protected]8cab8a82012-06-12 19:07:0939Value* NetLogReadWriteCompleteCallback(int bytes_copied,
40 net::NetLog::LogLevel /* log_level */) {
41 DCHECK_NE(bytes_copied, net::ERR_IO_PENDING);
[email protected]9eb8cdf2011-03-17 18:53:0242 DictionaryValue* dict = new DictionaryValue();
[email protected]8cab8a82012-06-12 19:07:0943 if (bytes_copied < 0) {
44 dict->SetInteger("net_error", bytes_copied);
[email protected]9eb8cdf2011-03-17 18:53:0245 } else {
[email protected]8cab8a82012-06-12 19:07:0946 dict->SetInteger("bytes_copied", bytes_copied);
[email protected]9eb8cdf2011-03-17 18:53:0247 }
48 return dict;
49}
50
[email protected]8cab8a82012-06-12 19:07:0951Value* NetLogSparseOperationCallback(int64 offset,
52 int buff_len,
53 net::NetLog::LogLevel /* log_level */) {
[email protected]9eb8cdf2011-03-17 18:53:0254 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]8cab8a82012-06-12 19:07:0957 dict->SetString("offset", base::Int64ToString(offset));
58 dict->SetInteger("buff_len", buff_len);
[email protected]9eb8cdf2011-03-17 18:53:0259 return dict;
60}
61
[email protected]8cab8a82012-06-12 19:07:0962Value* NetLogSparseReadWriteCallback(const net::NetLog::Source& source,
63 int child_len,
64 net::NetLog::LogLevel /* log_level */) {
[email protected]9eb8cdf2011-03-17 18:53:0265 DictionaryValue* dict = new DictionaryValue();
[email protected]8cab8a82012-06-12 19:07:0966 source.AddToEventParameters(dict);
67 dict->SetInteger("child_len", child_len);
[email protected]9eb8cdf2011-03-17 18:53:0268 return dict;
69}
70
[email protected]8cab8a82012-06-12 19:07:0971Value* NetLogGetAvailableRangeResultCallback(
[email protected]a9813302012-04-28 09:29:2872 int64 start,
[email protected]8cab8a82012-06-12 19:07:0973 int result,
74 net::NetLog::LogLevel /* log_level */) {
[email protected]9eb8cdf2011-03-17 18:53:0275 DictionaryValue* dict = new DictionaryValue();
[email protected]8cab8a82012-06-12 19:07:0976 if (result > 0) {
77 dict->SetInteger("length", result);
78 dict->SetString("start", base::Int64ToString(start));
[email protected]9eb8cdf2011-03-17 18:53:0279 } else {
[email protected]8cab8a82012-06-12 19:07:0980 dict->SetInteger("net_error", result);
[email protected]9eb8cdf2011-03-17 18:53:0281 }
82 return dict;
83}
84
[email protected]8cab8a82012-06-12 19:07:0985} // namespace
86
87namespace disk_cache {
88
89net::NetLog::ParametersCallback CreateNetLogEntryCreationCallback(
90 const Entry* entry,
91 bool created) {
92 DCHECK(entry);
93 return base::Bind(&NetLogEntryCreationCallback, entry, created);
94}
95
96net::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
105net::NetLog::ParametersCallback CreateNetLogReadWriteCompleteCallback(
106 int bytes_copied) {
107 return base::Bind(&NetLogReadWriteCompleteCallback, bytes_copied);
108}
109
110net::NetLog::ParametersCallback CreateNetLogSparseOperationCallback(
111 int64 offset,
112 int buff_len) {
113 return base::Bind(&NetLogSparseOperationCallback, offset, buff_len);
114}
115
116net::NetLog::ParametersCallback CreateNetLogSparseReadWriteCallback(
117 const net::NetLog::Source& source,
118 int child_len) {
119 return base::Bind(&NetLogSparseReadWriteCallback, source, child_len);
120}
121
122net::NetLog::ParametersCallback CreateNetLogGetAvailableRangeResultCallback(
123 int64 start,
124 int result) {
125 return base::Bind(&NetLogGetAvailableRangeResultCallback, start, result);
126}
[email protected]a9813302012-04-28 09:29:28127
[email protected]9eb8cdf2011-03-17 18:53:02128} // namespace disk_cache