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

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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 enough time has past since the last reinit, reset the delay.
jsbell 2014/01/24 21:13:44 This seems set up to handle very frequent corrupti
488 if (next_reinit_delay_ != kZeroDelta &&
489 base::Time::Now() - last_reinit_time_ > kOneHour) {
490 next_reinit_delay_ = kZeroDelta;
491 }
492 reinit_timer_.Start(FROM_HERE, next_reinit_delay_,
493 this, &AppCacheService::Reinitialize);
494
495 // Adjust the delay for next time.
496 base::TimeDelta increment = std::max(k30Seconds, next_reinit_delay_);
497 next_reinit_delay_ = std::min(next_reinit_delay_ + increment, kOneHour);
jsbell 2014/01/24 21:13:44 I don't think this is strictly necessary; if the t
michaeln 2014/01/28 22:12:16 Thnx for questioning, this doesn't do what i want
michaeln 2014/01/28 22:21:36 Actually i think the logic was doing what i want,
498 }
499
476 void AppCacheService::Reinitialize() { 500 void AppCacheService::Reinitialize() {
477 AppCacheHistograms::CountReinitAttempt(was_reinitialized_); 501 AppCacheHistograms::CountReinitAttempt(!last_reinit_time_.is_null());
478 502 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 503
484 // Inform observers of about this and give them a chance to 504 // Inform observers of about this and give them a chance to
485 // defer deletion of the old storage object. 505 // defer deletion of the old storage object.
486 scoped_refptr<AppCacheStorageReference> 506 scoped_refptr<AppCacheStorageReference>
487 old_storage_ref(new AppCacheStorageReference(storage_.Pass())); 507 old_storage_ref(new AppCacheStorageReference(storage_.Pass()));
488 FOR_EACH_OBSERVER(Observer, observers_, 508 FOR_EACH_OBSERVER(Observer, observers_,
489 OnServiceReinitialized(old_storage_ref.get())); 509 OnServiceReinitialized(old_storage_ref.get()));
490 510
491 Initialize(cache_directory_, db_thread_, cache_thread_); 511 Initialize(cache_directory_, db_thread_, cache_thread_);
492 } 512 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 backends_.insert( 560 backends_.insert(
541 BackendMap::value_type(backend_impl->process_id(), backend_impl)); 561 BackendMap::value_type(backend_impl->process_id(), backend_impl));
542 } 562 }
543 563
544 void AppCacheService::UnregisterBackend( 564 void AppCacheService::UnregisterBackend(
545 AppCacheBackendImpl* backend_impl) { 565 AppCacheBackendImpl* backend_impl) {
546 backends_.erase(backend_impl->process_id()); 566 backends_.erase(backend_impl->process_id());
547 } 567 }
548 568
549 } // namespace appcache 569 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698