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

Side by Side Diff: content/browser/appcache/view_appcache_internals_job.cc

Issue 667943003: Standardize usage of virtual/override/final in content/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/appcache/view_appcache_internals_job.h" 5 #include "content/browser/appcache/view_appcache_internals_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 protected: 314 protected:
315 BaseInternalsJob(net::URLRequest* request, 315 BaseInternalsJob(net::URLRequest* request,
316 net::NetworkDelegate* network_delegate, 316 net::NetworkDelegate* network_delegate,
317 AppCacheServiceImpl* service) 317 AppCacheServiceImpl* service)
318 : URLRequestSimpleJob(request, network_delegate), 318 : URLRequestSimpleJob(request, network_delegate),
319 appcache_service_(service), 319 appcache_service_(service),
320 appcache_storage_(service->storage()) { 320 appcache_storage_(service->storage()) {
321 appcache_service_->AddObserver(this); 321 appcache_service_->AddObserver(this);
322 } 322 }
323 323
324 virtual ~BaseInternalsJob() { 324 ~BaseInternalsJob() override { appcache_service_->RemoveObserver(this); }
325 appcache_service_->RemoveObserver(this);
326 }
327 325
328 virtual void OnServiceReinitialized( 326 void OnServiceReinitialized(
329 AppCacheStorageReference* old_storage_ref) override { 327 AppCacheStorageReference* old_storage_ref) override {
330 if (old_storage_ref->storage() == appcache_storage_) 328 if (old_storage_ref->storage() == appcache_storage_)
331 disabled_storage_reference_ = old_storage_ref; 329 disabled_storage_reference_ = old_storage_ref;
332 } 330 }
333 331
334 AppCacheServiceImpl* appcache_service_; 332 AppCacheServiceImpl* appcache_service_;
335 AppCacheStorage* appcache_storage_; 333 AppCacheStorage* appcache_storage_;
336 scoped_refptr<AppCacheStorageReference> disabled_storage_reference_; 334 scoped_refptr<AppCacheStorageReference> disabled_storage_reference_;
337 }; 335 };
338 336
339 // Job that lists all appcaches in the system. 337 // Job that lists all appcaches in the system.
340 class MainPageJob : public BaseInternalsJob { 338 class MainPageJob : public BaseInternalsJob {
341 public: 339 public:
342 MainPageJob(net::URLRequest* request, 340 MainPageJob(net::URLRequest* request,
343 net::NetworkDelegate* network_delegate, 341 net::NetworkDelegate* network_delegate,
344 AppCacheServiceImpl* service) 342 AppCacheServiceImpl* service)
345 : BaseInternalsJob(request, network_delegate, service), 343 : BaseInternalsJob(request, network_delegate, service),
346 weak_factory_(this) { 344 weak_factory_(this) {
347 } 345 }
348 346
349 virtual void Start() override { 347 void Start() override {
350 DCHECK(request_); 348 DCHECK(request_);
351 info_collection_ = new AppCacheInfoCollection; 349 info_collection_ = new AppCacheInfoCollection;
352 appcache_service_->GetAllAppCacheInfo( 350 appcache_service_->GetAllAppCacheInfo(
353 info_collection_.get(), 351 info_collection_.get(),
354 base::Bind(&MainPageJob::OnGotInfoComplete, 352 base::Bind(&MainPageJob::OnGotInfoComplete,
355 weak_factory_.GetWeakPtr())); 353 weak_factory_.GetWeakPtr()));
356 } 354 }
357 355
358 // Produces a page containing the listing 356 // Produces a page containing the listing
359 virtual int GetData(std::string* mime_type, 357 int GetData(std::string* mime_type,
360 std::string* charset, 358 std::string* charset,
361 std::string* out, 359 std::string* out,
362 const net::CompletionCallback& callback) const override { 360 const net::CompletionCallback& callback) const override {
363 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed. 361 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed.
364 tracked_objects::ScopedProfile tracking_profile( 362 tracked_objects::ScopedProfile tracking_profile(
365 FROM_HERE_WITH_EXPLICIT_FUNCTION("422489 MainPageJob::GetData")); 363 FROM_HERE_WITH_EXPLICIT_FUNCTION("422489 MainPageJob::GetData"));
366 364
367 mime_type->assign("text/html"); 365 mime_type->assign("text/html");
368 charset->assign("UTF-8"); 366 charset->assign("UTF-8");
369 367
370 out->clear(); 368 out->clear();
371 EmitPageStart(out); 369 EmitPageStart(out);
372 if (!info_collection_.get()) { 370 if (!info_collection_.get()) {
(...skipping 12 matching lines...) Expand all
385 std::sort(appcaches.begin(), appcaches.end(), SortByManifestUrl); 383 std::sort(appcaches.begin(), appcaches.end(), SortByManifestUrl);
386 384
387 GURL base_url = ClearQuery(request_->url()); 385 GURL base_url = ClearQuery(request_->url());
388 EmitAppCacheInfoVector(base_url, appcache_service_, appcaches, out); 386 EmitAppCacheInfoVector(base_url, appcache_service_, appcaches, out);
389 } 387 }
390 EmitPageEnd(out); 388 EmitPageEnd(out);
391 return net::OK; 389 return net::OK;
392 } 390 }
393 391
394 private: 392 private:
395 virtual ~MainPageJob() {} 393 ~MainPageJob() override {}
396 394
397 void OnGotInfoComplete(int rv) { 395 void OnGotInfoComplete(int rv) {
398 if (rv != net::OK) 396 if (rv != net::OK)
399 info_collection_ = NULL; 397 info_collection_ = NULL;
400 StartAsync(); 398 StartAsync();
401 } 399 }
402 400
403 scoped_refptr<AppCacheInfoCollection> info_collection_; 401 scoped_refptr<AppCacheInfoCollection> info_collection_;
404 base::WeakPtrFactory<MainPageJob> weak_factory_; 402 base::WeakPtrFactory<MainPageJob> weak_factory_;
405 DISALLOW_COPY_AND_ASSIGN(MainPageJob); 403 DISALLOW_COPY_AND_ASSIGN(MainPageJob);
406 }; 404 };
407 405
408 // Job that redirects back to the main appcache internals page. 406 // Job that redirects back to the main appcache internals page.
409 class RedirectToMainPageJob : public BaseInternalsJob { 407 class RedirectToMainPageJob : public BaseInternalsJob {
410 public: 408 public:
411 RedirectToMainPageJob(net::URLRequest* request, 409 RedirectToMainPageJob(net::URLRequest* request,
412 net::NetworkDelegate* network_delegate, 410 net::NetworkDelegate* network_delegate,
413 AppCacheServiceImpl* service) 411 AppCacheServiceImpl* service)
414 : BaseInternalsJob(request, network_delegate, service) {} 412 : BaseInternalsJob(request, network_delegate, service) {}
415 413
416 virtual int GetData(std::string* mime_type, 414 int GetData(std::string* mime_type,
417 std::string* charset, 415 std::string* charset,
418 std::string* data, 416 std::string* data,
419 const net::CompletionCallback& callback) const override { 417 const net::CompletionCallback& callback) const override {
420 return net::OK; // IsRedirectResponse induces a redirect. 418 return net::OK; // IsRedirectResponse induces a redirect.
421 } 419 }
422 420
423 virtual bool IsRedirectResponse(GURL* location, 421 bool IsRedirectResponse(GURL* location, int* http_status_code) override {
424 int* http_status_code) override {
425 *location = ClearQuery(request_->url()); 422 *location = ClearQuery(request_->url());
426 *http_status_code = 307; 423 *http_status_code = 307;
427 return true; 424 return true;
428 } 425 }
429 426
430 protected: 427 protected:
431 virtual ~RedirectToMainPageJob() {} 428 ~RedirectToMainPageJob() override {}
432 }; 429 };
433 430
434 // Job that removes an appcache and then redirects back to the main page. 431 // Job that removes an appcache and then redirects back to the main page.
435 class RemoveAppCacheJob : public RedirectToMainPageJob { 432 class RemoveAppCacheJob : public RedirectToMainPageJob {
436 public: 433 public:
437 RemoveAppCacheJob( 434 RemoveAppCacheJob(
438 net::URLRequest* request, 435 net::URLRequest* request,
439 net::NetworkDelegate* network_delegate, 436 net::NetworkDelegate* network_delegate,
440 AppCacheServiceImpl* service, 437 AppCacheServiceImpl* service,
441 const GURL& manifest_url) 438 const GURL& manifest_url)
442 : RedirectToMainPageJob(request, network_delegate, service), 439 : RedirectToMainPageJob(request, network_delegate, service),
443 manifest_url_(manifest_url), 440 manifest_url_(manifest_url),
444 weak_factory_(this) { 441 weak_factory_(this) {
445 } 442 }
446 443
447 virtual void Start() override { 444 void Start() override {
448 DCHECK(request_); 445 DCHECK(request_);
449 446
450 appcache_service_->DeleteAppCacheGroup( 447 appcache_service_->DeleteAppCacheGroup(
451 manifest_url_,base::Bind(&RemoveAppCacheJob::OnDeleteAppCacheComplete, 448 manifest_url_,base::Bind(&RemoveAppCacheJob::OnDeleteAppCacheComplete,
452 weak_factory_.GetWeakPtr())); 449 weak_factory_.GetWeakPtr()));
453 } 450 }
454 451
455 private: 452 private:
456 virtual ~RemoveAppCacheJob() {} 453 ~RemoveAppCacheJob() override {}
457 454
458 void OnDeleteAppCacheComplete(int rv) { 455 void OnDeleteAppCacheComplete(int rv) {
459 StartAsync(); // Causes the base class to redirect. 456 StartAsync(); // Causes the base class to redirect.
460 } 457 }
461 458
462 GURL manifest_url_; 459 GURL manifest_url_;
463 base::WeakPtrFactory<RemoveAppCacheJob> weak_factory_; 460 base::WeakPtrFactory<RemoveAppCacheJob> weak_factory_;
464 }; 461 };
465 462
466 463
467 // Job shows the details of a particular manifest url. 464 // Job shows the details of a particular manifest url.
468 class ViewAppCacheJob : public BaseInternalsJob, 465 class ViewAppCacheJob : public BaseInternalsJob,
469 public AppCacheStorage::Delegate { 466 public AppCacheStorage::Delegate {
470 public: 467 public:
471 ViewAppCacheJob( 468 ViewAppCacheJob(
472 net::URLRequest* request, 469 net::URLRequest* request,
473 net::NetworkDelegate* network_delegate, 470 net::NetworkDelegate* network_delegate,
474 AppCacheServiceImpl* service, 471 AppCacheServiceImpl* service,
475 const GURL& manifest_url) 472 const GURL& manifest_url)
476 : BaseInternalsJob(request, network_delegate, service), 473 : BaseInternalsJob(request, network_delegate, service),
477 manifest_url_(manifest_url) {} 474 manifest_url_(manifest_url) {}
478 475
479 virtual void Start() override { 476 void Start() override {
480 DCHECK(request_); 477 DCHECK(request_);
481 appcache_storage_->LoadOrCreateGroup(manifest_url_, this); 478 appcache_storage_->LoadOrCreateGroup(manifest_url_, this);
482 } 479 }
483 480
484 // Produces a page containing the entries listing. 481 // Produces a page containing the entries listing.
485 virtual int GetData(std::string* mime_type, 482 int GetData(std::string* mime_type,
486 std::string* charset, 483 std::string* charset,
487 std::string* out, 484 std::string* out,
488 const net::CompletionCallback& callback) const override { 485 const net::CompletionCallback& callback) const override {
489 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed. 486 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed.
490 tracked_objects::ScopedProfile tracking_profile( 487 tracked_objects::ScopedProfile tracking_profile(
491 FROM_HERE_WITH_EXPLICIT_FUNCTION("422489 ViewAppCacheJob::GetData")); 488 FROM_HERE_WITH_EXPLICIT_FUNCTION("422489 ViewAppCacheJob::GetData"));
492 489
493 mime_type->assign("text/html"); 490 mime_type->assign("text/html");
494 charset->assign("UTF-8"); 491 charset->assign("UTF-8");
495 out->clear(); 492 out->clear();
496 EmitPageStart(out); 493 EmitPageStart(out);
497 if (appcache_info_.manifest_url.is_empty()) { 494 if (appcache_info_.manifest_url.is_empty()) {
498 out->append(kManifestNotFoundMessage); 495 out->append(kManifestNotFoundMessage);
499 } else { 496 } else {
500 GURL base_url = ClearQuery(request_->url()); 497 GURL base_url = ClearQuery(request_->url());
501 EmitAppCacheInfo(base_url, appcache_service_, &appcache_info_, out); 498 EmitAppCacheInfo(base_url, appcache_service_, &appcache_info_, out);
502 EmitAppCacheResourceInfoVector(base_url, 499 EmitAppCacheResourceInfoVector(base_url,
503 manifest_url_, 500 manifest_url_,
504 resource_infos_, 501 resource_infos_,
505 appcache_info_.group_id, 502 appcache_info_.group_id,
506 out); 503 out);
507 } 504 }
508 EmitPageEnd(out); 505 EmitPageEnd(out);
509 return net::OK; 506 return net::OK;
510 } 507 }
511 508
512 private: 509 private:
513 virtual ~ViewAppCacheJob() { 510 ~ViewAppCacheJob() override {
514 appcache_storage_->CancelDelegateCallbacks(this); 511 appcache_storage_->CancelDelegateCallbacks(this);
515 } 512 }
516 513
517 // AppCacheStorage::Delegate override 514 // AppCacheStorage::Delegate override
518 virtual void OnGroupLoaded( 515 void OnGroupLoaded(AppCacheGroup* group, const GURL& manifest_url) override {
519 AppCacheGroup* group, const GURL& manifest_url) override {
520 DCHECK_EQ(manifest_url_, manifest_url); 516 DCHECK_EQ(manifest_url_, manifest_url);
521 if (group && group->newest_complete_cache()) { 517 if (group && group->newest_complete_cache()) {
522 appcache_info_.manifest_url = manifest_url; 518 appcache_info_.manifest_url = manifest_url;
523 appcache_info_.group_id = group->group_id(); 519 appcache_info_.group_id = group->group_id();
524 appcache_info_.size = group->newest_complete_cache()->cache_size(); 520 appcache_info_.size = group->newest_complete_cache()->cache_size();
525 appcache_info_.creation_time = group->creation_time(); 521 appcache_info_.creation_time = group->creation_time();
526 appcache_info_.last_update_time = 522 appcache_info_.last_update_time =
527 group->newest_complete_cache()->update_time(); 523 group->newest_complete_cache()->update_time();
528 appcache_info_.last_access_time = base::Time::Now(); 524 appcache_info_.last_access_time = base::Time::Now();
529 group->newest_complete_cache()->ToResourceInfoVector(&resource_infos_); 525 group->newest_complete_cache()->ToResourceInfoVector(&resource_infos_);
(...skipping 18 matching lines...) Expand all
548 net::NetworkDelegate* network_delegate, 544 net::NetworkDelegate* network_delegate,
549 AppCacheServiceImpl* service, 545 AppCacheServiceImpl* service,
550 const GURL& manifest_url, 546 const GURL& manifest_url,
551 const GURL& entry_url, 547 const GURL& entry_url,
552 int64 response_id, int64 group_id) 548 int64 response_id, int64 group_id)
553 : BaseInternalsJob(request, network_delegate, service), 549 : BaseInternalsJob(request, network_delegate, service),
554 manifest_url_(manifest_url), entry_url_(entry_url), 550 manifest_url_(manifest_url), entry_url_(entry_url),
555 response_id_(response_id), group_id_(group_id), amount_read_(0) { 551 response_id_(response_id), group_id_(group_id), amount_read_(0) {
556 } 552 }
557 553
558 virtual void Start() override { 554 void Start() override {
559 DCHECK(request_); 555 DCHECK(request_);
560 appcache_storage_->LoadResponseInfo( 556 appcache_storage_->LoadResponseInfo(
561 manifest_url_, group_id_, response_id_, this); 557 manifest_url_, group_id_, response_id_, this);
562 } 558 }
563 559
564 // Produces a page containing the response headers and data. 560 // Produces a page containing the response headers and data.
565 virtual int GetData(std::string* mime_type, 561 int GetData(std::string* mime_type,
566 std::string* charset, 562 std::string* charset,
567 std::string* out, 563 std::string* out,
568 const net::CompletionCallback& callback) const override { 564 const net::CompletionCallback& callback) const override {
569 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed. 565 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed.
570 tracked_objects::ScopedProfile tracking_profile( 566 tracked_objects::ScopedProfile tracking_profile(
571 FROM_HERE_WITH_EXPLICIT_FUNCTION("422489 ViewEntryJob::GetData")); 567 FROM_HERE_WITH_EXPLICIT_FUNCTION("422489 ViewEntryJob::GetData"));
572 568
573 mime_type->assign("text/html"); 569 mime_type->assign("text/html");
574 charset->assign("UTF-8"); 570 charset->assign("UTF-8");
575 out->clear(); 571 out->clear();
576 EmitPageStart(out); 572 EmitPageStart(out);
577 EmitAnchor(entry_url_.spec(), entry_url_.spec(), out); 573 EmitAnchor(entry_url_.spec(), entry_url_.spec(), out);
578 out->append("<br/>\n"); 574 out->append("<br/>\n");
(...skipping 13 matching lines...) Expand all
592 out->append("Failed to read response data.<br>"); 588 out->append("Failed to read response data.<br>");
593 } 589 }
594 } else { 590 } else {
595 out->append("Failed to read response headers and data.<br>"); 591 out->append("Failed to read response headers and data.<br>");
596 } 592 }
597 EmitPageEnd(out); 593 EmitPageEnd(out);
598 return net::OK; 594 return net::OK;
599 } 595 }
600 596
601 private: 597 private:
602 virtual ~ViewEntryJob() { 598 ~ViewEntryJob() override { appcache_storage_->CancelDelegateCallbacks(this); }
603 appcache_storage_->CancelDelegateCallbacks(this);
604 }
605 599
606 virtual void OnResponseInfoLoaded( 600 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info,
607 AppCacheResponseInfo* response_info, int64 response_id) override { 601 int64 response_id) override {
608 if (!response_info) { 602 if (!response_info) {
609 StartAsync(); 603 StartAsync();
610 return; 604 return;
611 } 605 }
612 response_info_ = response_info; 606 response_info_ = response_info;
613 607
614 // Read the response data, truncating if its too large. 608 // Read the response data, truncating if its too large.
615 const int64 kLimit = 100 * 1000; 609 const int64 kLimit = 100 * 1000;
616 int64 amount_to_read = 610 int64 amount_to_read =
617 std::min(kLimit, response_info->response_data_size()); 611 std::min(kLimit, response_info->response_data_size());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 return new ViewEntryJob(request, network_delegate, service, 667 return new ViewEntryJob(request, network_delegate, service,
674 DecodeBase64URL(tokens[0]), // manifest url 668 DecodeBase64URL(tokens[0]), // manifest url
675 DecodeBase64URL(tokens[1]), // entry url 669 DecodeBase64URL(tokens[1]), // entry url
676 response_id, group_id); 670 response_id, group_id);
677 } 671 }
678 672
679 return new RedirectToMainPageJob(request, network_delegate, service); 673 return new RedirectToMainPageJob(request, network_delegate, service);
680 } 674 }
681 675
682 } // namespace content 676 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698