Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / download / download_net_log_parameters.cc
blob8d04ae1d1feb4dd7adc76723e375c303337336fc
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 "content/browser/download/download_net_log_parameters.h"
7 #include "base/basictypes.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/values.h"
12 #include "content/public/browser/download_interrupt_reasons.h"
13 #include "net/base/net_errors.h"
14 #include "url/gurl.h"
16 namespace content {
18 namespace {
20 static const char* download_type_names[] = {
21 "NEW_DOWNLOAD",
22 "HISTORY_IMPORT",
23 "SAVE_PAGE_AS"
25 static const char* download_danger_names[] = {
26 "NOT_DANGEROUS",
27 "DANGEROUS_FILE",
28 "DANGEROUS_URL",
29 "DANGEROUS_CONTENT",
30 "MAYBE_DANGEROUS_CONTENT",
31 "UNCOMMON_CONTENT",
32 "USER_VALIDATED",
33 "DANGEROUS_HOST",
34 "POTENTIALLY_UNWANTED"
37 static_assert(arraysize(download_type_names) == SRC_SAVE_PAGE_AS + 1,
38 "download type enum has changed");
39 static_assert(arraysize(download_danger_names) == DOWNLOAD_DANGER_TYPE_MAX,
40 "download danger enum has changed");
42 } // namespace
44 base::Value* ItemActivatedNetLogCallback(const DownloadItem* download_item,
45 DownloadType download_type,
46 const std::string* file_name,
47 net::NetLogCaptureMode capture_mode) {
48 base::DictionaryValue* dict = new base::DictionaryValue();
50 dict->SetString("type", download_type_names[download_type]);
51 dict->SetString("id", base::Int64ToString(download_item->GetId()));
52 dict->SetString("original_url", download_item->GetOriginalUrl().spec());
53 dict->SetString("final_url", download_item->GetURL().spec());
54 dict->SetString("file_name", *file_name);
55 dict->SetString("danger_type",
56 download_danger_names[download_item->GetDangerType()]);
57 dict->SetString("start_offset",
58 base::Int64ToString(download_item->GetReceivedBytes()));
59 dict->SetBoolean("has_user_gesture", download_item->HasUserGesture());
61 return dict;
64 base::Value* ItemCheckedNetLogCallback(DownloadDangerType danger_type,
65 net::NetLogCaptureMode capture_mode) {
66 base::DictionaryValue* dict = new base::DictionaryValue();
68 dict->SetString("danger_type", download_danger_names[danger_type]);
70 return dict;
73 base::Value* ItemRenamedNetLogCallback(const base::FilePath* old_filename,
74 const base::FilePath* new_filename,
75 net::NetLogCaptureMode capture_mode) {
76 base::DictionaryValue* dict = new base::DictionaryValue();
78 dict->SetString("old_filename", old_filename->AsUTF8Unsafe());
79 dict->SetString("new_filename", new_filename->AsUTF8Unsafe());
81 return dict;
84 base::Value* ItemInterruptedNetLogCallback(
85 DownloadInterruptReason reason,
86 int64 bytes_so_far,
87 const std::string* hash_state,
88 net::NetLogCaptureMode capture_mode) {
89 base::DictionaryValue* dict = new base::DictionaryValue();
91 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason));
92 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
93 dict->SetString("hash_state",
94 base::HexEncode(hash_state->data(), hash_state->size()));
96 return dict;
99 base::Value* ItemResumingNetLogCallback(bool user_initiated,
100 DownloadInterruptReason reason,
101 int64 bytes_so_far,
102 const std::string* hash_state,
103 net::NetLogCaptureMode capture_mode) {
104 base::DictionaryValue* dict = new base::DictionaryValue();
106 dict->SetString("user_initiated", user_initiated ? "true" : "false");
107 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason));
108 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
109 dict->SetString("hash_state",
110 base::HexEncode(hash_state->data(), hash_state->size()));
112 return dict;
115 base::Value* ItemCompletingNetLogCallback(int64 bytes_so_far,
116 const std::string* final_hash,
117 net::NetLogCaptureMode capture_mode) {
118 base::DictionaryValue* dict = new base::DictionaryValue();
120 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
121 dict->SetString("final_hash",
122 base::HexEncode(final_hash->data(), final_hash->size()));
124 return dict;
127 base::Value* ItemFinishedNetLogCallback(bool auto_opened,
128 net::NetLogCaptureMode capture_mode) {
129 base::DictionaryValue* dict = new base::DictionaryValue();
131 dict->SetString("auto_opened", auto_opened ? "yes" : "no");
133 return dict;
136 base::Value* ItemCanceledNetLogCallback(int64 bytes_so_far,
137 const std::string* hash_state,
138 net::NetLogCaptureMode capture_mode) {
139 base::DictionaryValue* dict = new base::DictionaryValue();
141 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
142 dict->SetString("hash_state",
143 base::HexEncode(hash_state->data(), hash_state->size()));
145 return dict;
148 base::Value* FileOpenedNetLogCallback(const base::FilePath* file_name,
149 int64 start_offset,
150 net::NetLogCaptureMode capture_mode) {
151 base::DictionaryValue* dict = new base::DictionaryValue();
153 dict->SetString("file_name", file_name->AsUTF8Unsafe());
154 dict->SetString("start_offset", base::Int64ToString(start_offset));
156 return dict;
159 base::Value* FileStreamDrainedNetLogCallback(
160 size_t stream_size,
161 size_t num_buffers,
162 net::NetLogCaptureMode capture_mode) {
163 base::DictionaryValue* dict = new base::DictionaryValue();
165 dict->SetInteger("stream_size", static_cast<int>(stream_size));
166 dict->SetInteger("num_buffers", static_cast<int>(num_buffers));
168 return dict;
171 base::Value* FileRenamedNetLogCallback(const base::FilePath* old_filename,
172 const base::FilePath* new_filename,
173 net::NetLogCaptureMode capture_mode) {
174 base::DictionaryValue* dict = new base::DictionaryValue();
176 dict->SetString("old_filename", old_filename->AsUTF8Unsafe());
177 dict->SetString("new_filename", new_filename->AsUTF8Unsafe());
179 return dict;
182 base::Value* FileErrorNetLogCallback(const char* operation,
183 net::Error net_error,
184 net::NetLogCaptureMode capture_mode) {
185 base::DictionaryValue* dict = new base::DictionaryValue();
187 dict->SetString("operation", operation);
188 dict->SetInteger("net_error", net_error);
190 return dict;
193 base::Value* FileInterruptedNetLogCallback(
194 const char* operation,
195 int os_error,
196 DownloadInterruptReason reason,
197 net::NetLogCaptureMode capture_mode) {
198 base::DictionaryValue* dict = new base::DictionaryValue();
200 dict->SetString("operation", operation);
201 if (os_error != 0)
202 dict->SetInteger("os_error", os_error);
203 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason));
205 return dict;
208 } // namespace content