1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/download/download_net_log_parameters.h"
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "content/public/browser/download_interrupt_reasons.h"
#include "net/base/net_errors.h"
#include "url/gurl.h"
namespace content {
namespace {
static const char* download_type_names[] = {
"NEW_DOWNLOAD",
"HISTORY_IMPORT",
"SAVE_PAGE_AS"
};
static const char* download_danger_names[] = {
"NOT_DANGEROUS",
"DANGEROUS_FILE",
"DANGEROUS_URL",
"DANGEROUS_CONTENT",
"MAYBE_DANGEROUS_CONTENT",
"UNCOMMON_CONTENT",
"USER_VALIDATED",
"DANGEROUS_HOST",
"POTENTIALLY_UNWANTED"
};
COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_type_names) == SRC_SAVE_PAGE_AS + 1,
download_type_enum_has_changed);
COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_danger_names) ==
DOWNLOAD_DANGER_TYPE_MAX,
download_danger_enum_has_changed);
} // namespace
base::Value* ItemActivatedNetLogCallback(
const DownloadItem* download_item,
DownloadType download_type,
const std::string* file_name,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("type", download_type_names[download_type]);
dict->SetString("id", base::Int64ToString(download_item->GetId()));
dict->SetString("original_url", download_item->GetOriginalUrl().spec());
dict->SetString("final_url", download_item->GetURL().spec());
dict->SetString("file_name", *file_name);
dict->SetString("danger_type",
download_danger_names[download_item->GetDangerType()]);
dict->SetString("start_offset",
base::Int64ToString(download_item->GetReceivedBytes()));
dict->SetBoolean("has_user_gesture", download_item->HasUserGesture());
return dict;
}
base::Value* ItemCheckedNetLogCallback(
DownloadDangerType danger_type,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("danger_type", download_danger_names[danger_type]);
return dict;
}
base::Value* ItemRenamedNetLogCallback(const base::FilePath* old_filename,
const base::FilePath* new_filename,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("old_filename", old_filename->AsUTF8Unsafe());
dict->SetString("new_filename", new_filename->AsUTF8Unsafe());
return dict;
}
base::Value* ItemInterruptedNetLogCallback(DownloadInterruptReason reason,
int64 bytes_so_far,
const std::string* hash_state,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason));
dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
dict->SetString("hash_state",
base::HexEncode(hash_state->data(), hash_state->size()));
return dict;
}
base::Value* ItemResumingNetLogCallback(bool user_initiated,
DownloadInterruptReason reason,
int64 bytes_so_far,
const std::string* hash_state,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("user_initiated", user_initiated ? "true" : "false");
dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason));
dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
dict->SetString("hash_state",
base::HexEncode(hash_state->data(), hash_state->size()));
return dict;
}
base::Value* ItemCompletingNetLogCallback(int64 bytes_so_far,
const std::string* final_hash,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
dict->SetString("final_hash",
base::HexEncode(final_hash->data(), final_hash->size()));
return dict;
}
base::Value* ItemFinishedNetLogCallback(bool auto_opened,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("auto_opened", auto_opened ? "yes" : "no");
return dict;
}
base::Value* ItemCanceledNetLogCallback(int64 bytes_so_far,
const std::string* hash_state,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
dict->SetString("hash_state",
base::HexEncode(hash_state->data(), hash_state->size()));
return dict;
}
base::Value* FileOpenedNetLogCallback(const base::FilePath* file_name,
int64 start_offset,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("file_name", file_name->AsUTF8Unsafe());
dict->SetString("start_offset", base::Int64ToString(start_offset));
return dict;
}
base::Value* FileStreamDrainedNetLogCallback(size_t stream_size,
size_t num_buffers,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetInteger("stream_size", static_cast<int>(stream_size));
dict->SetInteger("num_buffers", static_cast<int>(num_buffers));
return dict;
}
base::Value* FileRenamedNetLogCallback(const base::FilePath* old_filename,
const base::FilePath* new_filename,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("old_filename", old_filename->AsUTF8Unsafe());
dict->SetString("new_filename", new_filename->AsUTF8Unsafe());
return dict;
}
base::Value* FileErrorNetLogCallback(const char* operation,
net::Error net_error,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("operation", operation);
dict->SetInteger("net_error", net_error);
return dict;
}
base::Value* FileInterruptedNetLogCallback(const char* operation,
int os_error,
DownloadInterruptReason reason,
net::NetLog::LogLevel log_level) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("operation", operation);
if (os_error != 0)
dict->SetInteger("os_error", os_error);
dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason));
return dict;
}
} // namespace content
|