OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/download/download_net_log_parameters.h" | 5 #include "content/browser/download/download_net_log_parameters.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "content/browser/download/interrupt_reasons.h" | 11 #include "content/browser/download/interrupt_reasons.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 | 13 |
14 namespace download_net_logs { | 14 namespace download_net_logs { |
15 | 15 |
16 namespace { | |
17 | |
18 static const char* download_type_names[] = { | |
19 "NEW_DOWNLOAD", | |
20 "HISTORY_IMPORT", | |
21 "SAVE_PAGE_AS" | |
22 }; | |
23 static const char* download_safety_names[] = { | |
24 "SAFE", | |
25 "DANGEROUS", | |
26 "DANGEROUS_BUT_VALIDATED" | |
27 }; | |
28 | |
29 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_type_names) == SRC_SAVE_PAGE_AS + 1, | |
30 download_type_enum_has_changed); | |
31 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_safety_names) == | |
32 content::DownloadItem::DANGEROUS_BUT_VALIDATED + 1, | |
33 downloaditem_safety_state_enum_has_changed); | |
34 | |
35 } // namespace | |
36 | |
37 ItemActivatedParameters::ItemActivatedParameters( | |
38 DownloadType download_type, | |
39 int64 id, | |
40 const std::string& original_url, | |
41 const std::string& final_url, | |
42 const std::string& intermediate_name, | |
43 const std::string& suggested_name, | |
44 content::DownloadItem::SafetyState safety_state, | |
45 int64 start_offset) | |
46 : type_(download_type), | |
mmenke
2012/02/03 17:59:45
nit: Fix indent.
ahendrickson
2012/02/04 05:24:04
Done (made consistent in this file).
| |
47 id_(id), | |
48 original_url_(original_url), | |
49 final_url_(final_url), | |
50 intermediate_filename_(intermediate_name), | |
51 suggested_final_filename_(suggested_name), | |
52 safety_state_(safety_state), | |
53 start_offset_(start_offset) { | |
54 } | |
55 | |
56 ItemActivatedParameters::~ItemActivatedParameters() { | |
57 } | |
58 | |
59 Value* ItemActivatedParameters::ToValue() const { | |
60 DictionaryValue* dict = new DictionaryValue(); | |
61 | |
62 dict->SetString("type", download_type_names[type_]); | |
63 dict->SetDouble("id", id_); | |
mmenke
2012/02/03 17:59:45
Suggest you use a string instead of a double. Goe
ahendrickson
2012/02/04 05:24:04
Done.
| |
64 dict->SetString("original_url", original_url_); | |
65 dict->SetString("final_url", final_url_); | |
66 dict->SetString("intermediate_name", intermediate_filename_); | |
67 dict->SetString("suggested_name", suggested_final_filename_); | |
68 dict->SetString("safety_state", download_safety_names[safety_state_]); | |
69 dict->SetDouble("start_offset", start_offset_); | |
70 | |
71 return dict; | |
72 } | |
73 | |
74 ItemCheckedParameters::ItemCheckedParameters( | |
75 content::DownloadItem::SafetyState safety_state) | |
76 : safety_state_(safety_state) { | |
mmenke
2012/02/03 17:59:45
nit: Fix indent.
ahendrickson
2012/02/04 05:24:04
Done.
| |
77 } | |
78 | |
79 Value* ItemCheckedParameters::ToValue() const { | |
80 DictionaryValue* dict = new DictionaryValue(); | |
81 | |
82 dict->SetString("safety_state", download_safety_names[safety_state_]); | |
83 | |
84 return dict; | |
85 } | |
86 | |
87 ItemInHistoryParameters::ItemInHistoryParameters(int64 handle) | |
88 : db_handle_(handle) { | |
89 } | |
90 | |
91 Value* ItemInHistoryParameters::ToValue() const { | |
92 DictionaryValue* dict = new DictionaryValue(); | |
93 | |
94 dict->SetDouble("db_handle", db_handle_); | |
95 | |
96 return dict; | |
97 } | |
98 | |
99 ItemUpdatedParameters::ItemUpdatedParameters( | |
100 int64 bytes_so_far, const std::string& hash_state) | |
101 : bytes_so_far_(bytes_so_far), hash_state_(hash_state) { | |
102 } | |
103 | |
104 Value* ItemUpdatedParameters::ToValue() const { | |
105 DictionaryValue* dict = new DictionaryValue(); | |
106 | |
107 dict->SetDouble("bytes_so_far", bytes_so_far_); | |
108 dict->SetString("hash_state", | |
109 base::HexEncode(hash_state_.data(), hash_state_.size())); | |
110 | |
111 return dict; | |
112 } | |
113 | |
114 ItemRenamedParameters::ItemRenamedParameters( | |
115 const std::string& old_filename, const std::string& new_filename) | |
116 : old_filename_(old_filename), new_filename_(new_filename) { | |
117 } | |
118 | |
119 Value* ItemRenamedParameters::ToValue() const { | |
120 DictionaryValue* dict = new DictionaryValue(); | |
121 | |
122 dict->SetString("old_filename", old_filename_); | |
123 dict->SetString("new_filename", new_filename_); | |
124 | |
125 return dict; | |
126 } | |
127 | |
128 ItemInterruptedParameters::ItemInterruptedParameters( | |
129 InterruptReason reason, | |
130 int64 bytes_so_far, | |
131 const std::string& hash_state) | |
132 : reason_(reason), | |
133 bytes_so_far_(bytes_so_far), | |
134 hash_state_(hash_state) { | |
135 } | |
136 | |
137 Value* ItemInterruptedParameters::ToValue() const { | |
138 DictionaryValue* dict = new DictionaryValue(); | |
139 | |
140 dict->SetString("interrupt_reason", InterruptReasonDebugString(reason_)); | |
141 dict->SetDouble("bytes_so_far", bytes_so_far_); | |
142 dict->SetString("hash_state", | |
143 base::HexEncode(hash_state_.data(), hash_state_.size())); | |
144 | |
145 return dict; | |
146 } | |
147 | |
148 ItemResumedParameters::ItemResumedParameters( | |
149 bool user_initiated, | |
150 InterruptReason reason, | |
151 int64 bytes_so_far, | |
152 const std::string& hash_state) | |
153 : user_initiated_(user_initiated), | |
mmenke
2012/02/03 17:59:45
nit: Fix indent (And goes for the rest of this fi
ahendrickson
2012/02/04 05:24:04
Done.
| |
154 reason_(reason), | |
155 bytes_so_far_(bytes_so_far), | |
156 hash_state_(hash_state) { | |
157 } | |
158 | |
159 Value* ItemResumedParameters::ToValue() const { | |
160 DictionaryValue* dict = new DictionaryValue(); | |
161 | |
162 dict->SetBoolean("user_initiated", user_initiated_); | |
163 dict->SetString("interrupt_reason", InterruptReasonDebugString(reason_)); | |
164 dict->SetDouble("bytes_so_far", bytes_so_far_); | |
165 dict->SetString("hash_state", | |
166 base::HexEncode(hash_state_.data(), hash_state_.size())); | |
167 | |
168 return dict; | |
169 } | |
170 | |
171 ItemFinishedParameters::ItemFinishedParameters( | |
172 int64 bytes_so_far, | |
173 const std::string& final_hash) | |
174 : bytes_so_far_(bytes_so_far), | |
175 final_hash_(final_hash) { | |
176 } | |
177 | |
178 Value* ItemFinishedParameters::ToValue() const { | |
179 DictionaryValue* dict = new DictionaryValue(); | |
180 | |
181 dict->SetDouble("bytes_so_far", bytes_so_far_); | |
182 dict->SetString("final_hash", | |
183 base::HexEncode(final_hash_.data(), final_hash_.size())); | |
184 | |
185 return dict; | |
186 } | |
187 | |
188 ItemCanceledParameters::ItemCanceledParameters( | |
189 int64 bytes_so_far, | |
190 const std::string& hash_state) | |
191 : bytes_so_far_(bytes_so_far), | |
192 hash_state_(hash_state) { | |
193 } | |
194 | |
195 Value* ItemCanceledParameters::ToValue() const { | |
196 DictionaryValue* dict = new DictionaryValue(); | |
197 | |
198 dict->SetDouble("bytes_so_far", bytes_so_far_); | |
199 dict->SetString("hash_state", | |
200 base::HexEncode(hash_state_.data(), hash_state_.size())); | |
201 | |
202 return dict; | |
203 } | |
204 | |
16 FileOpenedParameters::FileOpenedParameters( | 205 FileOpenedParameters::FileOpenedParameters( |
17 const std::string& file_name, | 206 const std::string& file_name, |
18 int64 start_offset) | 207 int64 start_offset) |
19 : file_name_(file_name), start_offset_(start_offset) { | 208 : file_name_(file_name), start_offset_(start_offset) { |
20 } | 209 } |
21 | 210 |
22 Value* FileOpenedParameters::ToValue() const { | 211 Value* FileOpenedParameters::ToValue() const { |
23 DictionaryValue* dict = new DictionaryValue(); | 212 DictionaryValue* dict = new DictionaryValue(); |
24 | 213 |
25 dict->SetString("file_name", file_name_); | 214 dict->SetString("file_name", file_name_); |
(...skipping 24 matching lines...) Expand all Loading... | |
50 Value* FileErrorParameters::ToValue() const { | 239 Value* FileErrorParameters::ToValue() const { |
51 DictionaryValue* dict = new DictionaryValue(); | 240 DictionaryValue* dict = new DictionaryValue(); |
52 | 241 |
53 dict->SetString("operation", operation_); | 242 dict->SetString("operation", operation_); |
54 dict->SetInteger("net_error", net_error_); | 243 dict->SetInteger("net_error", net_error_); |
55 | 244 |
56 return dict; | 245 return dict; |
57 } | 246 } |
58 | 247 |
59 } // namespace download_net_logs | 248 } // namespace download_net_logs |
OLD | NEW |