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 "storage/browser/blob/view_blob_internals_job.h" | 5 #include "storage/browser/blob/view_blob_internals_job.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/i18n/number_formatting.h" | 13 #include "base/i18n/number_formatting.h" |
14 #include "base/i18n/time_formatting.h" | 14 #include "base/i18n/time_formatting.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/disk_cache/disk_cache.h" | 23 #include "net/disk_cache/disk_cache.h" |
24 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
| 25 #include "storage/browser/blob/blob_data_item.h" |
25 #include "storage/browser/blob/blob_storage_context.h" | 26 #include "storage/browser/blob/blob_storage_context.h" |
| 27 #include "storage/browser/blob/blob_storage_registry.h" |
26 #include "storage/browser/blob/internal_blob_data.h" | 28 #include "storage/browser/blob/internal_blob_data.h" |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 const char kEmptyBlobStorageMessage[] = "No available blob data."; | 32 const char kEmptyBlobStorageMessage[] = "No available blob data."; |
31 const char kContentType[] = "Content Type: "; | 33 const char kContentType[] = "Content Type: "; |
32 const char kContentDisposition[] = "Content Disposition: "; | 34 const char kContentDisposition[] = "Content Disposition: "; |
33 const char kCount[] = "Count: "; | 35 const char kCount[] = "Count: "; |
34 const char kIndex[] = "Index: "; | 36 const char kIndex[] = "Index: "; |
35 const char kType[] = "Type: "; | 37 const char kType[] = "Type: "; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 int ViewBlobInternalsJob::GetData( | 135 int ViewBlobInternalsJob::GetData( |
134 std::string* mime_type, | 136 std::string* mime_type, |
135 std::string* charset, | 137 std::string* charset, |
136 std::string* data, | 138 std::string* data, |
137 const net::CompletionCallback& callback) const { | 139 const net::CompletionCallback& callback) const { |
138 mime_type->assign("text/html"); | 140 mime_type->assign("text/html"); |
139 charset->assign("UTF-8"); | 141 charset->assign("UTF-8"); |
140 | 142 |
141 data->clear(); | 143 data->clear(); |
142 StartHTML(data); | 144 StartHTML(data); |
143 if (blob_storage_context_->blob_map_.empty()) | 145 if (blob_storage_context_->registry_.blob_map_.empty()) |
144 data->append(kEmptyBlobStorageMessage); | 146 data->append(kEmptyBlobStorageMessage); |
145 else | 147 else |
146 GenerateHTML(data); | 148 GenerateHTML(data); |
147 EndHTML(data); | 149 EndHTML(data); |
148 return net::OK; | 150 return net::OK; |
149 } | 151 } |
150 | 152 |
151 void ViewBlobInternalsJob::GenerateHTML(std::string* out) const { | 153 void ViewBlobInternalsJob::GenerateHTML(std::string* out) const { |
152 for (BlobStorageContext::BlobMap::const_iterator iter = | 154 for (BlobStorageRegistry::BlobMap::const_iterator iter = |
153 blob_storage_context_->blob_map_.begin(); | 155 blob_storage_context_->registry_.blob_map_.begin(); |
154 iter != blob_storage_context_->blob_map_.end(); | 156 iter != blob_storage_context_->registry_.blob_map_.end(); ++iter) { |
155 ++iter) { | |
156 AddHTMLBoldText(iter->first, out); | 157 AddHTMLBoldText(iter->first, out); |
157 GenerateHTMLForBlobData(*iter->second->data, iter->second->refcount, out); | 158 GenerateHTMLForBlobData(*iter->second->data, iter->second->content_type, |
| 159 iter->second->content_disposition, |
| 160 iter->second->refcount, out); |
158 } | 161 } |
159 if (!blob_storage_context_->public_blob_urls_.empty()) { | 162 if (!blob_storage_context_->registry_.url_to_uuid_.empty()) { |
160 AddHorizontalRule(out); | 163 AddHorizontalRule(out); |
161 for (BlobStorageContext::BlobURLMap::const_iterator iter = | 164 for (BlobStorageRegistry::URLMap::const_iterator iter = |
162 blob_storage_context_->public_blob_urls_.begin(); | 165 blob_storage_context_->registry_.url_to_uuid_.begin(); |
163 iter != blob_storage_context_->public_blob_urls_.end(); | 166 iter != blob_storage_context_->registry_.url_to_uuid_.end(); ++iter) { |
164 ++iter) { | |
165 AddHTMLBoldText(iter->first.spec(), out); | 167 AddHTMLBoldText(iter->first.spec(), out); |
166 StartHTMLList(out); | 168 StartHTMLList(out); |
167 AddHTMLListItem(kUUID, iter->second, out); | 169 AddHTMLListItem(kUUID, iter->second, out); |
168 EndHTMLList(out); | 170 EndHTMLList(out); |
169 } | 171 } |
170 } | 172 } |
171 } | 173 } |
172 | 174 |
173 void ViewBlobInternalsJob::GenerateHTMLForBlobData( | 175 void ViewBlobInternalsJob::GenerateHTMLForBlobData( |
174 const InternalBlobData& blob_data, | 176 const InternalBlobData& blob_data, |
| 177 const std::string& content_type, |
| 178 const std::string& content_disposition, |
175 int refcount, | 179 int refcount, |
176 std::string* out) { | 180 std::string* out) { |
177 StartHTMLList(out); | 181 StartHTMLList(out); |
178 | 182 |
179 AddHTMLListItem(kRefcount, base::IntToString(refcount), out); | 183 AddHTMLListItem(kRefcount, base::IntToString(refcount), out); |
180 if (!blob_data.content_type().empty()) | 184 if (!content_type.empty()) |
181 AddHTMLListItem(kContentType, blob_data.content_type(), out); | 185 AddHTMLListItem(kContentType, content_type, out); |
182 if (!blob_data.content_disposition().empty()) | 186 if (!content_disposition.empty()) |
183 AddHTMLListItem(kContentDisposition, blob_data.content_disposition(), out); | 187 AddHTMLListItem(kContentDisposition, content_disposition, out); |
184 | 188 |
185 bool has_multi_items = blob_data.items().size() > 1; | 189 bool has_multi_items = blob_data.items().size() > 1; |
186 if (has_multi_items) { | 190 if (has_multi_items) { |
187 AddHTMLListItem(kCount, | 191 AddHTMLListItem(kCount, |
188 base::UTF16ToUTF8(base::FormatNumber(blob_data.items().size())), out); | 192 base::UTF16ToUTF8(base::FormatNumber(blob_data.items().size())), out); |
189 } | 193 } |
190 | 194 |
191 for (size_t i = 0; i < blob_data.items().size(); ++i) { | 195 for (size_t i = 0; i < blob_data.items().size(); ++i) { |
192 if (has_multi_items) { | 196 if (has_multi_items) { |
193 AddHTMLListItem(kIndex, base::UTF16ToUTF8(base::FormatNumber(i)), out); | 197 AddHTMLListItem(kIndex, base::UTF16ToUTF8(base::FormatNumber(i)), out); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 247 } |
244 | 248 |
245 if (has_multi_items) | 249 if (has_multi_items) |
246 EndHTMLList(out); | 250 EndHTMLList(out); |
247 } | 251 } |
248 | 252 |
249 EndHTMLList(out); | 253 EndHTMLList(out); |
250 } | 254 } |
251 | 255 |
252 } // namespace storage | 256 } // namespace storage |
OLD | NEW |