 Chromium Code Reviews
 Chromium Code Reviews Issue 137493003:
  Appcache::OnCorruptionDetected handling  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 137493003:
  Appcache::OnCorruptionDetected handling  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 "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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 check_result = AppCacheHistograms::UNEXPECTED_DATA_SIZE; | 418 check_result = AppCacheHistograms::UNEXPECTED_DATA_SIZE; | 
| 419 else | 419 else | 
| 420 check_result = AppCacheHistograms::RESPONSE_OK; | 420 check_result = AppCacheHistograms::RESPONSE_OK; | 
| 421 AppCacheHistograms::CountCheckResponseResult(check_result); | 421 AppCacheHistograms::CountCheckResponseResult(check_result); | 
| 422 | 422 | 
| 423 if (check_result != AppCacheHistograms::RESPONSE_OK) | 423 if (check_result != AppCacheHistograms::RESPONSE_OK) | 
| 424 service_->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); | 424 service_->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); | 
| 425 delete this; | 425 delete this; | 
| 426 } | 426 } | 
| 427 | 427 | 
| 428 | |
| 429 // AppCacheStorageReference ------ | 428 // AppCacheStorageReference ------ | 
| 430 | 429 | 
| 431 AppCacheStorageReference::AppCacheStorageReference( | 430 AppCacheStorageReference::AppCacheStorageReference( | 
| 432 scoped_ptr<AppCacheStorage> storage) | 431 scoped_ptr<AppCacheStorage> storage) | 
| 433 : storage_(storage.Pass()) {} | 432 : storage_(storage.Pass()) {} | 
| 434 AppCacheStorageReference::~AppCacheStorageReference() {} | 433 AppCacheStorageReference::~AppCacheStorageReference() {} | 
| 435 | 434 | 
| 436 // AppCacheService ------- | 435 // AppCacheService ------- | 
| 437 | 436 | 
| 438 AppCacheService::AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy) | 437 AppCacheService::AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy) | 
| 439 : appcache_policy_(NULL), quota_client_(NULL), handler_factory_(NULL), | 438 : appcache_policy_(NULL), quota_client_(NULL), handler_factory_(NULL), | 
| 440 quota_manager_proxy_(quota_manager_proxy), | 439 quota_manager_proxy_(quota_manager_proxy), | 
| 441 request_context_(NULL), | 440 request_context_(NULL), | 
| 442 force_keep_session_state_(false), | 441 force_keep_session_state_(false) { | 
| 443 was_reinitialized_(false) { | |
| 444 if (quota_manager_proxy_.get()) { | 442 if (quota_manager_proxy_.get()) { | 
| 445 quota_client_ = new AppCacheQuotaClient(this); | 443 quota_client_ = new AppCacheQuotaClient(this); | 
| 446 quota_manager_proxy_->RegisterClient(quota_client_); | 444 quota_manager_proxy_->RegisterClient(quota_client_); | 
| 447 } | 445 } | 
| 448 } | 446 } | 
| 449 | 447 | 
| 450 AppCacheService::~AppCacheService() { | 448 AppCacheService::~AppCacheService() { | 
| 451 DCHECK(backends_.empty()); | 449 DCHECK(backends_.empty()); | 
| 452 std::for_each(pending_helpers_.begin(), | 450 std::for_each(pending_helpers_.begin(), | 
| 453 pending_helpers_.end(), | 451 pending_helpers_.end(), | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 466 base::MessageLoopProxy* cache_thread) { | 464 base::MessageLoopProxy* cache_thread) { | 
| 467 DCHECK(!storage_.get()); | 465 DCHECK(!storage_.get()); | 
| 468 cache_directory_ = cache_directory; | 466 cache_directory_ = cache_directory; | 
| 469 db_thread_ = db_thread; | 467 db_thread_ = db_thread; | 
| 470 cache_thread_ = cache_thread; | 468 cache_thread_ = cache_thread; | 
| 471 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); | 469 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); | 
| 472 storage->Initialize(cache_directory, db_thread, cache_thread); | 470 storage->Initialize(cache_directory, db_thread, cache_thread); | 
| 473 storage_.reset(storage); | 471 storage_.reset(storage); | 
| 474 } | 472 } | 
| 475 | 473 | 
| 474 void AppCacheService::ScheduleReinitialize() { | |
| 475 if (reinit_timer_.IsRunning()) | |
| 476 return; | |
| 477 | |
| 478 // Reinitialization only happens when corruption has been noticed. | |
| 479 // We don't want to thrash the disk but we also don't want to | |
| 480 // leave the appcache disabled for an indefinite period of time. Some | |
| 481 // users never shutdown the browser. | |
| 482 | |
| 483 const base::TimeDelta kZeroDelta; | |
| 484 const base::TimeDelta kOneHour(base::TimeDelta::FromHours(1)); | |
| 485 const base::TimeDelta k30Seconds(base::TimeDelta::FromSeconds(30)); | |
| 486 | |
| 487 // If the system managed to stay up for long enough, reset the | |
| 488 // delay so a new failure won't incur a long wait to get going again. | |
| 489 base::TimeDelta up_time = base::Time::Now() - last_reinit_time_; | |
| 
jsbell
2014/01/28 22:45:47
Ah, yes, much clearer. I missed that last_reinit_t
 | |
| 490 if (next_reinit_delay_ != kZeroDelta && up_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 | |
| 476 void AppCacheService::Reinitialize() { | 501 void AppCacheService::Reinitialize() { | 
| 477 AppCacheHistograms::CountReinitAttempt(was_reinitialized_); | 502 AppCacheHistograms::CountReinitAttempt(!last_reinit_time_.is_null()); | 
| 478 | 503 last_reinit_time_ = base::Time::Now(); | 
| 479 // To avoid thrashing, we only do this once. | |
| 480 if (was_reinitialized_) | |
| 481 return; | |
| 482 was_reinitialized_ = true; | |
| 483 | 504 | 
| 484 // Inform observers of about this and give them a chance to | 505 // Inform observers of about this and give them a chance to | 
| 485 // defer deletion of the old storage object. | 506 // defer deletion of the old storage object. | 
| 486 scoped_refptr<AppCacheStorageReference> | 507 scoped_refptr<AppCacheStorageReference> | 
| 487 old_storage_ref(new AppCacheStorageReference(storage_.Pass())); | 508 old_storage_ref(new AppCacheStorageReference(storage_.Pass())); | 
| 488 FOR_EACH_OBSERVER(Observer, observers_, | 509 FOR_EACH_OBSERVER(Observer, observers_, | 
| 489 OnServiceReinitialized(old_storage_ref.get())); | 510 OnServiceReinitialized(old_storage_ref.get())); | 
| 490 | 511 | 
| 491 Initialize(cache_directory_, db_thread_, cache_thread_); | 512 Initialize(cache_directory_, db_thread_, cache_thread_); | 
| 492 } | 513 } | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 backends_.insert( | 561 backends_.insert( | 
| 541 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 562 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 
| 542 } | 563 } | 
| 543 | 564 | 
| 544 void AppCacheService::UnregisterBackend( | 565 void AppCacheService::UnregisterBackend( | 
| 545 AppCacheBackendImpl* backend_impl) { | 566 AppCacheBackendImpl* backend_impl) { | 
| 546 backends_.erase(backend_impl->process_id()); | 567 backends_.erase(backend_impl->process_id()); | 
| 547 } | 568 } | 
| 548 | 569 | 
| 549 } // namespace appcache | 570 } // namespace appcache | 
| OLD | NEW |