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

Side by Side Diff: webkit/appcache/view_appcache_internals_job.cc

Issue 8343018: More groundwork for flat file based response storage. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « webkit/appcache/mock_appcache_storage_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "webkit/appcache/view_appcache_internals_job.h" 8 #include "webkit/appcache/view_appcache_internals_job.h"
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 str.append("Fallback, "); 178 str.append("Fallback, ");
179 if (info.is_explicit) 179 if (info.is_explicit)
180 str.append("Explicit, "); 180 str.append("Explicit, ");
181 if (info.is_foreign) 181 if (info.is_foreign)
182 str.append("Foreign, "); 182 str.append("Foreign, ");
183 return str; 183 return str;
184 } 184 }
185 185
186 std::string FormViewEntryAnchor(const GURL& base_url, 186 std::string FormViewEntryAnchor(const GURL& base_url,
187 const GURL& manifest_url, const GURL& entry_url, 187 const GURL& manifest_url, const GURL& entry_url,
188 int64 response_id) { 188 int64 response_id,
189 int64 group_id) {
189 std::string manifest_url_base64; 190 std::string manifest_url_base64;
190 std::string entry_url_base64; 191 std::string entry_url_base64;
191 std::string response_id_string; 192 std::string response_id_string;
193 std::string group_id_string;
192 base::Base64Encode(manifest_url.spec(), &manifest_url_base64); 194 base::Base64Encode(manifest_url.spec(), &manifest_url_base64);
193 base::Base64Encode(entry_url.spec(), &entry_url_base64); 195 base::Base64Encode(entry_url.spec(), &entry_url_base64);
194 response_id_string = base::Int64ToString(response_id); 196 response_id_string = base::Int64ToString(response_id);
197 group_id_string = base::Int64ToString(group_id);
195 198
196 std::string query(kViewEntryCommand); 199 std::string query(kViewEntryCommand);
197 query.push_back('='); 200 query.push_back('=');
198 query.append(manifest_url_base64); 201 query.append(manifest_url_base64);
199 query.push_back('|'); 202 query.push_back('|');
200 query.append(entry_url_base64); 203 query.append(entry_url_base64);
201 query.push_back('|'); 204 query.push_back('|');
202 query.append(response_id_string); 205 query.append(response_id_string);
206 query.push_back('|');
207 query.append(group_id_string);
203 208
204 GURL::Replacements replacements; 209 GURL::Replacements replacements;
205 replacements.SetQuery(query.data(), 210 replacements.SetQuery(query.data(),
206 url_parse::Component(0, query.length())); 211 url_parse::Component(0, query.length()));
207 GURL view_entry_url = base_url.ReplaceComponents(replacements); 212 GURL view_entry_url = base_url.ReplaceComponents(replacements);
208 213
209 std::string anchor; 214 std::string anchor;
210 EmitAnchor(view_entry_url.spec(), entry_url.spec(), &anchor); 215 EmitAnchor(view_entry_url.spec(), entry_url.spec(), &anchor);
211 return anchor; 216 return anchor;
212 } 217 }
213 218
214 void EmitAppCacheResourceInfoVector( 219 void EmitAppCacheResourceInfoVector(
215 const GURL& base_url, 220 const GURL& base_url,
216 const GURL& manifest_url, 221 const GURL& manifest_url,
217 const AppCacheResourceInfoVector& resource_infos, 222 const AppCacheResourceInfoVector& resource_infos,
223 int64 group_id,
218 std::string* out) { 224 std::string* out) {
219 out->append("<table border='0'>\n"); 225 out->append("<table border='0'>\n");
220 out->append("<tr>"); 226 out->append("<tr>");
221 EmitTableData("Flags", false, true, out); 227 EmitTableData("Flags", false, true, out);
222 EmitTableData("URL", false, true, out); 228 EmitTableData("URL", false, true, out);
223 EmitTableData("Size (headers and data)", true, true, out); 229 EmitTableData("Size (headers and data)", true, true, out);
224 out->append("</tr>\n"); 230 out->append("</tr>\n");
225 for (AppCacheResourceInfoVector::const_iterator 231 for (AppCacheResourceInfoVector::const_iterator
226 iter = resource_infos.begin(); 232 iter = resource_infos.begin();
227 iter != resource_infos.end(); ++iter) { 233 iter != resource_infos.end(); ++iter) {
228 out->append("<tr>"); 234 out->append("<tr>");
229 EmitTableData(FormFlagsString(*iter), false, false, out); 235 EmitTableData(FormFlagsString(*iter), false, false, out);
230 EmitTableData(FormViewEntryAnchor(base_url, manifest_url, 236 EmitTableData(FormViewEntryAnchor(base_url, manifest_url,
231 iter->url, iter->response_id), 237 iter->url, iter->response_id,
238 group_id),
232 false, false, out); 239 false, false, out);
233 EmitTableData(UTF16ToUTF8(FormatBytesUnlocalized(iter->size)), 240 EmitTableData(UTF16ToUTF8(FormatBytesUnlocalized(iter->size)),
234 true, false, out); 241 true, false, out);
235 out->append("</tr>\n"); 242 out->append("</tr>\n");
236 } 243 }
237 out->append("</table>\n"); 244 out->append("</table>\n");
238 } 245 }
239 246
240 void EmitResponseHeaders(net::HttpResponseHeaders* headers, std::string* out) { 247 void EmitResponseHeaders(net::HttpResponseHeaders* headers, std::string* out) {
241 out->append("<hr><pre>"); 248 out->append("<hr><pre>");
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 charset->assign("UTF-8"); 455 charset->assign("UTF-8");
449 out->clear(); 456 out->clear();
450 EmitPageStart(out); 457 EmitPageStart(out);
451 if (appcache_info_.manifest_url.is_empty()) { 458 if (appcache_info_.manifest_url.is_empty()) {
452 out->append(kManifestNotFoundMessage); 459 out->append(kManifestNotFoundMessage);
453 } else { 460 } else {
454 GURL base_url = ClearQuery(request_->url()); 461 GURL base_url = ClearQuery(request_->url());
455 EmitAppCacheInfo(base_url, appcache_service_, &appcache_info_, out); 462 EmitAppCacheInfo(base_url, appcache_service_, &appcache_info_, out);
456 EmitAppCacheResourceInfoVector(base_url, 463 EmitAppCacheResourceInfoVector(base_url,
457 manifest_url_, 464 manifest_url_,
458 resource_infos_, out); 465 resource_infos_,
466 appcache_info_.group_id,
467 out);
459 } 468 }
460 EmitPageEnd(out); 469 EmitPageEnd(out);
461 return true; 470 return true;
462 } 471 }
463 472
464 private: 473 private:
465 virtual ~ViewAppCacheJob() { 474 virtual ~ViewAppCacheJob() {
466 appcache_service_->storage()->CancelDelegateCallbacks(this); 475 appcache_service_->storage()->CancelDelegateCallbacks(this);
467 } 476 }
468 477
469 // AppCacheStorage::Delegate override 478 // AppCacheStorage::Delegate override
470 virtual void OnGroupLoaded( 479 virtual void OnGroupLoaded(
471 AppCacheGroup* group, const GURL& manifest_url) OVERRIDE { 480 AppCacheGroup* group, const GURL& manifest_url) OVERRIDE {
472 DCHECK_EQ(manifest_url_, manifest_url); 481 DCHECK_EQ(manifest_url_, manifest_url);
473 if (group && group->newest_complete_cache()) { 482 if (group && group->newest_complete_cache()) {
474 appcache_info_.manifest_url = manifest_url; 483 appcache_info_.manifest_url = manifest_url;
484 appcache_info_.group_id = group->group_id();
475 appcache_info_.size = group->newest_complete_cache()->cache_size(); 485 appcache_info_.size = group->newest_complete_cache()->cache_size();
476 appcache_info_.creation_time = group->creation_time(); 486 appcache_info_.creation_time = group->creation_time();
477 appcache_info_.last_update_time = 487 appcache_info_.last_update_time =
478 group->newest_complete_cache()->update_time(); 488 group->newest_complete_cache()->update_time();
479 appcache_info_.last_access_time = base::Time::Now(); 489 appcache_info_.last_access_time = base::Time::Now();
480 group->newest_complete_cache()->ToResourceInfoVector(&resource_infos_); 490 group->newest_complete_cache()->ToResourceInfoVector(&resource_infos_);
481 std::sort(resource_infos_.begin(), resource_infos_.end(), 491 std::sort(resource_infos_.begin(), resource_infos_.end(),
482 SortByResourceUrl); 492 SortByResourceUrl);
483 } 493 }
484 StartAsync(); 494 StartAsync();
485 } 495 }
486 496
487 GURL manifest_url_; 497 GURL manifest_url_;
488 AppCacheInfo appcache_info_; 498 AppCacheInfo appcache_info_;
489 AppCacheResourceInfoVector resource_infos_; 499 AppCacheResourceInfoVector resource_infos_;
490 DISALLOW_COPY_AND_ASSIGN(ViewAppCacheJob); 500 DISALLOW_COPY_AND_ASSIGN(ViewAppCacheJob);
491 }; 501 };
492 502
493 // Job that shows the details of a particular cached resource. 503 // Job that shows the details of a particular cached resource.
494 class ViewEntryJob : public BaseInternalsJob, 504 class ViewEntryJob : public BaseInternalsJob,
495 public AppCacheStorage::Delegate { 505 public AppCacheStorage::Delegate {
496 public: 506 public:
497 ViewEntryJob( 507 ViewEntryJob(
498 net::URLRequest* request, AppCacheService* service, 508 net::URLRequest* request, AppCacheService* service,
499 const GURL& manifest_url, const GURL& entry_url, 509 const GURL& manifest_url, const GURL& entry_url,
500 int64 response_id) 510 int64 response_id, int64 group_id)
501 : BaseInternalsJob(request, service), 511 : BaseInternalsJob(request, service),
502 manifest_url_(manifest_url), entry_url_(entry_url), 512 manifest_url_(manifest_url), entry_url_(entry_url),
503 response_id_(response_id), amount_read_(0), 513 response_id_(response_id), group_id_(group_id), amount_read_(0),
504 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( 514 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
505 this, &ViewEntryJob::OnReadComplete)) {} 515 this, &ViewEntryJob::OnReadComplete)) {}
506 516
507 virtual void Start() { 517 virtual void Start() {
508 DCHECK(request_); 518 DCHECK(request_);
509 appcache_service_->storage()->LoadResponseInfo( 519 appcache_service_->storage()->LoadResponseInfo(
510 manifest_url_, response_id_, this); 520 manifest_url_, group_id_, response_id_, this);
511 } 521 }
512 522
513 // Produces a page containing the response headers and data. 523 // Produces a page containing the response headers and data.
514 virtual bool GetData(std::string* mime_type, 524 virtual bool GetData(std::string* mime_type,
515 std::string* charset, 525 std::string* charset,
516 std::string* out) const { 526 std::string* out) const {
517 mime_type->assign("text/html"); 527 mime_type->assign("text/html");
518 charset->assign("UTF-8"); 528 charset->assign("UTF-8");
519 out->clear(); 529 out->clear();
520 EmitPageStart(out); 530 EmitPageStart(out);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 } 562 }
553 response_info_ = response_info; 563 response_info_ = response_info;
554 564
555 // Read the response data, truncating if its too large. 565 // Read the response data, truncating if its too large.
556 const int64 kLimit = 100 * 1000; 566 const int64 kLimit = 100 * 1000;
557 int64 amount_to_read = 567 int64 amount_to_read =
558 std::min(kLimit, response_info->response_data_size()); 568 std::min(kLimit, response_info->response_data_size());
559 response_data_ = new net::IOBuffer(amount_to_read); 569 response_data_ = new net::IOBuffer(amount_to_read);
560 570
561 reader_.reset(appcache_service_->storage()->CreateResponseReader( 571 reader_.reset(appcache_service_->storage()->CreateResponseReader(
562 manifest_url_, response_id_)); 572 manifest_url_, group_id_, response_id_));
563 reader_->ReadData( 573 reader_->ReadData(
564 response_data_, amount_to_read, &read_callback_); 574 response_data_, amount_to_read, &read_callback_);
565 } 575 }
566 576
567 void OnReadComplete(int result) { 577 void OnReadComplete(int result) {
568 reader_.reset(); 578 reader_.reset();
569 amount_read_ = result; 579 amount_read_ = result;
570 if (result < 0) 580 if (result < 0)
571 response_data_ = NULL; 581 response_data_ = NULL;
572 StartAsync(); 582 StartAsync();
573 } 583 }
574 584
575 GURL manifest_url_; 585 GURL manifest_url_;
576 GURL entry_url_; 586 GURL entry_url_;
577 int64 response_id_; 587 int64 response_id_;
588 int64 group_id_;
578 scoped_refptr<AppCacheResponseInfo> response_info_; 589 scoped_refptr<AppCacheResponseInfo> response_info_;
579 scoped_refptr<net::IOBuffer> response_data_; 590 scoped_refptr<net::IOBuffer> response_data_;
580 int amount_read_; 591 int amount_read_;
581 scoped_ptr<AppCacheResponseReader> reader_; 592 scoped_ptr<AppCacheResponseReader> reader_;
582 net::OldCompletionCallbackImpl<ViewEntryJob> read_callback_; 593 net::OldCompletionCallbackImpl<ViewEntryJob> read_callback_;
583 }; 594 };
584 595
585 } // namespace 596 } // namespace
586 597
587 net::URLRequestJob* ViewAppCacheInternalsJobFactory::CreateJobForRequest( 598 net::URLRequestJob* ViewAppCacheInternalsJobFactory::CreateJobForRequest(
588 net::URLRequest* request, AppCacheService* service) { 599 net::URLRequest* request, AppCacheService* service) {
589 if (!request->url().has_query()) 600 if (!request->url().has_query())
590 return new MainPageJob(request, service); 601 return new MainPageJob(request, service);
591 602
592 std::string command; 603 std::string command;
593 std::string param; 604 std::string param;
594 ParseQuery(request->url().query(), &command, &param); 605 ParseQuery(request->url().query(), &command, &param);
595 606
596 if (command == kRemoveCacheCommand) 607 if (command == kRemoveCacheCommand)
597 return new RemoveAppCacheJob(request, service, 608 return new RemoveAppCacheJob(request, service,
598 DecodeBase64URL(param)); 609 DecodeBase64URL(param));
599 610
600 if (command == kViewCacheCommand) 611 if (command == kViewCacheCommand)
601 return new ViewAppCacheJob(request, service, 612 return new ViewAppCacheJob(request, service,
602 DecodeBase64URL(param)); 613 DecodeBase64URL(param));
603 614
604 std::vector<std::string> tokens; 615 std::vector<std::string> tokens;
605 int64 response_id; 616 int64 response_id;
606 if (command == kViewEntryCommand && 617 int64 group_id;
607 Tokenize(param, "|", &tokens) == 3u && 618 if (command == kViewEntryCommand && Tokenize(param, "|", &tokens) == 4u &&
608 base::StringToInt64(tokens[2], &response_id)) { 619 base::StringToInt64(tokens[2], &response_id) &&
620 base::StringToInt64(tokens[3], &group_id)) {
609 return new ViewEntryJob(request, service, 621 return new ViewEntryJob(request, service,
610 DecodeBase64URL(tokens[0]), // manifest url 622 DecodeBase64URL(tokens[0]), // manifest url
611 DecodeBase64URL(tokens[1]), // entry url 623 DecodeBase64URL(tokens[1]), // entry url
612 response_id); 624 response_id, group_id);
613 } 625 }
614 626
615 return new RedirectToMainPageJob(request, service); 627 return new RedirectToMainPageJob(request, service);
616 } 628 }
617 629
618 } // namespace appcache 630 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/mock_appcache_storage_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698