| 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/file_path.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "content/public/browser/download_interrupt_reasons.h" | 12 #include "content/public/browser/download_interrupt_reasons.h" |
| 13 #include "googleurl/src/gurl.h" |
| 12 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 13 | 15 |
| 14 namespace download_net_logs { | 16 namespace download_net_logs { |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 static const char* download_type_names[] = { | 20 static const char* download_type_names[] = { |
| 19 "NEW_DOWNLOAD", | 21 "NEW_DOWNLOAD", |
| 20 "HISTORY_IMPORT", | 22 "HISTORY_IMPORT", |
| 21 "SAVE_PAGE_AS" | 23 "SAVE_PAGE_AS" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 38 download_type_enum_has_changed); | 40 download_type_enum_has_changed); |
| 39 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_safety_names) == | 41 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_safety_names) == |
| 40 content::DownloadItem::DANGEROUS_BUT_VALIDATED + 1, | 42 content::DownloadItem::DANGEROUS_BUT_VALIDATED + 1, |
| 41 downloaditem_safety_state_enum_has_changed); | 43 downloaditem_safety_state_enum_has_changed); |
| 42 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_danger_names) == | 44 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_danger_names) == |
| 43 content::DOWNLOAD_DANGER_TYPE_MAX, | 45 content::DOWNLOAD_DANGER_TYPE_MAX, |
| 44 download_danger_enum_has_changed); | 46 download_danger_enum_has_changed); |
| 45 | 47 |
| 46 } // namespace | 48 } // namespace |
| 47 | 49 |
| 48 ItemActivatedParameters::ItemActivatedParameters( | 50 base::Value* ItemActivatedCallback( |
| 51 const content::DownloadItem* download_item, |
| 49 DownloadType download_type, | 52 DownloadType download_type, |
| 50 int64 id, | 53 const std::string* file_name, |
| 51 const std::string& original_url, | 54 net::NetLog::LogLevel /* log_level */) { |
| 52 const std::string& final_url, | |
| 53 const std::string& file_name, | |
| 54 content::DownloadDangerType danger_type, | |
| 55 content::DownloadItem::SafetyState safety_state, | |
| 56 int64 start_offset) | |
| 57 : type_(download_type), | |
| 58 id_(id), | |
| 59 original_url_(original_url), | |
| 60 final_url_(final_url), | |
| 61 file_name_(file_name), | |
| 62 danger_type_(danger_type), | |
| 63 safety_state_(safety_state), | |
| 64 start_offset_(start_offset) { | |
| 65 } | |
| 66 | |
| 67 Value* ItemActivatedParameters::ToValue() const { | |
| 68 DictionaryValue* dict = new DictionaryValue(); | 55 DictionaryValue* dict = new DictionaryValue(); |
| 69 | 56 |
| 70 dict->SetString("type", download_type_names[type_]); | 57 dict->SetString("type", download_type_names[download_type]); |
| 71 dict->SetString("id", base::Int64ToString(id_)); | 58 dict->SetString("id", base::Int64ToString(download_item->GetId())); |
| 72 dict->SetString("original_url", original_url_); | 59 dict->SetString("original_url", download_item->GetOriginalUrl().spec()); |
| 73 dict->SetString("final_url", final_url_); | 60 dict->SetString("final_url", download_item->GetURL().spec()); |
| 74 dict->SetString("file_name", file_name_); | 61 dict->SetString("file_name", *file_name); |
| 75 dict->SetString("danger_type", download_danger_names[danger_type_]); | 62 dict->SetString("danger_type", |
| 76 dict->SetString("safety_state", download_safety_names[safety_state_]); | 63 download_danger_names[download_item->GetDangerType()]); |
| 77 dict->SetString("start_offset", base::Int64ToString(start_offset_)); | 64 dict->SetString("safety_state", |
| 65 download_safety_names[download_item->GetSafetyState()]); |
| 66 dict->SetString("start_offset", |
| 67 base::Int64ToString(download_item->GetReceivedBytes())); |
| 78 | 68 |
| 79 return dict; | 69 return dict; |
| 80 } | 70 } |
| 81 | 71 |
| 82 ItemActivatedParameters::~ItemActivatedParameters() {} | 72 base::Value* ItemCheckedCallback( |
| 83 | |
| 84 ItemCheckedParameters::ItemCheckedParameters( | |
| 85 content::DownloadDangerType danger_type, | 73 content::DownloadDangerType danger_type, |
| 86 content::DownloadItem::SafetyState safety_state) | 74 content::DownloadItem::SafetyState safety_state, |
| 87 : danger_type_(danger_type), safety_state_(safety_state) { | 75 net::NetLog::LogLevel /* log_level */) { |
| 88 } | |
| 89 | |
| 90 Value* ItemCheckedParameters::ToValue() const { | |
| 91 DictionaryValue* dict = new DictionaryValue(); | 76 DictionaryValue* dict = new DictionaryValue(); |
| 92 | 77 |
| 93 dict->SetString("danger_type", download_danger_names[danger_type_]); | 78 dict->SetString("danger_type", download_danger_names[danger_type]); |
| 94 dict->SetString("safety_state", download_safety_names[safety_state_]); | 79 dict->SetString("safety_state", download_safety_names[safety_state]); |
| 95 | 80 |
| 96 return dict; | 81 return dict; |
| 97 } | 82 } |
| 98 | 83 |
| 99 ItemCheckedParameters::~ItemCheckedParameters() {} | 84 base::Value* ItemRenamedCallback(const FilePath* old_filename, |
| 100 | 85 const FilePath* new_filename, |
| 101 ItemInHistoryParameters::ItemInHistoryParameters(int64 handle) | 86 net::NetLog::LogLevel /* log_level */) { |
| 102 : db_handle_(handle) { | |
| 103 } | |
| 104 | |
| 105 Value* ItemInHistoryParameters::ToValue() const { | |
| 106 DictionaryValue* dict = new DictionaryValue(); | 87 DictionaryValue* dict = new DictionaryValue(); |
| 107 | 88 |
| 108 dict->SetString("db_handle", base::Int64ToString(db_handle_)); | 89 dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); |
| 90 dict->SetString("new_filename", new_filename->AsUTF8Unsafe()); |
| 109 | 91 |
| 110 return dict; | 92 return dict; |
| 111 } | 93 } |
| 112 | 94 |
| 113 ItemInHistoryParameters::~ItemInHistoryParameters() {} | 95 base::Value* ItemInterruptedCallback(content::DownloadInterruptReason reason, |
| 114 | 96 int64 bytes_so_far, |
| 115 ItemUpdatedParameters::ItemUpdatedParameters(int64 bytes_so_far) | 97 const std::string* hash_state, |
| 116 : bytes_so_far_(bytes_so_far) { | 98 net::NetLog::LogLevel /* log_level */) { |
| 117 } | |
| 118 | |
| 119 Value* ItemUpdatedParameters::ToValue() const { | |
| 120 DictionaryValue* dict = new DictionaryValue(); | 99 DictionaryValue* dict = new DictionaryValue(); |
| 121 | 100 |
| 122 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); | 101 dict->SetString("interrupt_reason", InterruptReasonDebugString(reason)); |
| 102 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); |
| 103 dict->SetString("hash_state", |
| 104 base::HexEncode(hash_state->data(), hash_state->size())); |
| 123 | 105 |
| 124 return dict; | 106 return dict; |
| 125 } | 107 } |
| 126 | 108 |
| 127 ItemUpdatedParameters::~ItemUpdatedParameters() {} | 109 base::Value* ItemFinishedCallback(int64 bytes_so_far, |
| 128 | 110 const std::string* final_hash, |
| 129 ItemRenamedParameters::ItemRenamedParameters( | 111 net::NetLog::LogLevel /* log_level */) { |
| 130 const std::string& old_filename, const std::string& new_filename) | |
| 131 : old_filename_(old_filename), new_filename_(new_filename) { | |
| 132 } | |
| 133 | |
| 134 Value* ItemRenamedParameters::ToValue() const { | |
| 135 DictionaryValue* dict = new DictionaryValue(); | 112 DictionaryValue* dict = new DictionaryValue(); |
| 136 | 113 |
| 137 dict->SetString("old_filename", old_filename_); | 114 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); |
| 138 dict->SetString("new_filename", new_filename_); | 115 dict->SetString("final_hash", |
| 116 base::HexEncode(final_hash->data(), final_hash->size())); |
| 139 | 117 |
| 140 return dict; | 118 return dict; |
| 141 } | 119 } |
| 142 | 120 |
| 143 ItemRenamedParameters::~ItemRenamedParameters() {} | 121 base::Value* ItemCanceledCallback(int64 bytes_so_far, |
| 144 | 122 const std::string* hash_state, |
| 145 ItemInterruptedParameters::ItemInterruptedParameters( | 123 net::NetLog::LogLevel /* log_level */) { |
| 146 content::DownloadInterruptReason reason, | |
| 147 int64 bytes_so_far, | |
| 148 const std::string& hash_state) | |
| 149 : reason_(reason), | |
| 150 bytes_so_far_(bytes_so_far), | |
| 151 hash_state_(hash_state) { | |
| 152 } | |
| 153 | |
| 154 Value* ItemInterruptedParameters::ToValue() const { | |
| 155 DictionaryValue* dict = new DictionaryValue(); | 124 DictionaryValue* dict = new DictionaryValue(); |
| 156 | 125 |
| 157 dict->SetString("interrupt_reason", InterruptReasonDebugString(reason_)); | 126 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); |
| 158 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); | |
| 159 dict->SetString("hash_state", | 127 dict->SetString("hash_state", |
| 160 base::HexEncode(hash_state_.data(), hash_state_.size())); | 128 base::HexEncode(hash_state->data(), hash_state->size())); |
| 161 | 129 |
| 162 return dict; | 130 return dict; |
| 163 } | 131 } |
| 164 | 132 |
| 165 ItemInterruptedParameters::~ItemInterruptedParameters() {} | 133 base::Value* FileOpenedCallback(const FilePath* file_name, |
| 166 | 134 int64 start_offset, |
| 167 ItemFinishedParameters::ItemFinishedParameters( | 135 net::NetLog::LogLevel /* log_level */) { |
| 168 int64 bytes_so_far, | |
| 169 const std::string& final_hash) | |
| 170 : bytes_so_far_(bytes_so_far), | |
| 171 final_hash_(final_hash) { | |
| 172 } | |
| 173 | |
| 174 Value* ItemFinishedParameters::ToValue() const { | |
| 175 DictionaryValue* dict = new DictionaryValue(); | 136 DictionaryValue* dict = new DictionaryValue(); |
| 176 | 137 |
| 177 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); | 138 dict->SetString("file_name", file_name->AsUTF8Unsafe()); |
| 178 dict->SetString("final_hash", | 139 dict->SetString("start_offset", base::Int64ToString(start_offset)); |
| 179 base::HexEncode(final_hash_.data(), final_hash_.size())); | |
| 180 | 140 |
| 181 return dict; | 141 return dict; |
| 182 } | 142 } |
| 183 | 143 |
| 184 ItemFinishedParameters::~ItemFinishedParameters() {} | 144 base::Value* FileStreamDrainedCallback(size_t stream_size, |
| 185 | 145 size_t num_buffers, |
| 186 ItemCanceledParameters::ItemCanceledParameters( | 146 net::NetLog::LogLevel /* log_level */) { |
| 187 int64 bytes_so_far, | |
| 188 const std::string& hash_state) | |
| 189 : bytes_so_far_(bytes_so_far), | |
| 190 hash_state_(hash_state) { | |
| 191 } | |
| 192 | |
| 193 Value* ItemCanceledParameters::ToValue() const { | |
| 194 DictionaryValue* dict = new DictionaryValue(); | 147 DictionaryValue* dict = new DictionaryValue(); |
| 195 | 148 |
| 196 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); | 149 dict->SetInteger("stream_size", static_cast<int>(stream_size)); |
| 197 dict->SetString("hash_state", | 150 dict->SetInteger("num_buffers", static_cast<int>(num_buffers)); |
| 198 base::HexEncode(hash_state_.data(), hash_state_.size())); | |
| 199 | 151 |
| 200 return dict; | 152 return dict; |
| 201 } | 153 } |
| 202 | 154 |
| 203 ItemCanceledParameters::~ItemCanceledParameters() {} | 155 base::Value* FileRenamedCallback(const FilePath* old_filename, |
| 204 | 156 const FilePath* new_filename, |
| 205 FileOpenedParameters::FileOpenedParameters(const std::string& file_name, | 157 net::NetLog::LogLevel /* log_level */) { |
| 206 int64 start_offset) | |
| 207 : file_name_(file_name), start_offset_(start_offset) { | |
| 208 } | |
| 209 | |
| 210 Value* FileOpenedParameters::ToValue() const { | |
| 211 DictionaryValue* dict = new DictionaryValue(); | 158 DictionaryValue* dict = new DictionaryValue(); |
| 212 | 159 |
| 213 dict->SetString("file_name", file_name_); | 160 dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); |
| 214 dict->SetString("start_offset", base::Int64ToString(start_offset_)); | 161 dict->SetString("new_filename", new_filename->AsUTF8Unsafe()); |
| 215 | 162 |
| 216 return dict; | 163 return dict; |
| 217 } | 164 } |
| 218 | 165 |
| 219 FileOpenedParameters::~FileOpenedParameters() {} | 166 base::Value* FileErrorCallback(const char* operation, |
| 220 | 167 net::Error net_error, |
| 221 FileStreamDrainedParameters::FileStreamDrainedParameters( | 168 net::NetLog::LogLevel /* log_level */) { |
| 222 size_t stream_size, size_t num_buffers) | |
| 223 : stream_size_(stream_size), num_buffers_(num_buffers) { | |
| 224 } | |
| 225 | |
| 226 Value* FileStreamDrainedParameters::ToValue() const { | |
| 227 DictionaryValue* dict = new DictionaryValue(); | 169 DictionaryValue* dict = new DictionaryValue(); |
| 228 | 170 |
| 229 dict->SetInteger("stream_size", static_cast<int>(stream_size_)); | 171 dict->SetString("operation", operation); |
| 230 dict->SetInteger("num_buffers", static_cast<int>(num_buffers_)); | 172 dict->SetInteger("net_error", net_error); |
| 231 | 173 |
| 232 return dict; | 174 return dict; |
| 233 } | 175 } |
| 234 | 176 |
| 235 FileStreamDrainedParameters::~FileStreamDrainedParameters() { } | |
| 236 | |
| 237 FileRenamedParameters::FileRenamedParameters( | |
| 238 const std::string& old_filename, const std::string& new_filename) | |
| 239 : old_filename_(old_filename), new_filename_(new_filename) { | |
| 240 } | |
| 241 | |
| 242 Value* FileRenamedParameters::ToValue() const { | |
| 243 DictionaryValue* dict = new DictionaryValue(); | |
| 244 | |
| 245 dict->SetString("old_filename", old_filename_); | |
| 246 dict->SetString("new_filename", new_filename_); | |
| 247 | |
| 248 return dict; | |
| 249 } | |
| 250 | |
| 251 FileRenamedParameters::~FileRenamedParameters() {} | |
| 252 | |
| 253 FileErrorParameters::FileErrorParameters(const std::string& operation, | |
| 254 net::Error net_error) | |
| 255 : operation_(operation), net_error_(net_error) { | |
| 256 } | |
| 257 | |
| 258 Value* FileErrorParameters::ToValue() const { | |
| 259 DictionaryValue* dict = new DictionaryValue(); | |
| 260 | |
| 261 dict->SetString("operation", operation_); | |
| 262 dict->SetInteger("net_error", net_error_); | |
| 263 | |
| 264 return dict; | |
| 265 } | |
| 266 | |
| 267 FileErrorParameters::~FileErrorParameters() {} | |
| 268 | |
| 269 } // namespace download_net_logs | 177 } // namespace download_net_logs |
| OLD | NEW |