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

Side by Side Diff: storage/browser/blob/view_blob_internals_job.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed copyright Created 5 years, 11 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 "storage/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 "storage/browser/blob/blob_data_snapshot.h"
21 #include "storage/browser/blob/blob_storage_context.h" 22 #include "storage/browser/blob/blob_storage_context.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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(*(iter->second->data.get()), iter->second->refcount,
154 iter->second.refcount,
155 out); 154 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(
172 int refcount, 171 const BlobDataSnapshot& blob_data,
173 std::string* out) { 172 int refcount,
173 std::string* out) {
174 StartHTMLList(out); 174 StartHTMLList(out);
175 175
176 AddHTMLListItem(kRefcount, base::IntToString(refcount), out); 176 AddHTMLListItem(kRefcount, base::IntToString(refcount), out);
177 if (!blob_data.content_type().empty()) 177 if (!blob_data.content_type().empty())
178 AddHTMLListItem(kContentType, blob_data.content_type(), out); 178 AddHTMLListItem(kContentType, blob_data.content_type(), out);
179 if (!blob_data.content_disposition().empty()) 179 if (!blob_data.content_disposition().empty())
180 AddHTMLListItem(kContentDisposition, blob_data.content_disposition(), out); 180 AddHTMLListItem(kContentDisposition, blob_data.content_disposition(), out);
181 181
182 bool has_multi_items = blob_data.items().size() > 1; 182 bool has_multi_items = blob_data.items().size() > 1;
183 if (has_multi_items) { 183 if (has_multi_items) {
184 AddHTMLListItem(kCount, 184 AddHTMLListItem(kCount,
185 base::UTF16ToUTF8(base::FormatNumber(blob_data.items().size())), out); 185 base::UTF16ToUTF8(base::FormatNumber(blob_data.items().size())), out);
186 } 186 }
187 187
188 for (size_t i = 0; i < blob_data.items().size(); ++i) { 188 for (size_t i = 0; i < blob_data.items().size(); ++i) {
189 if (has_multi_items) { 189 if (has_multi_items) {
190 AddHTMLListItem(kIndex, base::UTF16ToUTF8(base::FormatNumber(i)), out); 190 AddHTMLListItem(kIndex, base::UTF16ToUTF8(base::FormatNumber(i)), out);
191 StartHTMLList(out); 191 StartHTMLList(out);
192 } 192 }
193 const BlobData::Item& item = blob_data.items().at(i); 193 const BlobDataItem& item = *(blob_data.items().at(i));
194 194
195 switch (item.type()) { 195 switch (item.type()) {
196 case BlobData::Item::TYPE_BYTES: 196 case DataElement::TYPE_BYTES:
197 AddHTMLListItem(kType, "data", out); 197 AddHTMLListItem(kType, "data", out);
198 break; 198 break;
199 case BlobData::Item::TYPE_FILE: 199 case DataElement::TYPE_FILE:
200 AddHTMLListItem(kType, "file", out); 200 AddHTMLListItem(kType, "file", out);
201 AddHTMLListItem(kPath, 201 AddHTMLListItem(kPath,
202 net::EscapeForHTML(item.path().AsUTF8Unsafe()), 202 net::EscapeForHTML(item.path().AsUTF8Unsafe()),
203 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, base::UTF16ToUTF8(
206 TimeFormatFriendlyDateAndTime(item.expected_modification_time())), 206 TimeFormatFriendlyDateAndTime(item.expected_modification_time())),
207 out); 207 out);
208 } 208 }
209 break; 209 break;
210 case BlobData::Item::TYPE_BLOB: 210 case DataElement::TYPE_BLOB:
211 NOTREACHED(); // Should be flattened in the storage context. 211 NOTREACHED(); // Should be flattened in the storage context.
212 break; 212 break;
213 case BlobData::Item::TYPE_FILE_FILESYSTEM: 213 case DataElement::TYPE_FILE_FILESYSTEM:
214 AddHTMLListItem(kType, "filesystem", out); 214 AddHTMLListItem(kType, "filesystem", out);
215 AddHTMLListItem(kURL, item.filesystem_url().spec(), out); 215 AddHTMLListItem(kURL, item.filesystem_url().spec(), out);
216 if (!item.expected_modification_time().is_null()) { 216 if (!item.expected_modification_time().is_null()) {
217 AddHTMLListItem(kModificationTime, base::UTF16ToUTF8( 217 AddHTMLListItem(kModificationTime, base::UTF16ToUTF8(
218 TimeFormatFriendlyDateAndTime(item.expected_modification_time())), 218 TimeFormatFriendlyDateAndTime(item.expected_modification_time())),
219 out); 219 out);
220 } 220 }
221 break; 221 break;
222 case BlobData::Item::TYPE_UNKNOWN: 222 case DataElement::TYPE_UNKNOWN:
223 NOTREACHED(); 223 NOTREACHED();
224 break; 224 break;
225 } 225 }
226 if (item.offset()) { 226 if (item.offset()) {
227 AddHTMLListItem(kOffset, base::UTF16ToUTF8(base::FormatNumber( 227 AddHTMLListItem(kOffset, base::UTF16ToUTF8(base::FormatNumber(
228 static_cast<int64>(item.offset()))), out); 228 static_cast<int64>(item.offset()))), out);
229 } 229 }
230 if (static_cast<int64>(item.length()) != -1) { 230 if (static_cast<int64>(item.length()) != -1) {
231 AddHTMLListItem(kLength, base::UTF16ToUTF8(base::FormatNumber( 231 AddHTMLListItem(kLength, base::UTF16ToUTF8(base::FormatNumber(
232 static_cast<int64>(item.length()))), out); 232 static_cast<int64>(item.length()))), out);
233 } 233 }
234 234
235 if (has_multi_items) 235 if (has_multi_items)
236 EndHTMLList(out); 236 EndHTMLList(out);
237 } 237 }
238 238
239 EndHTMLList(out); 239 EndHTMLList(out);
240 } 240 }
241 241
242 } // namespace storage 242 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698