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& file_name, |
| 43 content::DownloadItem::SafetyState safety_state, |
| 44 int64 start_offset) |
| 45 : type_(download_type), |
| 46 id_(id), |
| 47 original_url_(original_url), |
| 48 final_url_(final_url), |
| 49 file_name_(file_name), |
| 50 safety_state_(safety_state), |
| 51 start_offset_(start_offset) { |
| 52 } |
| 53 |
| 54 ItemActivatedParameters::~ItemActivatedParameters() { |
| 55 } |
| 56 |
| 57 Value* ItemActivatedParameters::ToValue() const { |
| 58 DictionaryValue* dict = new DictionaryValue(); |
| 59 |
| 60 dict->SetString("type", download_type_names[type_]); |
| 61 dict->SetString("id", base::Int64ToString(id_)); |
| 62 dict->SetString("original_url", original_url_); |
| 63 dict->SetString("final_url", final_url_); |
| 64 dict->SetString("file_name", file_name_); |
| 65 dict->SetString("safety_state", download_safety_names[safety_state_]); |
| 66 dict->SetString("start_offset", base::Int64ToString(start_offset_)); |
| 67 |
| 68 return dict; |
| 69 } |
| 70 |
| 71 ItemCheckedParameters::ItemCheckedParameters( |
| 72 content::DownloadItem::SafetyState safety_state) |
| 73 : safety_state_(safety_state) { |
| 74 } |
| 75 |
| 76 Value* ItemCheckedParameters::ToValue() const { |
| 77 DictionaryValue* dict = new DictionaryValue(); |
| 78 |
| 79 dict->SetString("safety_state", download_safety_names[safety_state_]); |
| 80 |
| 81 return dict; |
| 82 } |
| 83 |
| 84 ItemInHistoryParameters::ItemInHistoryParameters(int64 handle) |
| 85 : db_handle_(handle) { |
| 86 } |
| 87 |
| 88 Value* ItemInHistoryParameters::ToValue() const { |
| 89 DictionaryValue* dict = new DictionaryValue(); |
| 90 |
| 91 dict->SetString("db_handle", base::Int64ToString(db_handle_)); |
| 92 |
| 93 return dict; |
| 94 } |
| 95 |
| 96 ItemUpdatedParameters::ItemUpdatedParameters(int64 bytes_so_far) |
| 97 : bytes_so_far_(bytes_so_far) { |
| 98 } |
| 99 |
| 100 Value* ItemUpdatedParameters::ToValue() const { |
| 101 DictionaryValue* dict = new DictionaryValue(); |
| 102 |
| 103 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); |
| 104 |
| 105 return dict; |
| 106 } |
| 107 |
| 108 ItemRenamedParameters::ItemRenamedParameters( |
| 109 const std::string& old_filename, const std::string& new_filename) |
| 110 : old_filename_(old_filename), new_filename_(new_filename) { |
| 111 } |
| 112 |
| 113 Value* ItemRenamedParameters::ToValue() const { |
| 114 DictionaryValue* dict = new DictionaryValue(); |
| 115 |
| 116 dict->SetString("old_filename", old_filename_); |
| 117 dict->SetString("new_filename", new_filename_); |
| 118 |
| 119 return dict; |
| 120 } |
| 121 |
| 122 ItemInterruptedParameters::ItemInterruptedParameters( |
| 123 InterruptReason reason, |
| 124 int64 bytes_so_far, |
| 125 const std::string& hash_state) |
| 126 : reason_(reason), |
| 127 bytes_so_far_(bytes_so_far), |
| 128 hash_state_(hash_state) { |
| 129 } |
| 130 |
| 131 Value* ItemInterruptedParameters::ToValue() const { |
| 132 DictionaryValue* dict = new DictionaryValue(); |
| 133 |
| 134 dict->SetString("interrupt_reason", InterruptReasonDebugString(reason_)); |
| 135 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); |
| 136 dict->SetString("hash_state", |
| 137 base::HexEncode(hash_state_.data(), hash_state_.size())); |
| 138 |
| 139 return dict; |
| 140 } |
| 141 |
| 142 ItemFinishedParameters::ItemFinishedParameters( |
| 143 int64 bytes_so_far, |
| 144 const std::string& final_hash) |
| 145 : bytes_so_far_(bytes_so_far), |
| 146 final_hash_(final_hash) { |
| 147 } |
| 148 |
| 149 Value* ItemFinishedParameters::ToValue() const { |
| 150 DictionaryValue* dict = new DictionaryValue(); |
| 151 |
| 152 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); |
| 153 dict->SetString("final_hash", |
| 154 base::HexEncode(final_hash_.data(), final_hash_.size())); |
| 155 |
| 156 return dict; |
| 157 } |
| 158 |
| 159 ItemCanceledParameters::ItemCanceledParameters( |
| 160 int64 bytes_so_far, |
| 161 const std::string& hash_state) |
| 162 : bytes_so_far_(bytes_so_far), |
| 163 hash_state_(hash_state) { |
| 164 } |
| 165 |
| 166 Value* ItemCanceledParameters::ToValue() const { |
| 167 DictionaryValue* dict = new DictionaryValue(); |
| 168 |
| 169 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far_)); |
| 170 dict->SetString("hash_state", |
| 171 base::HexEncode(hash_state_.data(), hash_state_.size())); |
| 172 |
| 173 return dict; |
| 174 } |
| 175 |
16 FileOpenedParameters::FileOpenedParameters(const std::string& file_name, | 176 FileOpenedParameters::FileOpenedParameters(const std::string& file_name, |
17 int64 start_offset) | 177 int64 start_offset) |
18 : file_name_(file_name), start_offset_(start_offset) { | 178 : file_name_(file_name), start_offset_(start_offset) { |
19 } | 179 } |
20 | 180 |
21 Value* FileOpenedParameters::ToValue() const { | 181 Value* FileOpenedParameters::ToValue() const { |
22 DictionaryValue* dict = new DictionaryValue(); | 182 DictionaryValue* dict = new DictionaryValue(); |
23 | 183 |
24 dict->SetString("file_name", file_name_); | 184 dict->SetString("file_name", file_name_); |
25 dict->SetString("start_offset", base::Int64ToString(start_offset_)); | 185 dict->SetString("start_offset", base::Int64ToString(start_offset_)); |
(...skipping 23 matching lines...) Expand all Loading... |
49 Value* FileErrorParameters::ToValue() const { | 209 Value* FileErrorParameters::ToValue() const { |
50 DictionaryValue* dict = new DictionaryValue(); | 210 DictionaryValue* dict = new DictionaryValue(); |
51 | 211 |
52 dict->SetString("operation", operation_); | 212 dict->SetString("operation", operation_); |
53 dict->SetInteger("net_error", net_error_); | 213 dict->SetInteger("net_error", net_error_); |
54 | 214 |
55 return dict; | 215 return dict; |
56 } | 216 } |
57 | 217 |
58 } // namespace download_net_logs | 218 } // namespace download_net_logs |
OLD | NEW |