| OLD | NEW |
| 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 "chrome/browser/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 base::Time delete_begin, | 59 base::Time delete_begin, |
| 60 base::Time delete_end) | 60 base::Time delete_end) |
| 61 : profile_(profile), | 61 : profile_(profile), |
| 62 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | 62 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
| 63 delete_begin_(delete_begin), | 63 delete_begin_(delete_begin), |
| 64 delete_end_(delete_end), | 64 delete_end_(delete_end), |
| 65 ALLOW_THIS_IN_INITIALIZER_LIST(database_cleared_callback_( | 65 ALLOW_THIS_IN_INITIALIZER_LIST(database_cleared_callback_( |
| 66 this, &BrowsingDataRemover::OnClearedDatabases)), | 66 this, &BrowsingDataRemover::OnClearedDatabases)), |
| 67 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( | 67 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( |
| 68 this, &BrowsingDataRemover::DoClearCache)), | 68 this, &BrowsingDataRemover::DoClearCache)), |
| 69 appcache_service_(profile->GetAppCacheService()), | 69 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_cleared_callback_( |
| 70 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_got_info_callback_( | 70 this, &BrowsingDataRemover::OnClearedAppCache)), |
| 71 this, &BrowsingDataRemover::OnGotAppCacheInfo)), | |
| 72 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( | |
| 73 this, &BrowsingDataRemover::OnAppCacheDeleted)), | |
| 74 appcaches_to_be_deleted_count_(0), | |
| 75 next_cache_state_(STATE_NONE), | 71 next_cache_state_(STATE_NONE), |
| 76 cache_(NULL), | 72 cache_(NULL), |
| 77 main_context_getter_(profile->GetRequestContext()), | 73 main_context_getter_(profile->GetRequestContext()), |
| 78 media_context_getter_(profile->GetRequestContextForMedia()), | 74 media_context_getter_(profile->GetRequestContextForMedia()), |
| 79 waiting_for_clear_databases_(false), | 75 waiting_for_clear_databases_(false), |
| 80 waiting_for_clear_history_(false), | 76 waiting_for_clear_history_(false), |
| 81 waiting_for_clear_networking_history_(false), | 77 waiting_for_clear_networking_history_(false), |
| 82 waiting_for_clear_cache_(false), | 78 waiting_for_clear_cache_(false), |
| 83 waiting_for_clear_appcache_(false), | 79 waiting_for_clear_appcache_(false), |
| 84 waiting_for_clear_gears_data_(false), | 80 waiting_for_clear_gears_data_(false), |
| 85 waiting_for_clear_file_systems_(false) { | 81 waiting_for_clear_file_systems_(false) { |
| 86 DCHECK(profile); | 82 DCHECK(profile); |
| 87 } | 83 } |
| 88 | 84 |
| 89 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | 85 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
| 90 TimePeriod time_period, | 86 TimePeriod time_period, |
| 91 base::Time delete_end) | 87 base::Time delete_end) |
| 92 : profile_(profile), | 88 : profile_(profile), |
| 93 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | 89 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
| 94 delete_begin_(CalculateBeginDeleteTime(time_period)), | 90 delete_begin_(CalculateBeginDeleteTime(time_period)), |
| 95 delete_end_(delete_end), | 91 delete_end_(delete_end), |
| 96 ALLOW_THIS_IN_INITIALIZER_LIST(database_cleared_callback_( | 92 ALLOW_THIS_IN_INITIALIZER_LIST(database_cleared_callback_( |
| 97 this, &BrowsingDataRemover::OnClearedDatabases)), | 93 this, &BrowsingDataRemover::OnClearedDatabases)), |
| 98 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( | 94 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( |
| 99 this, &BrowsingDataRemover::DoClearCache)), | 95 this, &BrowsingDataRemover::DoClearCache)), |
| 100 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_got_info_callback_( | 96 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_cleared_callback_( |
| 101 this, &BrowsingDataRemover::OnGotAppCacheInfo)), | 97 this, &BrowsingDataRemover::OnClearedAppCache)), |
| 102 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( | |
| 103 this, &BrowsingDataRemover::OnAppCacheDeleted)), | |
| 104 appcaches_to_be_deleted_count_(0), | |
| 105 next_cache_state_(STATE_NONE), | 98 next_cache_state_(STATE_NONE), |
| 106 cache_(NULL), | 99 cache_(NULL), |
| 107 main_context_getter_(profile->GetRequestContext()), | 100 main_context_getter_(profile->GetRequestContext()), |
| 108 media_context_getter_(profile->GetRequestContextForMedia()), | 101 media_context_getter_(profile->GetRequestContextForMedia()), |
| 109 waiting_for_clear_databases_(false), | 102 waiting_for_clear_databases_(false), |
| 110 waiting_for_clear_history_(false), | 103 waiting_for_clear_history_(false), |
| 111 waiting_for_clear_networking_history_(false), | 104 waiting_for_clear_networking_history_(false), |
| 112 waiting_for_clear_cache_(false), | 105 waiting_for_clear_cache_(false), |
| 113 waiting_for_clear_appcache_(false), | 106 waiting_for_clear_appcache_(false), |
| 114 waiting_for_clear_lso_data_(false), | 107 waiting_for_clear_lso_data_(false), |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 | 497 |
| 505 void BrowsingDataRemover::ClearDatabasesOnFILEThread() { | 498 void BrowsingDataRemover::ClearDatabasesOnFILEThread() { |
| 506 // This function should be called on the FILE thread. | 499 // This function should be called on the FILE thread. |
| 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 508 int rv = database_tracker_->DeleteDataModifiedSince( | 501 int rv = database_tracker_->DeleteDataModifiedSince( |
| 509 delete_begin_, &database_cleared_callback_); | 502 delete_begin_, &database_cleared_callback_); |
| 510 if (rv != net::ERR_IO_PENDING) | 503 if (rv != net::ERR_IO_PENDING) |
| 511 OnClearedDatabases(rv); | 504 OnClearedDatabases(rv); |
| 512 } | 505 } |
| 513 | 506 |
| 514 void BrowsingDataRemover::OnClearedAppCache() { | 507 void BrowsingDataRemover::OnClearedAppCache(int rv) { |
| 515 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 508 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 516 bool result = BrowserThread::PostTask( | 509 bool result = BrowserThread::PostTask( |
| 517 BrowserThread::UI, FROM_HERE, | 510 BrowserThread::UI, FROM_HERE, |
| 518 NewRunnableMethod(this, &BrowsingDataRemover::OnClearedAppCache)); | 511 NewRunnableMethod(this, &BrowsingDataRemover::OnClearedAppCache, rv)); |
| 519 DCHECK(result); | 512 DCHECK(result); |
| 520 return; | 513 return; |
| 521 } | 514 } |
| 522 waiting_for_clear_appcache_ = false; | 515 waiting_for_clear_appcache_ = false; |
| 523 NotifyAndDeleteIfDone(); | 516 NotifyAndDeleteIfDone(); |
| 524 } | 517 } |
| 525 | 518 |
| 526 void BrowsingDataRemover::ClearAppCacheOnIOThread() { | 519 void BrowsingDataRemover::ClearAppCacheOnIOThread() { |
| 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 528 DCHECK(waiting_for_clear_appcache_); | 521 DCHECK(waiting_for_clear_appcache_); |
| 529 appcache_info_ = new appcache::AppCacheInfoCollection; | |
| 530 if (appcache_service_) { | 522 if (appcache_service_) { |
| 531 appcache_service_->GetAllAppCacheInfo( | 523 appcache_service_->ClearAppCache(&appcache_cleared_callback_); |
| 532 appcache_info_, &appcache_got_info_callback_); | 524 // continues in OnClearedAppCache |
| 533 // continues in OnGotAppCacheInfo | |
| 534 } else { | 525 } else { |
| 535 // Couldn't get app cache service, nothing to clear. | 526 // Couldn't get app cache service, nothing to clear. |
| 536 OnClearedAppCache(); | 527 OnClearedAppCache(0); |
| 537 } | 528 } |
| 538 } | 529 } |
| 539 | 530 |
| 540 void BrowsingDataRemover::OnGotAppCacheInfo(int rv) { | |
| 541 using appcache::AppCacheInfoVector; | |
| 542 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; | |
| 543 | |
| 544 for (InfoByOrigin::const_iterator origin = | |
| 545 appcache_info_->infos_by_origin.begin(); | |
| 546 origin != appcache_info_->infos_by_origin.end(); ++origin) { | |
| 547 if (special_storage_policy_->IsStorageProtected(origin->first)) | |
| 548 continue; | |
| 549 for (AppCacheInfoVector::const_iterator info = origin->second.begin(); | |
| 550 info != origin->second.end(); ++info) { | |
| 551 if (info->creation_time > delete_begin_) { | |
| 552 ++appcaches_to_be_deleted_count_; | |
| 553 appcache_service_->DeleteAppCacheGroup( | |
| 554 info->manifest_url, &appcache_deleted_callback_); | |
| 555 } | |
| 556 } | |
| 557 } | |
| 558 | |
| 559 if (!appcaches_to_be_deleted_count_) | |
| 560 OnClearedAppCache(); | |
| 561 // else continues in OnAppCacheDeleted | |
| 562 } | |
| 563 | |
| 564 void BrowsingDataRemover::OnAppCacheDeleted(int rv) { | |
| 565 --appcaches_to_be_deleted_count_; | |
| 566 if (!appcaches_to_be_deleted_count_) | |
| 567 OnClearedAppCache(); | |
| 568 } | |
| 569 | |
| 570 void BrowsingDataRemover::ClearFileSystemsOnFILEThread() { | 531 void BrowsingDataRemover::ClearFileSystemsOnFILEThread() { |
| 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 572 DCHECK(waiting_for_clear_file_systems_); | 533 DCHECK(waiting_for_clear_file_systems_); |
| 573 scoped_refptr<fileapi::FileSystemContext> | 534 scoped_refptr<fileapi::FileSystemContext> |
| 574 fs_context(profile_->GetFileSystemContext()); | 535 fs_context(profile_->GetFileSystemContext()); |
| 575 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> | 536 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> |
| 576 origin_enumerator(fs_context->path_manager()->sandbox_provider()-> | 537 origin_enumerator(fs_context->path_manager()->sandbox_provider()-> |
| 577 CreateOriginEnumerator()); | 538 CreateOriginEnumerator()); |
| 578 | 539 |
| 579 GURL origin; | 540 GURL origin; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 589 |
| 629 ClearGearsData(profile_dir); | 590 ClearGearsData(profile_dir); |
| 630 OnClearedGearsData(); | 591 OnClearedGearsData(); |
| 631 } | 592 } |
| 632 | 593 |
| 633 void BrowsingDataRemover::OnWaitableEventSignaled( | 594 void BrowsingDataRemover::OnWaitableEventSignaled( |
| 634 base::WaitableEvent* waitable_event) { | 595 base::WaitableEvent* waitable_event) { |
| 635 waiting_for_clear_lso_data_ = false; | 596 waiting_for_clear_lso_data_ = false; |
| 636 NotifyAndDeleteIfDone(); | 597 NotifyAndDeleteIfDone(); |
| 637 } | 598 } |
| OLD | NEW |