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

Side by Side Diff: webkit/browser/appcache/appcache_service.cc

Issue 137493003: Appcache::OnCorruptionDetected handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 "webkit/browser/appcache/appcache_service.h" 5 #include "webkit/browser/appcache/appcache_service.h"
6 6
7 #include <functional> 7 #include <functional>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 check_result = AppCacheHistograms::UNEXPECTED_DATA_SIZE; 419 check_result = AppCacheHistograms::UNEXPECTED_DATA_SIZE;
420 else 420 else
421 check_result = AppCacheHistograms::RESPONSE_OK; 421 check_result = AppCacheHistograms::RESPONSE_OK;
422 AppCacheHistograms::CountCheckResponseResult(check_result); 422 AppCacheHistograms::CountCheckResponseResult(check_result);
423 423
424 if (check_result != AppCacheHistograms::RESPONSE_OK) 424 if (check_result != AppCacheHistograms::RESPONSE_OK)
425 service_->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); 425 service_->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback());
426 delete this; 426 delete this;
427 } 427 }
428 428
429
430 // AppCacheStorageReference ------ 429 // AppCacheStorageReference ------
431 430
432 AppCacheStorageReference::AppCacheStorageReference( 431 AppCacheStorageReference::AppCacheStorageReference(
433 scoped_ptr<AppCacheStorage> storage) 432 scoped_ptr<AppCacheStorage> storage)
434 : storage_(storage.Pass()) {} 433 : storage_(storage.Pass()) {}
435 AppCacheStorageReference::~AppCacheStorageReference() {} 434 AppCacheStorageReference::~AppCacheStorageReference() {}
436 435
437 // AppCacheService ------- 436 // AppCacheService -------
438 437
439 AppCacheService::AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy) 438 AppCacheService::AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy)
440 : appcache_policy_(NULL), quota_client_(NULL), handler_factory_(NULL), 439 : appcache_policy_(NULL), quota_client_(NULL), handler_factory_(NULL),
441 quota_manager_proxy_(quota_manager_proxy), 440 quota_manager_proxy_(quota_manager_proxy),
442 request_context_(NULL), 441 request_context_(NULL),
443 force_keep_session_state_(false), 442 force_keep_session_state_(false) {
444 was_reinitialized_(false) {
445 if (quota_manager_proxy_.get()) { 443 if (quota_manager_proxy_.get()) {
446 quota_client_ = new AppCacheQuotaClient(this); 444 quota_client_ = new AppCacheQuotaClient(this);
447 quota_manager_proxy_->RegisterClient(quota_client_); 445 quota_manager_proxy_->RegisterClient(quota_client_);
448 } 446 }
449 } 447 }
450 448
451 AppCacheService::~AppCacheService() { 449 AppCacheService::~AppCacheService() {
452 DCHECK(backends_.empty()); 450 DCHECK(backends_.empty());
453 std::for_each(pending_helpers_.begin(), 451 std::for_each(pending_helpers_.begin(),
454 pending_helpers_.end(), 452 pending_helpers_.end(),
(...skipping 12 matching lines...) Expand all
467 base::MessageLoopProxy* cache_thread) { 465 base::MessageLoopProxy* cache_thread) {
468 DCHECK(!storage_.get()); 466 DCHECK(!storage_.get());
469 cache_directory_ = cache_directory; 467 cache_directory_ = cache_directory;
470 db_thread_ = db_thread; 468 db_thread_ = db_thread;
471 cache_thread_ = cache_thread; 469 cache_thread_ = cache_thread;
472 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); 470 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this);
473 storage->Initialize(cache_directory, db_thread, cache_thread); 471 storage->Initialize(cache_directory, db_thread, cache_thread);
474 storage_.reset(storage); 472 storage_.reset(storage);
475 } 473 }
476 474
475 void AppCacheService::ScheduleReinitialize() {
476 if (reinit_timer_.IsRunning())
477 return;
478
479 // Reinitialization only happens when corruption has been noticed.
480 // We don't want to thrash the disk but we also don't want to
481 // leave the appcache disabled for an indefinite period of time. Some
482 // users never shutdown the browser.
483
484 const base::TimeDelta kZeroDelta;
485 const base::TimeDelta kOneHour(base::TimeDelta::FromHours(1));
486 const base::TimeDelta k30Seconds(base::TimeDelta::FromSeconds(30));
487
488 // If enough time has past since the last reinit, reset the delay.
489 if (next_reinit_delay_ != kZeroDelta &&
490 base::Time::Now() - last_reinit_time_ > kOneHour) {
491 next_reinit_delay_ = kZeroDelta;
492 }
493 reinit_timer_.Start(FROM_HERE, next_reinit_delay_,
494 this, &AppCacheService::Reinitialize);
495
496 // Adjust the delay for next time.
497 base::TimeDelta increment = std::max(k30Seconds, next_reinit_delay_);
498 next_reinit_delay_ = std::min(next_reinit_delay_ + increment, kOneHour);
499 }
500
477 void AppCacheService::Reinitialize() { 501 void AppCacheService::Reinitialize() {
478 AppCacheHistograms::CountReinitAttempt(was_reinitialized_); 502 AppCacheHistograms::CountReinitAttempt(!last_reinit_time_.is_null());
479 503 last_reinit_time_ = base::Time::Now();
480 // To avoid thrashing, we only do this once.
481 if (was_reinitialized_)
482 return;
483 was_reinitialized_ = true;
484 504
485 // Inform observers of about this and give them a chance to 505 // Inform observers of about this and give them a chance to
486 // defer deletion of the old storage object. 506 // defer deletion of the old storage object.
487 scoped_refptr<AppCacheStorageReference> 507 scoped_refptr<AppCacheStorageReference>
488 old_storage_ref(new AppCacheStorageReference(storage_.Pass())); 508 old_storage_ref(new AppCacheStorageReference(storage_.Pass()));
489 FOR_EACH_OBSERVER(Observer, observers_, 509 FOR_EACH_OBSERVER(Observer, observers_,
490 OnServiceReinitialized(old_storage_ref.get())); 510 OnServiceReinitialized(old_storage_ref.get()));
491 511
492 Initialize(cache_directory_, db_thread_, cache_thread_); 512 Initialize(cache_directory_, db_thread_, cache_thread_);
493 } 513 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 backends_.insert( 561 backends_.insert(
542 BackendMap::value_type(backend_impl->process_id(), backend_impl)); 562 BackendMap::value_type(backend_impl->process_id(), backend_impl));
543 } 563 }
544 564
545 void AppCacheService::UnregisterBackend( 565 void AppCacheService::UnregisterBackend(
546 AppCacheBackendImpl* backend_impl) { 566 AppCacheBackendImpl* backend_impl) {
547 backends_.erase(backend_impl->process_id()); 567 backends_.erase(backend_impl->process_id());
548 } 568 }
549 569
550 } // namespace appcache 570 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698