Chromium Code Reviews| 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_got_info_callback_( | 70 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_got_info_callback_( |
| 70 this, &BrowsingDataRemover::OnGotAppCacheInfo)), | 71 this, &BrowsingDataRemover::OnGotAppCacheInfo)), |
| 71 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( | 72 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( |
| 72 this, &BrowsingDataRemover::OnAppCacheDeleted)), | 73 this, &BrowsingDataRemover::OnAppCacheDeleted)), |
| 73 appcaches_to_be_deleted_count_(0), | 74 appcaches_to_be_deleted_count_(0), |
| 74 next_cache_state_(STATE_NONE), | 75 next_cache_state_(STATE_NONE), |
| 75 cache_(NULL), | 76 cache_(NULL), |
| 76 main_context_getter_(profile->GetRequestContext()), | 77 main_context_getter_(profile->GetRequestContext()), |
| 77 media_context_getter_(profile->GetRequestContextForMedia()), | 78 media_context_getter_(profile->GetRequestContextForMedia()), |
| 78 waiting_for_clear_databases_(false), | 79 waiting_for_clear_databases_(false), |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 database_tracker_ = profile_->GetDatabaseTracker(); | 218 database_tracker_ = profile_->GetDatabaseTracker(); |
| 218 if (database_tracker_.get()) { | 219 if (database_tracker_.get()) { |
| 219 waiting_for_clear_databases_ = true; | 220 waiting_for_clear_databases_ = true; |
| 220 BrowserThread::PostTask( | 221 BrowserThread::PostTask( |
| 221 BrowserThread::FILE, FROM_HERE, | 222 BrowserThread::FILE, FROM_HERE, |
| 222 NewRunnableMethod( | 223 NewRunnableMethod( |
| 223 this, | 224 this, |
| 224 &BrowsingDataRemover::ClearDatabasesOnFILEThread)); | 225 &BrowsingDataRemover::ClearDatabasesOnFILEThread)); |
| 225 } | 226 } |
| 226 | 227 |
| 227 waiting_for_clear_appcache_ = true; | 228 waiting_for_clear_appcache_ = true; |
|
willchan no longer on Chromium
2011/07/03 09:11:21
Awesome! I was going to do this cleanup too. Glad
marja(google)
2011/07/06 09:40:01
I created another changelist for that http://coder
| |
| 228 BrowserThread::PostTask( | 229 BrowserThread::PostTask( |
| 229 BrowserThread::IO, FROM_HERE, | 230 BrowserThread::IO, FROM_HERE, |
| 230 NewRunnableMethod( | 231 NewRunnableMethod( |
| 231 this, | 232 this, |
| 232 &BrowsingDataRemover::ClearAppCacheOnIOThread)); | 233 &BrowsingDataRemover::ClearAppCacheOnIOThread)); |
| 233 | 234 |
| 234 waiting_for_clear_gears_data_ = true; | 235 waiting_for_clear_gears_data_ = true; |
| 235 BrowserThread::PostTask( | 236 BrowserThread::PostTask( |
| 236 BrowserThread::FILE, FROM_HERE, | 237 BrowserThread::FILE, FROM_HERE, |
| 237 NewRunnableMethod( | 238 NewRunnableMethod( |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 return; | 520 return; |
| 520 } | 521 } |
| 521 waiting_for_clear_appcache_ = false; | 522 waiting_for_clear_appcache_ = false; |
| 522 NotifyAndDeleteIfDone(); | 523 NotifyAndDeleteIfDone(); |
| 523 } | 524 } |
| 524 | 525 |
| 525 void BrowsingDataRemover::ClearAppCacheOnIOThread() { | 526 void BrowsingDataRemover::ClearAppCacheOnIOThread() { |
| 526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 527 DCHECK(waiting_for_clear_appcache_); | 528 DCHECK(waiting_for_clear_appcache_); |
| 528 appcache_info_ = new appcache::AppCacheInfoCollection; | 529 appcache_info_ = new appcache::AppCacheInfoCollection; |
| 529 if (GetAppCacheService()) { | 530 if (appcache_service_) { |
| 530 GetAppCacheService()->GetAllAppCacheInfo( | 531 appcache_service_->GetAllAppCacheInfo( |
| 531 appcache_info_, &appcache_got_info_callback_); | 532 appcache_info_, &appcache_got_info_callback_); |
| 532 // continues in OnGotAppCacheInfo | 533 // continues in OnGotAppCacheInfo |
| 533 } else { | 534 } else { |
| 534 // Couldn't get app cache service, nothing to clear. | 535 // Couldn't get app cache service, nothing to clear. |
| 535 OnClearedAppCache(); | 536 OnClearedAppCache(); |
| 536 } | 537 } |
| 537 } | 538 } |
| 538 | 539 |
| 539 void BrowsingDataRemover::OnGotAppCacheInfo(int rv) { | 540 void BrowsingDataRemover::OnGotAppCacheInfo(int rv) { |
| 540 using appcache::AppCacheInfoVector; | 541 using appcache::AppCacheInfoVector; |
| 541 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; | 542 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; |
| 542 | 543 |
| 543 for (InfoByOrigin::const_iterator origin = | 544 for (InfoByOrigin::const_iterator origin = |
| 544 appcache_info_->infos_by_origin.begin(); | 545 appcache_info_->infos_by_origin.begin(); |
| 545 origin != appcache_info_->infos_by_origin.end(); ++origin) { | 546 origin != appcache_info_->infos_by_origin.end(); ++origin) { |
| 546 if (special_storage_policy_->IsStorageProtected(origin->first)) | 547 if (special_storage_policy_->IsStorageProtected(origin->first)) |
| 547 continue; | 548 continue; |
| 548 for (AppCacheInfoVector::const_iterator info = origin->second.begin(); | 549 for (AppCacheInfoVector::const_iterator info = origin->second.begin(); |
| 549 info != origin->second.end(); ++info) { | 550 info != origin->second.end(); ++info) { |
| 550 if (info->creation_time > delete_begin_) { | 551 if (info->creation_time > delete_begin_) { |
| 551 ++appcaches_to_be_deleted_count_; | 552 ++appcaches_to_be_deleted_count_; |
| 552 GetAppCacheService()->DeleteAppCacheGroup( | 553 appcache_service_->DeleteAppCacheGroup( |
| 553 info->manifest_url, &appcache_deleted_callback_); | 554 info->manifest_url, &appcache_deleted_callback_); |
| 554 } | 555 } |
| 555 } | 556 } |
| 556 } | 557 } |
| 557 | 558 |
| 558 if (!appcaches_to_be_deleted_count_) | 559 if (!appcaches_to_be_deleted_count_) |
| 559 OnClearedAppCache(); | 560 OnClearedAppCache(); |
| 560 // else continues in OnAppCacheDeleted | 561 // else continues in OnAppCacheDeleted |
| 561 } | 562 } |
| 562 | 563 |
| 563 void BrowsingDataRemover::OnAppCacheDeleted(int rv) { | 564 void BrowsingDataRemover::OnAppCacheDeleted(int rv) { |
| 564 --appcaches_to_be_deleted_count_; | 565 --appcaches_to_be_deleted_count_; |
| 565 if (!appcaches_to_be_deleted_count_) | 566 if (!appcaches_to_be_deleted_count_) |
| 566 OnClearedAppCache(); | 567 OnClearedAppCache(); |
| 567 } | 568 } |
| 568 | 569 |
| 569 ChromeAppCacheService* BrowsingDataRemover::GetAppCacheService() { | |
| 570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 571 ChromeURLRequestContext* request_context = NULL; | |
| 572 if (main_context_getter_) | |
| 573 request_context = reinterpret_cast<ChromeURLRequestContext*>( | |
| 574 main_context_getter_->GetURLRequestContext()); | |
| 575 return request_context ? request_context->appcache_service() | |
| 576 : NULL; | |
| 577 } | |
| 578 | |
| 579 void BrowsingDataRemover::ClearFileSystemsOnFILEThread() { | 570 void BrowsingDataRemover::ClearFileSystemsOnFILEThread() { |
| 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 581 DCHECK(waiting_for_clear_file_systems_); | 572 DCHECK(waiting_for_clear_file_systems_); |
| 582 scoped_refptr<fileapi::FileSystemContext> | 573 scoped_refptr<fileapi::FileSystemContext> |
| 583 fs_context(profile_->GetFileSystemContext()); | 574 fs_context(profile_->GetFileSystemContext()); |
| 584 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> | 575 scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> |
| 585 origin_enumerator(fs_context->path_manager()->sandbox_provider()-> | 576 origin_enumerator(fs_context->path_manager()->sandbox_provider()-> |
| 586 CreateOriginEnumerator()); | 577 CreateOriginEnumerator()); |
| 587 | 578 |
| 588 GURL origin; | 579 GURL origin; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 | 628 |
| 638 ClearGearsData(profile_dir); | 629 ClearGearsData(profile_dir); |
| 639 OnClearedGearsData(); | 630 OnClearedGearsData(); |
| 640 } | 631 } |
| 641 | 632 |
| 642 void BrowsingDataRemover::OnWaitableEventSignaled( | 633 void BrowsingDataRemover::OnWaitableEventSignaled( |
| 643 base::WaitableEvent* waitable_event) { | 634 base::WaitableEvent* waitable_event) { |
| 644 waiting_for_clear_lso_data_ = false; | 635 waiting_for_clear_lso_data_ = false; |
| 645 NotifyAndDeleteIfDone(); | 636 NotifyAndDeleteIfDone(); |
| 646 } | 637 } |
| OLD | NEW |