| 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 <utility> |
| 8 |
| 7 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/values.h" | 13 #include "base/values.h" |
| 12 #include "content/public/browser/download_interrupt_reasons.h" | 14 #include "content/public/browser/download_interrupt_reasons.h" |
| 13 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 15 | 17 |
| 16 namespace content { | 18 namespace content { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 dict->SetString("id", base::UintToString(download_item->GetId())); | 54 dict->SetString("id", base::UintToString(download_item->GetId())); |
| 53 dict->SetString("original_url", download_item->GetOriginalUrl().spec()); | 55 dict->SetString("original_url", download_item->GetOriginalUrl().spec()); |
| 54 dict->SetString("final_url", download_item->GetURL().spec()); | 56 dict->SetString("final_url", download_item->GetURL().spec()); |
| 55 dict->SetString("file_name", *file_name); | 57 dict->SetString("file_name", *file_name); |
| 56 dict->SetString("danger_type", | 58 dict->SetString("danger_type", |
| 57 download_danger_names[download_item->GetDangerType()]); | 59 download_danger_names[download_item->GetDangerType()]); |
| 58 dict->SetString("start_offset", | 60 dict->SetString("start_offset", |
| 59 base::Int64ToString(download_item->GetReceivedBytes())); | 61 base::Int64ToString(download_item->GetReceivedBytes())); |
| 60 dict->SetBoolean("has_user_gesture", download_item->HasUserGesture()); | 62 dict->SetBoolean("has_user_gesture", download_item->HasUserGesture()); |
| 61 | 63 |
| 62 return dict.Pass(); | 64 return std::move(dict); |
| 63 } | 65 } |
| 64 | 66 |
| 65 scoped_ptr<base::Value> ItemCheckedNetLogCallback( | 67 scoped_ptr<base::Value> ItemCheckedNetLogCallback( |
| 66 DownloadDangerType danger_type, | 68 DownloadDangerType danger_type, |
| 67 net::NetLogCaptureMode capture_mode) { | 69 net::NetLogCaptureMode capture_mode) { |
| 68 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 70 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 69 | 71 |
| 70 dict->SetString("danger_type", download_danger_names[danger_type]); | 72 dict->SetString("danger_type", download_danger_names[danger_type]); |
| 71 | 73 |
| 72 return dict.Pass(); | 74 return std::move(dict); |
| 73 } | 75 } |
| 74 | 76 |
| 75 scoped_ptr<base::Value> ItemRenamedNetLogCallback( | 77 scoped_ptr<base::Value> ItemRenamedNetLogCallback( |
| 76 const base::FilePath* old_filename, | 78 const base::FilePath* old_filename, |
| 77 const base::FilePath* new_filename, | 79 const base::FilePath* new_filename, |
| 78 net::NetLogCaptureMode capture_mode) { | 80 net::NetLogCaptureMode capture_mode) { |
| 79 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 81 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 80 | 82 |
| 81 dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); | 83 dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); |
| 82 dict->SetString("new_filename", new_filename->AsUTF8Unsafe()); | 84 dict->SetString("new_filename", new_filename->AsUTF8Unsafe()); |
| 83 | 85 |
| 84 return dict.Pass(); | 86 return std::move(dict); |
| 85 } | 87 } |
| 86 | 88 |
| 87 scoped_ptr<base::Value> ItemInterruptedNetLogCallback( | 89 scoped_ptr<base::Value> ItemInterruptedNetLogCallback( |
| 88 DownloadInterruptReason reason, | 90 DownloadInterruptReason reason, |
| 89 int64_t bytes_so_far, | 91 int64_t bytes_so_far, |
| 90 const std::string* hash_state, | 92 const std::string* hash_state, |
| 91 net::NetLogCaptureMode capture_mode) { | 93 net::NetLogCaptureMode capture_mode) { |
| 92 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 94 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 93 | 95 |
| 94 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); | 96 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); |
| 95 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); | 97 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); |
| 96 dict->SetString("hash_state", | 98 dict->SetString("hash_state", |
| 97 base::HexEncode(hash_state->data(), hash_state->size())); | 99 base::HexEncode(hash_state->data(), hash_state->size())); |
| 98 | 100 |
| 99 return dict.Pass(); | 101 return std::move(dict); |
| 100 } | 102 } |
| 101 | 103 |
| 102 scoped_ptr<base::Value> ItemResumingNetLogCallback( | 104 scoped_ptr<base::Value> ItemResumingNetLogCallback( |
| 103 bool user_initiated, | 105 bool user_initiated, |
| 104 DownloadInterruptReason reason, | 106 DownloadInterruptReason reason, |
| 105 int64_t bytes_so_far, | 107 int64_t bytes_so_far, |
| 106 const std::string* hash_state, | 108 const std::string* hash_state, |
| 107 net::NetLogCaptureMode capture_mode) { | 109 net::NetLogCaptureMode capture_mode) { |
| 108 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 110 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 109 | 111 |
| 110 dict->SetString("user_initiated", user_initiated ? "true" : "false"); | 112 dict->SetString("user_initiated", user_initiated ? "true" : "false"); |
| 111 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); | 113 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); |
| 112 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); | 114 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); |
| 113 dict->SetString("hash_state", | 115 dict->SetString("hash_state", |
| 114 base::HexEncode(hash_state->data(), hash_state->size())); | 116 base::HexEncode(hash_state->data(), hash_state->size())); |
| 115 | 117 |
| 116 return dict.Pass(); | 118 return std::move(dict); |
| 117 } | 119 } |
| 118 | 120 |
| 119 scoped_ptr<base::Value> ItemCompletingNetLogCallback( | 121 scoped_ptr<base::Value> ItemCompletingNetLogCallback( |
| 120 int64_t bytes_so_far, | 122 int64_t bytes_so_far, |
| 121 const std::string* final_hash, | 123 const std::string* final_hash, |
| 122 net::NetLogCaptureMode capture_mode) { | 124 net::NetLogCaptureMode capture_mode) { |
| 123 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 125 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 124 | 126 |
| 125 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); | 127 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); |
| 126 dict->SetString("final_hash", | 128 dict->SetString("final_hash", |
| 127 base::HexEncode(final_hash->data(), final_hash->size())); | 129 base::HexEncode(final_hash->data(), final_hash->size())); |
| 128 | 130 |
| 129 return dict.Pass(); | 131 return std::move(dict); |
| 130 } | 132 } |
| 131 | 133 |
| 132 scoped_ptr<base::Value> ItemFinishedNetLogCallback( | 134 scoped_ptr<base::Value> ItemFinishedNetLogCallback( |
| 133 bool auto_opened, | 135 bool auto_opened, |
| 134 net::NetLogCaptureMode capture_mode) { | 136 net::NetLogCaptureMode capture_mode) { |
| 135 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 137 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 136 | 138 |
| 137 dict->SetString("auto_opened", auto_opened ? "yes" : "no"); | 139 dict->SetString("auto_opened", auto_opened ? "yes" : "no"); |
| 138 | 140 |
| 139 return dict.Pass(); | 141 return std::move(dict); |
| 140 } | 142 } |
| 141 | 143 |
| 142 scoped_ptr<base::Value> ItemCanceledNetLogCallback( | 144 scoped_ptr<base::Value> ItemCanceledNetLogCallback( |
| 143 int64_t bytes_so_far, | 145 int64_t bytes_so_far, |
| 144 const std::string* hash_state, | 146 const std::string* hash_state, |
| 145 net::NetLogCaptureMode capture_mode) { | 147 net::NetLogCaptureMode capture_mode) { |
| 146 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 148 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 147 | 149 |
| 148 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); | 150 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); |
| 149 dict->SetString("hash_state", | 151 dict->SetString("hash_state", |
| 150 base::HexEncode(hash_state->data(), hash_state->size())); | 152 base::HexEncode(hash_state->data(), hash_state->size())); |
| 151 | 153 |
| 152 return dict.Pass(); | 154 return std::move(dict); |
| 153 } | 155 } |
| 154 | 156 |
| 155 scoped_ptr<base::Value> FileOpenedNetLogCallback( | 157 scoped_ptr<base::Value> FileOpenedNetLogCallback( |
| 156 const base::FilePath* file_name, | 158 const base::FilePath* file_name, |
| 157 int64_t start_offset, | 159 int64_t start_offset, |
| 158 net::NetLogCaptureMode capture_mode) { | 160 net::NetLogCaptureMode capture_mode) { |
| 159 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 161 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 160 | 162 |
| 161 dict->SetString("file_name", file_name->AsUTF8Unsafe()); | 163 dict->SetString("file_name", file_name->AsUTF8Unsafe()); |
| 162 dict->SetString("start_offset", base::Int64ToString(start_offset)); | 164 dict->SetString("start_offset", base::Int64ToString(start_offset)); |
| 163 | 165 |
| 164 return dict.Pass(); | 166 return std::move(dict); |
| 165 } | 167 } |
| 166 | 168 |
| 167 scoped_ptr<base::Value> FileStreamDrainedNetLogCallback( | 169 scoped_ptr<base::Value> FileStreamDrainedNetLogCallback( |
| 168 size_t stream_size, | 170 size_t stream_size, |
| 169 size_t num_buffers, | 171 size_t num_buffers, |
| 170 net::NetLogCaptureMode capture_mode) { | 172 net::NetLogCaptureMode capture_mode) { |
| 171 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 173 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 172 | 174 |
| 173 dict->SetInteger("stream_size", static_cast<int>(stream_size)); | 175 dict->SetInteger("stream_size", static_cast<int>(stream_size)); |
| 174 dict->SetInteger("num_buffers", static_cast<int>(num_buffers)); | 176 dict->SetInteger("num_buffers", static_cast<int>(num_buffers)); |
| 175 | 177 |
| 176 return dict.Pass(); | 178 return std::move(dict); |
| 177 } | 179 } |
| 178 | 180 |
| 179 scoped_ptr<base::Value> FileRenamedNetLogCallback( | 181 scoped_ptr<base::Value> FileRenamedNetLogCallback( |
| 180 const base::FilePath* old_filename, | 182 const base::FilePath* old_filename, |
| 181 const base::FilePath* new_filename, | 183 const base::FilePath* new_filename, |
| 182 net::NetLogCaptureMode capture_mode) { | 184 net::NetLogCaptureMode capture_mode) { |
| 183 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 185 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 184 | 186 |
| 185 dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); | 187 dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); |
| 186 dict->SetString("new_filename", new_filename->AsUTF8Unsafe()); | 188 dict->SetString("new_filename", new_filename->AsUTF8Unsafe()); |
| 187 | 189 |
| 188 return dict.Pass(); | 190 return std::move(dict); |
| 189 } | 191 } |
| 190 | 192 |
| 191 scoped_ptr<base::Value> FileErrorNetLogCallback( | 193 scoped_ptr<base::Value> FileErrorNetLogCallback( |
| 192 const char* operation, | 194 const char* operation, |
| 193 net::Error net_error, | 195 net::Error net_error, |
| 194 net::NetLogCaptureMode capture_mode) { | 196 net::NetLogCaptureMode capture_mode) { |
| 195 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 197 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 196 | 198 |
| 197 dict->SetString("operation", operation); | 199 dict->SetString("operation", operation); |
| 198 dict->SetInteger("net_error", net_error); | 200 dict->SetInteger("net_error", net_error); |
| 199 | 201 |
| 200 return dict.Pass(); | 202 return std::move(dict); |
| 201 } | 203 } |
| 202 | 204 |
| 203 scoped_ptr<base::Value> FileInterruptedNetLogCallback( | 205 scoped_ptr<base::Value> FileInterruptedNetLogCallback( |
| 204 const char* operation, | 206 const char* operation, |
| 205 int os_error, | 207 int os_error, |
| 206 DownloadInterruptReason reason, | 208 DownloadInterruptReason reason, |
| 207 net::NetLogCaptureMode capture_mode) { | 209 net::NetLogCaptureMode capture_mode) { |
| 208 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 210 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 209 | 211 |
| 210 dict->SetString("operation", operation); | 212 dict->SetString("operation", operation); |
| 211 if (os_error != 0) | 213 if (os_error != 0) |
| 212 dict->SetInteger("os_error", os_error); | 214 dict->SetInteger("os_error", os_error); |
| 213 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); | 215 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); |
| 214 | 216 |
| 215 return dict.Pass(); | 217 return std::move(dict); |
| 216 } | 218 } |
| 217 | 219 |
| 218 } // namespace content | 220 } // namespace content |
| OLD | NEW |