Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: content/browser/download/download_net_log_parameters.cc

Issue 1149763005: Change NetLog::ParametersCallback to return a scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments on ownership removed Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 23 matching lines...) Expand all
34 "POTENTIALLY_UNWANTED" 34 "POTENTIALLY_UNWANTED"
35 }; 35 };
36 36
37 static_assert(arraysize(download_type_names) == SRC_SAVE_PAGE_AS + 1, 37 static_assert(arraysize(download_type_names) == SRC_SAVE_PAGE_AS + 1,
38 "download type enum has changed"); 38 "download type enum has changed");
39 static_assert(arraysize(download_danger_names) == DOWNLOAD_DANGER_TYPE_MAX, 39 static_assert(arraysize(download_danger_names) == DOWNLOAD_DANGER_TYPE_MAX,
40 "download danger enum has changed"); 40 "download danger enum has changed");
41 41
42 } // namespace 42 } // namespace
43 43
44 base::Value* ItemActivatedNetLogCallback(const DownloadItem* download_item, 44 scoped_ptr<base::Value> ItemActivatedNetLogCallback(
45 DownloadType download_type, 45 const DownloadItem* download_item,
46 const std::string* file_name, 46 DownloadType download_type,
47 net::NetLogCaptureMode capture_mode) { 47 const std::string* file_name,
48 base::DictionaryValue* dict = new base::DictionaryValue(); 48 net::NetLogCaptureMode capture_mode) {
49 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
49 50
50 dict->SetString("type", download_type_names[download_type]); 51 dict->SetString("type", download_type_names[download_type]);
51 dict->SetString("id", base::Int64ToString(download_item->GetId())); 52 dict->SetString("id", base::Int64ToString(download_item->GetId()));
52 dict->SetString("original_url", download_item->GetOriginalUrl().spec()); 53 dict->SetString("original_url", download_item->GetOriginalUrl().spec());
53 dict->SetString("final_url", download_item->GetURL().spec()); 54 dict->SetString("final_url", download_item->GetURL().spec());
54 dict->SetString("file_name", *file_name); 55 dict->SetString("file_name", *file_name);
55 dict->SetString("danger_type", 56 dict->SetString("danger_type",
56 download_danger_names[download_item->GetDangerType()]); 57 download_danger_names[download_item->GetDangerType()]);
57 dict->SetString("start_offset", 58 dict->SetString("start_offset",
58 base::Int64ToString(download_item->GetReceivedBytes())); 59 base::Int64ToString(download_item->GetReceivedBytes()));
59 dict->SetBoolean("has_user_gesture", download_item->HasUserGesture()); 60 dict->SetBoolean("has_user_gesture", download_item->HasUserGesture());
60 61
61 return dict; 62 return dict.Pass();
62 } 63 }
63 64
64 base::Value* ItemCheckedNetLogCallback(DownloadDangerType danger_type, 65 scoped_ptr<base::Value> ItemCheckedNetLogCallback(
65 net::NetLogCaptureMode capture_mode) { 66 DownloadDangerType danger_type,
66 base::DictionaryValue* dict = new base::DictionaryValue(); 67 net::NetLogCaptureMode capture_mode) {
68 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
67 69
68 dict->SetString("danger_type", download_danger_names[danger_type]); 70 dict->SetString("danger_type", download_danger_names[danger_type]);
69 71
70 return dict; 72 return dict.Pass();
71 } 73 }
72 74
73 base::Value* ItemRenamedNetLogCallback(const base::FilePath* old_filename, 75 scoped_ptr<base::Value> ItemRenamedNetLogCallback(
74 const base::FilePath* new_filename, 76 const base::FilePath* old_filename,
75 net::NetLogCaptureMode capture_mode) { 77 const base::FilePath* new_filename,
76 base::DictionaryValue* dict = new base::DictionaryValue(); 78 net::NetLogCaptureMode capture_mode) {
79 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
77 80
78 dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); 81 dict->SetString("old_filename", old_filename->AsUTF8Unsafe());
79 dict->SetString("new_filename", new_filename->AsUTF8Unsafe()); 82 dict->SetString("new_filename", new_filename->AsUTF8Unsafe());
80 83
81 return dict; 84 return dict.Pass();
82 } 85 }
83 86
84 base::Value* ItemInterruptedNetLogCallback( 87 scoped_ptr<base::Value> ItemInterruptedNetLogCallback(
85 DownloadInterruptReason reason, 88 DownloadInterruptReason reason,
86 int64 bytes_so_far, 89 int64 bytes_so_far,
87 const std::string* hash_state, 90 const std::string* hash_state,
88 net::NetLogCaptureMode capture_mode) { 91 net::NetLogCaptureMode capture_mode) {
89 base::DictionaryValue* dict = new base::DictionaryValue(); 92 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
90 93
91 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); 94 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason));
92 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); 95 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
93 dict->SetString("hash_state", 96 dict->SetString("hash_state",
94 base::HexEncode(hash_state->data(), hash_state->size())); 97 base::HexEncode(hash_state->data(), hash_state->size()));
95 98
96 return dict; 99 return dict.Pass();
97 } 100 }
98 101
99 base::Value* ItemResumingNetLogCallback(bool user_initiated, 102 scoped_ptr<base::Value> ItemResumingNetLogCallback(
100 DownloadInterruptReason reason, 103 bool user_initiated,
101 int64 bytes_so_far, 104 DownloadInterruptReason reason,
102 const std::string* hash_state, 105 int64 bytes_so_far,
103 net::NetLogCaptureMode capture_mode) { 106 const std::string* hash_state,
104 base::DictionaryValue* dict = new base::DictionaryValue(); 107 net::NetLogCaptureMode capture_mode) {
108 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
105 109
106 dict->SetString("user_initiated", user_initiated ? "true" : "false"); 110 dict->SetString("user_initiated", user_initiated ? "true" : "false");
107 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); 111 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason));
108 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); 112 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
109 dict->SetString("hash_state", 113 dict->SetString("hash_state",
110 base::HexEncode(hash_state->data(), hash_state->size())); 114 base::HexEncode(hash_state->data(), hash_state->size()));
111 115
112 return dict; 116 return dict.Pass();
113 } 117 }
114 118
115 base::Value* ItemCompletingNetLogCallback(int64 bytes_so_far, 119 scoped_ptr<base::Value> ItemCompletingNetLogCallback(
116 const std::string* final_hash, 120 int64 bytes_so_far,
117 net::NetLogCaptureMode capture_mode) { 121 const std::string* final_hash,
118 base::DictionaryValue* dict = new base::DictionaryValue(); 122 net::NetLogCaptureMode capture_mode) {
123 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
119 124
120 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); 125 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
121 dict->SetString("final_hash", 126 dict->SetString("final_hash",
122 base::HexEncode(final_hash->data(), final_hash->size())); 127 base::HexEncode(final_hash->data(), final_hash->size()));
123 128
124 return dict; 129 return dict.Pass();
125 } 130 }
126 131
127 base::Value* ItemFinishedNetLogCallback(bool auto_opened, 132 scoped_ptr<base::Value> ItemFinishedNetLogCallback(
128 net::NetLogCaptureMode capture_mode) { 133 bool auto_opened,
129 base::DictionaryValue* dict = new base::DictionaryValue(); 134 net::NetLogCaptureMode capture_mode) {
135 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
130 136
131 dict->SetString("auto_opened", auto_opened ? "yes" : "no"); 137 dict->SetString("auto_opened", auto_opened ? "yes" : "no");
132 138
133 return dict; 139 return dict.Pass();
134 } 140 }
135 141
136 base::Value* ItemCanceledNetLogCallback(int64 bytes_so_far, 142 scoped_ptr<base::Value> ItemCanceledNetLogCallback(
137 const std::string* hash_state, 143 int64 bytes_so_far,
138 net::NetLogCaptureMode capture_mode) { 144 const std::string* hash_state,
139 base::DictionaryValue* dict = new base::DictionaryValue(); 145 net::NetLogCaptureMode capture_mode) {
146 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
140 147
141 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far)); 148 dict->SetString("bytes_so_far", base::Int64ToString(bytes_so_far));
142 dict->SetString("hash_state", 149 dict->SetString("hash_state",
143 base::HexEncode(hash_state->data(), hash_state->size())); 150 base::HexEncode(hash_state->data(), hash_state->size()));
144 151
145 return dict; 152 return dict.Pass();
146 } 153 }
147 154
148 base::Value* FileOpenedNetLogCallback(const base::FilePath* file_name, 155 scoped_ptr<base::Value> FileOpenedNetLogCallback(
149 int64 start_offset, 156 const base::FilePath* file_name,
150 net::NetLogCaptureMode capture_mode) { 157 int64 start_offset,
151 base::DictionaryValue* dict = new base::DictionaryValue(); 158 net::NetLogCaptureMode capture_mode) {
159 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
152 160
153 dict->SetString("file_name", file_name->AsUTF8Unsafe()); 161 dict->SetString("file_name", file_name->AsUTF8Unsafe());
154 dict->SetString("start_offset", base::Int64ToString(start_offset)); 162 dict->SetString("start_offset", base::Int64ToString(start_offset));
155 163
156 return dict; 164 return dict.Pass();
157 } 165 }
158 166
159 base::Value* FileStreamDrainedNetLogCallback( 167 scoped_ptr<base::Value> FileStreamDrainedNetLogCallback(
160 size_t stream_size, 168 size_t stream_size,
161 size_t num_buffers, 169 size_t num_buffers,
162 net::NetLogCaptureMode capture_mode) { 170 net::NetLogCaptureMode capture_mode) {
163 base::DictionaryValue* dict = new base::DictionaryValue(); 171 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
164 172
165 dict->SetInteger("stream_size", static_cast<int>(stream_size)); 173 dict->SetInteger("stream_size", static_cast<int>(stream_size));
166 dict->SetInteger("num_buffers", static_cast<int>(num_buffers)); 174 dict->SetInteger("num_buffers", static_cast<int>(num_buffers));
167 175
168 return dict; 176 return dict.Pass();
169 } 177 }
170 178
171 base::Value* FileRenamedNetLogCallback(const base::FilePath* old_filename, 179 scoped_ptr<base::Value> FileRenamedNetLogCallback(
172 const base::FilePath* new_filename, 180 const base::FilePath* old_filename,
173 net::NetLogCaptureMode capture_mode) { 181 const base::FilePath* new_filename,
174 base::DictionaryValue* dict = new base::DictionaryValue(); 182 net::NetLogCaptureMode capture_mode) {
183 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
175 184
176 dict->SetString("old_filename", old_filename->AsUTF8Unsafe()); 185 dict->SetString("old_filename", old_filename->AsUTF8Unsafe());
177 dict->SetString("new_filename", new_filename->AsUTF8Unsafe()); 186 dict->SetString("new_filename", new_filename->AsUTF8Unsafe());
178 187
179 return dict; 188 return dict.Pass();
180 } 189 }
181 190
182 base::Value* FileErrorNetLogCallback(const char* operation, 191 scoped_ptr<base::Value> FileErrorNetLogCallback(
183 net::Error net_error, 192 const char* operation,
184 net::NetLogCaptureMode capture_mode) { 193 net::Error net_error,
185 base::DictionaryValue* dict = new base::DictionaryValue(); 194 net::NetLogCaptureMode capture_mode) {
195 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
186 196
187 dict->SetString("operation", operation); 197 dict->SetString("operation", operation);
188 dict->SetInteger("net_error", net_error); 198 dict->SetInteger("net_error", net_error);
189 199
190 return dict; 200 return dict.Pass();
191 } 201 }
192 202
193 base::Value* FileInterruptedNetLogCallback( 203 scoped_ptr<base::Value> FileInterruptedNetLogCallback(
194 const char* operation, 204 const char* operation,
195 int os_error, 205 int os_error,
196 DownloadInterruptReason reason, 206 DownloadInterruptReason reason,
197 net::NetLogCaptureMode capture_mode) { 207 net::NetLogCaptureMode capture_mode) {
198 base::DictionaryValue* dict = new base::DictionaryValue(); 208 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
199 209
200 dict->SetString("operation", operation); 210 dict->SetString("operation", operation);
201 if (os_error != 0) 211 if (os_error != 0)
202 dict->SetInteger("os_error", os_error); 212 dict->SetInteger("os_error", os_error);
203 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason)); 213 dict->SetString("interrupt_reason", DownloadInterruptReasonToString(reason));
204 214
205 return dict; 215 return dict.Pass();
206 } 216 }
207 217
208 } // namespace content 218 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_net_log_parameters.h ('k') | extensions/browser/api/web_request/web_request_api_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698