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