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 static const char* download_danger_names[] = { |
| 29 "NOT_DANGEROUS", |
| 30 "DANGEROUS_FILE", |
| 31 "DANGEROUS_URL", |
| 32 "DANGEROUS_CONTENT", |
| 33 "MAYBE_DANGEROUS_CONTENT" |
| 34 }; |
| 35 |
| 36 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_type_names) == SRC_SAVE_PAGE_AS + 1, |
| 37 download_type_enum_has_changed); |
| 38 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_safety_names) == |
| 39 content::DownloadItem::DANGEROUS_BUT_VALIDATED + 1, |
| 40 downloaditem_safety_state_enum_has_changed); |
| 41 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(download_danger_names) == |
| 42 content::DOWNLOAD_DANGER_TYPE_MAX, |
| 43 download_danger_enum_has_changed); |
| 44 |
| 45 } // namespace |
| 46 |
| 47 ItemActivatedParameters::ItemActivatedParameters( |
| 48 DownloadType download_type, |
| 49 int64 id, |
| 50 const std::string& original_url, |
| 51 const std::string& final_url, |
| 52 const std::string& file_name, |
| 53 content::DownloadDangerType danger_type, |
| 54 content::DownloadItem::SafetyState safety_state, |
| 55 int64 start_offset) |
| 56 : type_(download_type), |
| 57 id_(id), |
| 58 original_url_(original_url), |
| 59 final_url_(final_url), |
| 60 file_name_(file_name), |
| 61 danger_type_(danger_type), |
| 62 safety_state_(safety_state), |
| 63 start_offset_(start_offset) { |
| 64 } |
| 65 |
| 66 ItemActivatedParameters::~ItemActivatedParameters() { |
| 67 } |
| 68 |
| 69 Value* ItemActivatedParameters::ToValue() const { |
| 70 DictionaryValue* dict = new DictionaryValue(); |
| 71 |
| 72 dict->SetString("type", download_type_names[type_]); |
| 73 dict->SetString("id", base::Int64ToString(id_)); |
| 74 dict->SetString("original_url", original_url_); |
| 75 dict->SetString("final_url", final_url_); |
| 76 dict->SetString("file_name", file_name_); |
| 77 dict->SetString("danger_type", download_danger_names[danger_type_]); |
| 78 dict->SetString("safety_state", download_safety_names[safety_state_]); |
| 79 dict->SetString("start_offset", base::Int64ToString(start_offset_)); |
| 80 |
| 81 return dict; |
| 82 } |
| 83 |
| 84 ItemCheckedParameters::ItemCheckedParameters( |
| 85 content::DownloadDangerType danger_type, |
| 86 content::DownloadItem::SafetyState safety_state) |
| 87 : danger_type_(danger_type), safety_state_(safety_state) { |
| 88 } |
| 89 |
| 90 Value* ItemCheckedParameters::ToValue() const { |
| 91 DictionaryValue* dict = new DictionaryValue(); |
| 92 |
| 93 dict->SetString("danger_type", download_danger_names[danger_type_]); |
| 94 dict->SetString("safety_state", download_safety_names[safety_state_]); |
| 95 |
| 96 return dict; |
| 97 } |
| 98 |
| 99 ItemInHistoryParameters::ItemInHistoryParameters(int64 handle) |
| 100 : db_handle_(handle) { |
| 101 } |
| 102 |
| 103 Value* ItemInHistoryParameters::ToValue() const { |
| 104 DictionaryValue* dict = new DictionaryValue(); |
| 105 |
| 106 dict->SetString("db_handle", base::Int64ToString(db_handle_)); |
| 107 |
| 108 return dict; |
| 109 } |
| 110 |
| 111 ItemUpdatedParameters::ItemUpdatedParameters(int64 bytes_so_far) |
| 112 : bytes_so_far_(bytes_so_far) { |
| 113 } |
| 114 |
| 115 Value* ItemUpdatedParameters::ToValue() const { |
| 116 DictionaryValue* dict = new DictionaryValue(); |
| 117 |
| 118 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); |
| 119 |
| 120 return dict; |
| 121 } |
| 122 |
| 123 ItemRenamedParameters::ItemRenamedParameters( |
| 124 const std::string& old_filename, const std::string& new_filename) |
| 125 : old_filename_(old_filename), new_filename_(new_filename) { |
| 126 } |
| 127 |
| 128 Value* ItemRenamedParameters::ToValue() const { |
| 129 DictionaryValue* dict = new DictionaryValue(); |
| 130 |
| 131 dict->SetString("old_filename", old_filename_); |
| 132 dict->SetString("new_filename", new_filename_); |
| 133 |
| 134 return dict; |
| 135 } |
| 136 |
| 137 ItemInterruptedParameters::ItemInterruptedParameters( |
| 138 InterruptReason reason, |
| 139 int64 bytes_so_far, |
| 140 const std::string& hash_state) |
| 141 : reason_(reason), |
| 142 bytes_so_far_(bytes_so_far), |
| 143 hash_state_(hash_state) { |
| 144 } |
| 145 |
| 146 Value* ItemInterruptedParameters::ToValue() const { |
| 147 DictionaryValue* dict = new DictionaryValue(); |
| 148 |
| 149 dict->SetString("interrupt_reason", InterruptReasonDebugString(reason_)); |
| 150 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); |
| 151 dict->SetString("hash_state", |
| 152 base::HexEncode(hash_state_.data(), hash_state_.size())); |
| 153 |
| 154 return dict; |
| 155 } |
| 156 |
| 157 ItemFinishedParameters::ItemFinishedParameters( |
| 158 int64 bytes_so_far, |
| 159 const std::string& final_hash) |
| 160 : bytes_so_far_(bytes_so_far), |
| 161 final_hash_(final_hash) { |
| 162 } |
| 163 |
| 164 Value* ItemFinishedParameters::ToValue() const { |
| 165 DictionaryValue* dict = new DictionaryValue(); |
| 166 |
| 167 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); |
| 168 dict->SetString("final_hash", |
| 169 base::HexEncode(final_hash_.data(), final_hash_.size())); |
| 170 |
| 171 return dict; |
| 172 } |
| 173 |
| 174 ItemCanceledParameters::ItemCanceledParameters( |
| 175 int64 bytes_so_far, |
| 176 const std::string& hash_state) |
| 177 : bytes_so_far_(bytes_so_far), |
| 178 hash_state_(hash_state) { |
| 179 } |
| 180 |
| 181 Value* ItemCanceledParameters::ToValue() const { |
| 182 DictionaryValue* dict = new DictionaryValue(); |
| 183 |
| 184 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); |
| 185 dict->SetString("hash_state", |
| 186 base::HexEncode(hash_state_.data(), hash_state_.size())); |
| 187 |
| 188 return dict; |
| 189 } |
| 190 |
16 FileOpenedParameters::FileOpenedParameters(const std::string& file_name, | 191 FileOpenedParameters::FileOpenedParameters(const std::string& file_name, |
17 int64 start_offset) | 192 int64 start_offset) |
18 : file_name_(file_name), start_offset_(start_offset) { | 193 : file_name_(file_name), start_offset_(start_offset) { |
19 } | 194 } |
20 | 195 |
21 Value* FileOpenedParameters::ToValue() const { | 196 Value* FileOpenedParameters::ToValue() const { |
22 DictionaryValue* dict = new DictionaryValue(); | 197 DictionaryValue* dict = new DictionaryValue(); |
23 | 198 |
24 dict->SetString("file_name", file_name_); | 199 dict->SetString("file_name", file_name_); |
25 dict->SetString("start_offset", base::Int64ToString(start_offset_)); | 200 dict->SetString("start_offset", base::Int64ToString(start_offset_)); |
(...skipping 23 matching lines...) Expand all Loading... |
49 Value* FileErrorParameters::ToValue() const { | 224 Value* FileErrorParameters::ToValue() const { |
50 DictionaryValue* dict = new DictionaryValue(); | 225 DictionaryValue* dict = new DictionaryValue(); |
51 | 226 |
52 dict->SetString("operation", operation_); | 227 dict->SetString("operation", operation_); |
53 dict->SetInteger("net_error", net_error_); | 228 dict->SetInteger("net_error", net_error_); |
54 | 229 |
55 return dict; | 230 return dict; |
56 } | 231 } |
57 | 232 |
58 } // namespace download_net_logs | 233 } // namespace download_net_logs |
OLD | NEW |