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 "webkit/browser/blob/view_blob_internals_job.h" | 5 #include "storage/browser/blob/view_blob_internals_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
11 #include "base/i18n/time_formatting.h" | 11 #include "base/i18n/time_formatting.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
20 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
21 #include "webkit/browser/blob/blob_storage_context.h" | 21 #include "storage/browser/blob/blob_storage_context.h" |
22 #include "webkit/common/blob/blob_data.h" | 22 #include "storage/common/blob/blob_data.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const char kEmptyBlobStorageMessage[] = "No available blob data."; | 26 const char kEmptyBlobStorageMessage[] = "No available blob data."; |
27 const char kContentType[] = "Content Type: "; | 27 const char kContentType[] = "Content Type: "; |
28 const char kContentDisposition[] = "Content Disposition: "; | 28 const char kContentDisposition[] = "Content Disposition: "; |
29 const char kCount[] = "Count: "; | 29 const char kCount[] = "Count: "; |
30 const char kIndex[] = "Index: "; | 30 const char kIndex[] = "Index: "; |
31 const char kType[] = "Type: "; | 31 const char kType[] = "Type: "; |
32 const char kPath[] = "Path: "; | 32 const char kPath[] = "Path: "; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 out->append(net::EscapeForHTML(element_data)); | 80 out->append(net::EscapeForHTML(element_data)); |
81 out->append("</li>\n"); | 81 out->append("</li>\n"); |
82 } | 82 } |
83 | 83 |
84 void AddHorizontalRule(std::string* out) { | 84 void AddHorizontalRule(std::string* out) { |
85 out->append("\n<hr>\n"); | 85 out->append("\n<hr>\n"); |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 namespace webkit_blob { | 90 namespace storage { |
91 | 91 |
92 ViewBlobInternalsJob::ViewBlobInternalsJob( | 92 ViewBlobInternalsJob::ViewBlobInternalsJob( |
93 net::URLRequest* request, | 93 net::URLRequest* request, |
94 net::NetworkDelegate* network_delegate, | 94 net::NetworkDelegate* network_delegate, |
95 BlobStorageContext* blob_storage_context) | 95 BlobStorageContext* blob_storage_context) |
96 : net::URLRequestSimpleJob(request, network_delegate), | 96 : net::URLRequestSimpleJob(request, network_delegate), |
97 blob_storage_context_(blob_storage_context), | 97 blob_storage_context_(blob_storage_context), |
98 weak_factory_(this) { | 98 weak_factory_(this) { |
99 } | 99 } |
100 | 100 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 EndHTML(data); | 143 EndHTML(data); |
144 return net::OK; | 144 return net::OK; |
145 } | 145 } |
146 | 146 |
147 void ViewBlobInternalsJob::GenerateHTML(std::string* out) const { | 147 void ViewBlobInternalsJob::GenerateHTML(std::string* out) const { |
148 for (BlobStorageContext::BlobMap::const_iterator iter = | 148 for (BlobStorageContext::BlobMap::const_iterator iter = |
149 blob_storage_context_->blob_map_.begin(); | 149 blob_storage_context_->blob_map_.begin(); |
150 iter != blob_storage_context_->blob_map_.end(); | 150 iter != blob_storage_context_->blob_map_.end(); |
151 ++iter) { | 151 ++iter) { |
152 AddHTMLBoldText(iter->first, out); | 152 AddHTMLBoldText(iter->first, out); |
153 GenerateHTMLForBlobData(*(iter->second.data.get()), | 153 GenerateHTMLForBlobData( |
154 iter->second.refcount, | 154 *(iter->second.data.get()), iter->second.refcount, out); |
155 out); | |
156 } | 155 } |
157 if (!blob_storage_context_->public_blob_urls_.empty()) { | 156 if (!blob_storage_context_->public_blob_urls_.empty()) { |
158 AddHorizontalRule(out); | 157 AddHorizontalRule(out); |
159 for (BlobStorageContext::BlobURLMap::const_iterator iter = | 158 for (BlobStorageContext::BlobURLMap::const_iterator iter = |
160 blob_storage_context_->public_blob_urls_.begin(); | 159 blob_storage_context_->public_blob_urls_.begin(); |
161 iter != blob_storage_context_->public_blob_urls_.end(); | 160 iter != blob_storage_context_->public_blob_urls_.end(); |
162 ++iter) { | 161 ++iter) { |
163 AddHTMLBoldText(iter->first.spec(), out); | 162 AddHTMLBoldText(iter->first.spec(), out); |
164 StartHTMLList(out); | 163 StartHTMLList(out); |
165 AddHTMLListItem(kUUID, iter->second, out); | 164 AddHTMLListItem(kUUID, iter->second, out); |
166 EndHTMLList(out); | 165 EndHTMLList(out); |
167 } | 166 } |
168 } | 167 } |
169 } | 168 } |
170 | 169 |
171 void ViewBlobInternalsJob::GenerateHTMLForBlobData(const BlobData& blob_data, | 170 void ViewBlobInternalsJob::GenerateHTMLForBlobData(const BlobData& blob_data, |
172 int refcount, | 171 int refcount, |
173 std::string* out) { | 172 std::string* out) { |
174 StartHTMLList(out); | 173 StartHTMLList(out); |
175 | 174 |
176 AddHTMLListItem(kRefcount, base::IntToString(refcount), out); | 175 AddHTMLListItem(kRefcount, base::IntToString(refcount), out); |
177 if (!blob_data.content_type().empty()) | 176 if (!blob_data.content_type().empty()) |
178 AddHTMLListItem(kContentType, blob_data.content_type(), out); | 177 AddHTMLListItem(kContentType, blob_data.content_type(), out); |
179 if (!blob_data.content_disposition().empty()) | 178 if (!blob_data.content_disposition().empty()) |
180 AddHTMLListItem(kContentDisposition, blob_data.content_disposition(), out); | 179 AddHTMLListItem(kContentDisposition, blob_data.content_disposition(), out); |
181 | 180 |
182 bool has_multi_items = blob_data.items().size() > 1; | 181 bool has_multi_items = blob_data.items().size() > 1; |
183 if (has_multi_items) { | 182 if (has_multi_items) { |
184 AddHTMLListItem(kCount, | 183 AddHTMLListItem( |
185 base::UTF16ToUTF8(base::FormatNumber(blob_data.items().size())), out); | 184 kCount, |
| 185 base::UTF16ToUTF8(base::FormatNumber(blob_data.items().size())), |
| 186 out); |
186 } | 187 } |
187 | 188 |
188 for (size_t i = 0; i < blob_data.items().size(); ++i) { | 189 for (size_t i = 0; i < blob_data.items().size(); ++i) { |
189 if (has_multi_items) { | 190 if (has_multi_items) { |
190 AddHTMLListItem(kIndex, base::UTF16ToUTF8(base::FormatNumber(i)), out); | 191 AddHTMLListItem(kIndex, base::UTF16ToUTF8(base::FormatNumber(i)), out); |
191 StartHTMLList(out); | 192 StartHTMLList(out); |
192 } | 193 } |
193 const BlobData::Item& item = blob_data.items().at(i); | 194 const BlobData::Item& item = blob_data.items().at(i); |
194 | 195 |
195 switch (item.type()) { | 196 switch (item.type()) { |
196 case BlobData::Item::TYPE_BYTES: | 197 case BlobData::Item::TYPE_BYTES: |
197 AddHTMLListItem(kType, "data", out); | 198 AddHTMLListItem(kType, "data", out); |
198 break; | 199 break; |
199 case BlobData::Item::TYPE_FILE: | 200 case BlobData::Item::TYPE_FILE: |
200 AddHTMLListItem(kType, "file", out); | 201 AddHTMLListItem(kType, "file", out); |
201 AddHTMLListItem(kPath, | 202 AddHTMLListItem( |
202 net::EscapeForHTML(item.path().AsUTF8Unsafe()), | 203 kPath, net::EscapeForHTML(item.path().AsUTF8Unsafe()), out); |
203 out); | |
204 if (!item.expected_modification_time().is_null()) { | 204 if (!item.expected_modification_time().is_null()) { |
205 AddHTMLListItem(kModificationTime, base::UTF16ToUTF8( | 205 AddHTMLListItem(kModificationTime, |
206 TimeFormatFriendlyDateAndTime(item.expected_modification_time())), | 206 base::UTF16ToUTF8(TimeFormatFriendlyDateAndTime( |
207 out); | 207 item.expected_modification_time())), |
| 208 out); |
208 } | 209 } |
209 break; | 210 break; |
210 case BlobData::Item::TYPE_BLOB: | 211 case BlobData::Item::TYPE_BLOB: |
211 NOTREACHED(); // Should be flattened in the storage context. | 212 NOTREACHED(); // Should be flattened in the storage context. |
212 break; | 213 break; |
213 case BlobData::Item::TYPE_FILE_FILESYSTEM: | 214 case BlobData::Item::TYPE_FILE_FILESYSTEM: |
214 AddHTMLListItem(kType, "filesystem", out); | 215 AddHTMLListItem(kType, "filesystem", out); |
215 AddHTMLListItem(kURL, item.filesystem_url().spec(), out); | 216 AddHTMLListItem(kURL, item.filesystem_url().spec(), out); |
216 if (!item.expected_modification_time().is_null()) { | 217 if (!item.expected_modification_time().is_null()) { |
217 AddHTMLListItem(kModificationTime, base::UTF16ToUTF8( | 218 AddHTMLListItem(kModificationTime, |
218 TimeFormatFriendlyDateAndTime(item.expected_modification_time())), | 219 base::UTF16ToUTF8(TimeFormatFriendlyDateAndTime( |
219 out); | 220 item.expected_modification_time())), |
| 221 out); |
220 } | 222 } |
221 break; | 223 break; |
222 case BlobData::Item::TYPE_UNKNOWN: | 224 case BlobData::Item::TYPE_UNKNOWN: |
223 NOTREACHED(); | 225 NOTREACHED(); |
224 break; | 226 break; |
225 } | 227 } |
226 if (item.offset()) { | 228 if (item.offset()) { |
227 AddHTMLListItem(kOffset, base::UTF16ToUTF8(base::FormatNumber( | 229 AddHTMLListItem(kOffset, |
228 static_cast<int64>(item.offset()))), out); | 230 base::UTF16ToUTF8(base::FormatNumber( |
| 231 static_cast<int64>(item.offset()))), |
| 232 out); |
229 } | 233 } |
230 if (static_cast<int64>(item.length()) != -1) { | 234 if (static_cast<int64>(item.length()) != -1) { |
231 AddHTMLListItem(kLength, base::UTF16ToUTF8(base::FormatNumber( | 235 AddHTMLListItem(kLength, |
232 static_cast<int64>(item.length()))), out); | 236 base::UTF16ToUTF8(base::FormatNumber( |
| 237 static_cast<int64>(item.length()))), |
| 238 out); |
233 } | 239 } |
234 | 240 |
235 if (has_multi_items) | 241 if (has_multi_items) |
236 EndHTMLList(out); | 242 EndHTMLList(out); |
237 } | 243 } |
238 | 244 |
239 EndHTMLList(out); | 245 EndHTMLList(out); |
240 } | 246 } |
241 | 247 |
242 } // namespace webkit_blob | 248 } // namespace storage |
OLD | NEW |