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 "chrome/browser/browsing_data/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 16 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 18 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 19 #include "chrome/browser/browsing_data/storage_partition_http_cache_data_remover
.h" |
19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
20 #include "chrome/browser/domain_reliability/service_factory.h" | 21 #include "chrome/browser/domain_reliability/service_factory.h" |
21 #include "chrome/browser/download/download_prefs.h" | 22 #include "chrome/browser/download/download_prefs.h" |
22 #include "chrome/browser/download/download_service_factory.h" | 23 #include "chrome/browser/download/download_service_factory.h" |
23 #include "chrome/browser/history/history_service_factory.h" | 24 #include "chrome/browser/history/history_service_factory.h" |
24 #include "chrome/browser/history/web_history_service_factory.h" | 25 #include "chrome/browser/history/web_history_service_factory.h" |
25 #include "chrome/browser/io_thread.h" | 26 #include "chrome/browser/io_thread.h" |
26 #include "chrome/browser/media/media_device_id_salt.h" | 27 #include "chrome/browser/media/media_device_id_salt.h" |
27 #include "chrome/browser/net/predictor.h" | 28 #include "chrome/browser/net/predictor.h" |
28 #include "chrome/browser/password_manager/password_store_factory.h" | 29 #include "chrome/browser/password_manager/password_store_factory.h" |
(...skipping 18 matching lines...) Expand all Loading... |
47 #include "components/domain_reliability/service.h" | 48 #include "components/domain_reliability/service.h" |
48 #include "components/history/core/browser/history_service.h" | 49 #include "components/history/core/browser/history_service.h" |
49 #include "components/nacl/browser/nacl_browser.h" | 50 #include "components/nacl/browser/nacl_browser.h" |
50 #include "components/nacl/browser/pnacl_host.h" | 51 #include "components/nacl/browser/pnacl_host.h" |
51 #include "components/password_manager/core/browser/password_store.h" | 52 #include "components/password_manager/core/browser/password_store.h" |
52 #include "components/power/origin_power_map.h" | 53 #include "components/power/origin_power_map.h" |
53 #include "components/power/origin_power_map_factory.h" | 54 #include "components/power/origin_power_map_factory.h" |
54 #include "components/search_engines/template_url_service.h" | 55 #include "components/search_engines/template_url_service.h" |
55 #include "components/web_cache/browser/web_cache_manager.h" | 56 #include "components/web_cache/browser/web_cache_manager.h" |
56 #include "content/public/browser/browser_thread.h" | 57 #include "content/public/browser/browser_thread.h" |
57 #include "content/public/browser/dom_storage_context.h" | |
58 #include "content/public/browser/download_manager.h" | 58 #include "content/public/browser/download_manager.h" |
59 #include "content/public/browser/local_storage_usage_info.h" | |
60 #include "content/public/browser/notification_service.h" | 59 #include "content/public/browser/notification_service.h" |
61 #include "content/public/browser/plugin_data_remover.h" | 60 #include "content/public/browser/plugin_data_remover.h" |
62 #include "content/public/browser/session_storage_usage_info.h" | |
63 #include "content/public/browser/ssl_host_state_delegate.h" | 61 #include "content/public/browser/ssl_host_state_delegate.h" |
64 #include "content/public/browser/storage_partition.h" | 62 #include "content/public/browser/storage_partition.h" |
65 #include "content/public/browser/user_metrics.h" | 63 #include "content/public/browser/user_metrics.h" |
66 #include "net/base/net_errors.h" | 64 #include "net/base/net_errors.h" |
67 #include "net/base/sdch_manager.h" | |
68 #include "net/cookies/cookie_store.h" | 65 #include "net/cookies/cookie_store.h" |
69 #include "net/disk_cache/disk_cache.h" | |
70 #include "net/http/http_cache.h" | |
71 #include "net/http/transport_security_state.h" | 66 #include "net/http/transport_security_state.h" |
72 #include "net/ssl/channel_id_service.h" | 67 #include "net/ssl/channel_id_service.h" |
73 #include "net/ssl/channel_id_store.h" | 68 #include "net/ssl/channel_id_store.h" |
74 #include "net/url_request/url_request_context.h" | 69 #include "net/url_request/url_request_context.h" |
75 #include "net/url_request/url_request_context_getter.h" | 70 #include "net/url_request/url_request_context_getter.h" |
76 #include "storage/browser/quota/quota_manager.h" | |
77 #include "storage/browser/quota/special_storage_policy.h" | 71 #include "storage/browser/quota/special_storage_policy.h" |
78 #include "storage/common/quota/quota_types.h" | |
79 | 72 |
80 #if defined(OS_CHROMEOS) | 73 #if defined(OS_CHROMEOS) |
81 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 74 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
82 #include "chromeos/attestation/attestation_constants.h" | 75 #include "chromeos/attestation/attestation_constants.h" |
83 #include "chromeos/dbus/cryptohome_client.h" | 76 #include "chromeos/dbus/cryptohome_client.h" |
84 #include "chromeos/dbus/dbus_thread_manager.h" | 77 #include "chromeos/dbus/dbus_thread_manager.h" |
85 #include "components/user_manager/user.h" | 78 #include "components/user_manager/user.h" |
86 #endif | 79 #endif |
87 | 80 |
88 #if defined(ENABLE_EXTENSIONS) | 81 #if defined(ENABLE_EXTENSIONS) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 BrowsingDataRemover::CalculateBeginDeleteTime(period), | 194 BrowsingDataRemover::CalculateBeginDeleteTime(period), |
202 base::Time::Max()); | 195 base::Time::Max()); |
203 } | 196 } |
204 | 197 |
205 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | 198 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
206 base::Time delete_begin, | 199 base::Time delete_begin, |
207 base::Time delete_end) | 200 base::Time delete_end) |
208 : profile_(profile), | 201 : profile_(profile), |
209 delete_begin_(delete_begin), | 202 delete_begin_(delete_begin), |
210 delete_end_(delete_end), | 203 delete_end_(delete_end), |
211 next_cache_state_(STATE_NONE), | |
212 cache_(NULL), | |
213 main_context_getter_(profile->GetRequestContext()), | 204 main_context_getter_(profile->GetRequestContext()), |
214 media_context_getter_(profile->GetMediaRequestContext()), | 205 media_context_getter_(profile->GetMediaRequestContext()), |
215 deauthorize_content_licenses_request_id_(0), | 206 deauthorize_content_licenses_request_id_(0), |
216 waiting_for_clear_autofill_origin_urls_(false), | 207 waiting_for_clear_autofill_origin_urls_(false), |
217 waiting_for_clear_cache_(false), | 208 waiting_for_clear_cache_(false), |
218 waiting_for_clear_channel_ids_(false), | 209 waiting_for_clear_channel_ids_(false), |
219 waiting_for_clear_content_licenses_(false), | 210 waiting_for_clear_content_licenses_(false), |
220 waiting_for_clear_cookies_count_(0), | 211 waiting_for_clear_cookies_count_(0), |
221 waiting_for_clear_domain_reliability_monitor_(false), | 212 waiting_for_clear_domain_reliability_monitor_(false), |
222 waiting_for_clear_form_(false), | 213 waiting_for_clear_form_(false), |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 autofill::PersonalDataManagerFactory::GetForProfile(profile_); | 598 autofill::PersonalDataManagerFactory::GetForProfile(profile_); |
608 if (data_manager) | 599 if (data_manager) |
609 data_manager->Refresh(); | 600 data_manager->Refresh(); |
610 } | 601 } |
611 } | 602 } |
612 | 603 |
613 if (remove_mask & REMOVE_CACHE) { | 604 if (remove_mask & REMOVE_CACHE) { |
614 // Tell the renderers to clear their cache. | 605 // Tell the renderers to clear their cache. |
615 web_cache::WebCacheManager::GetInstance()->ClearCache(); | 606 web_cache::WebCacheManager::GetInstance()->ClearCache(); |
616 | 607 |
617 // Invoke DoClearCache on the IO thread. | |
618 waiting_for_clear_cache_ = true; | |
619 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); | 608 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); |
620 | 609 |
621 BrowserThread::PostTask( | 610 waiting_for_clear_cache_ = true; |
622 BrowserThread::IO, FROM_HERE, | 611 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. |
623 base::Bind(&BrowsingDataRemover::ClearCacheOnIOThread, | 612 StoragePartitionHttpCacheDataRemover::CreateForRange( |
624 base::Unretained(this))); | 613 BrowserContext::GetDefaultStoragePartition(profile_), delete_begin_, |
| 614 delete_end_) |
| 615 ->Remove(base::Bind(&BrowsingDataRemover::ClearedCache, |
| 616 base::Unretained(this))); |
625 | 617 |
626 #if !defined(DISABLE_NACL) | 618 #if !defined(DISABLE_NACL) |
627 waiting_for_clear_nacl_cache_ = true; | 619 waiting_for_clear_nacl_cache_ = true; |
628 | 620 |
629 BrowserThread::PostTask( | 621 BrowserThread::PostTask( |
630 BrowserThread::IO, FROM_HERE, | 622 BrowserThread::IO, FROM_HERE, |
631 base::Bind(&BrowsingDataRemover::ClearNaClCacheOnIOThread, | 623 base::Bind(&BrowsingDataRemover::ClearNaClCacheOnIOThread, |
632 base::Unretained(this))); | 624 base::Unretained(this))); |
633 | 625 |
634 waiting_for_clear_pnacl_cache_ = true; | 626 waiting_for_clear_pnacl_cache_ = true; |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 waiting_for_clear_networking_history_ = false; | 948 waiting_for_clear_networking_history_ = false; |
957 NotifyAndDeleteIfDone(); | 949 NotifyAndDeleteIfDone(); |
958 } | 950 } |
959 | 951 |
960 void BrowsingDataRemover::ClearedCache() { | 952 void BrowsingDataRemover::ClearedCache() { |
961 waiting_for_clear_cache_ = false; | 953 waiting_for_clear_cache_ = false; |
962 | 954 |
963 NotifyAndDeleteIfDone(); | 955 NotifyAndDeleteIfDone(); |
964 } | 956 } |
965 | 957 |
966 void BrowsingDataRemover::ClearCacheOnIOThread() { | |
967 // This function should be called on the IO thread. | |
968 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
969 DCHECK_EQ(STATE_NONE, next_cache_state_); | |
970 DCHECK(main_context_getter_.get()); | |
971 DCHECK(media_context_getter_.get()); | |
972 | |
973 next_cache_state_ = STATE_CREATE_MAIN; | |
974 DoClearCache(net::OK); | |
975 } | |
976 | |
977 // The expected state sequence is STATE_NONE --> STATE_CREATE_MAIN --> | |
978 // STATE_DELETE_MAIN --> STATE_CREATE_MEDIA --> STATE_DELETE_MEDIA --> | |
979 // STATE_DONE, and any errors are ignored. | |
980 void BrowsingDataRemover::DoClearCache(int rv) { | |
981 DCHECK_NE(STATE_NONE, next_cache_state_); | |
982 | |
983 while (rv != net::ERR_IO_PENDING && next_cache_state_ != STATE_NONE) { | |
984 switch (next_cache_state_) { | |
985 case STATE_CREATE_MAIN: | |
986 case STATE_CREATE_MEDIA: { | |
987 // Get a pointer to the cache. | |
988 net::URLRequestContextGetter* getter = | |
989 (next_cache_state_ == STATE_CREATE_MAIN) | |
990 ? main_context_getter_.get() | |
991 : media_context_getter_.get(); | |
992 net::HttpCache* http_cache = | |
993 getter->GetURLRequestContext()->http_transaction_factory()-> | |
994 GetCache(); | |
995 | |
996 next_cache_state_ = (next_cache_state_ == STATE_CREATE_MAIN) ? | |
997 STATE_DELETE_MAIN : STATE_DELETE_MEDIA; | |
998 | |
999 // Clear QUIC server information from memory and the disk cache. | |
1000 http_cache->GetSession()->quic_stream_factory()-> | |
1001 ClearCachedStatesInCryptoConfig(); | |
1002 | |
1003 // Clear SDCH dictionary state. | |
1004 net::SdchManager* sdch_manager = | |
1005 getter->GetURLRequestContext()->sdch_manager(); | |
1006 // The test is probably overkill, since chrome should always have an | |
1007 // SdchManager. But in general the URLRequestContext is *not* | |
1008 // guaranteed to have an SdchManager, so checking is wise. | |
1009 if (sdch_manager) | |
1010 sdch_manager->ClearData(); | |
1011 | |
1012 rv = http_cache->GetBackend( | |
1013 &cache_, base::Bind(&BrowsingDataRemover::DoClearCache, | |
1014 base::Unretained(this))); | |
1015 break; | |
1016 } | |
1017 case STATE_DELETE_MAIN: | |
1018 case STATE_DELETE_MEDIA: { | |
1019 next_cache_state_ = (next_cache_state_ == STATE_DELETE_MAIN) ? | |
1020 STATE_CREATE_MEDIA : STATE_DONE; | |
1021 | |
1022 // |cache_| can be null if it cannot be initialized. | |
1023 if (cache_) { | |
1024 if (delete_begin_.is_null()) { | |
1025 rv = cache_->DoomAllEntries( | |
1026 base::Bind(&BrowsingDataRemover::DoClearCache, | |
1027 base::Unretained(this))); | |
1028 } else { | |
1029 rv = cache_->DoomEntriesBetween( | |
1030 delete_begin_, delete_end_, | |
1031 base::Bind(&BrowsingDataRemover::DoClearCache, | |
1032 base::Unretained(this))); | |
1033 } | |
1034 cache_ = NULL; | |
1035 } | |
1036 break; | |
1037 } | |
1038 case STATE_DONE: { | |
1039 cache_ = NULL; | |
1040 next_cache_state_ = STATE_NONE; | |
1041 | |
1042 // Notify the UI thread that we are done. | |
1043 BrowserThread::PostTask( | |
1044 BrowserThread::UI, FROM_HERE, | |
1045 base::Bind(&BrowsingDataRemover::ClearedCache, | |
1046 base::Unretained(this))); | |
1047 return; | |
1048 } | |
1049 default: { | |
1050 NOTREACHED() << "bad state"; | |
1051 next_cache_state_ = STATE_NONE; // Stop looping. | |
1052 return; | |
1053 } | |
1054 } | |
1055 } | |
1056 } | |
1057 | |
1058 #if !defined(DISABLE_NACL) | 958 #if !defined(DISABLE_NACL) |
1059 void BrowsingDataRemover::ClearedNaClCache() { | 959 void BrowsingDataRemover::ClearedNaClCache() { |
1060 // This function should be called on the UI thread. | 960 // This function should be called on the UI thread. |
1061 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 961 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1062 | 962 |
1063 waiting_for_clear_nacl_cache_ = false; | 963 waiting_for_clear_nacl_cache_ = false; |
1064 | 964 |
1065 NotifyAndDeleteIfDone(); | 965 NotifyAndDeleteIfDone(); |
1066 } | 966 } |
1067 | 967 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 waiting_for_clear_domain_reliability_monitor_ = false; | 1133 waiting_for_clear_domain_reliability_monitor_ = false; |
1234 NotifyAndDeleteIfDone(); | 1134 NotifyAndDeleteIfDone(); |
1235 } | 1135 } |
1236 | 1136 |
1237 // static | 1137 // static |
1238 BrowsingDataRemover::CallbackSubscription | 1138 BrowsingDataRemover::CallbackSubscription |
1239 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | 1139 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( |
1240 const BrowsingDataRemover::Callback& callback) { | 1140 const BrowsingDataRemover::Callback& callback) { |
1241 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); | 1141 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); |
1242 } | 1142 } |
OLD | NEW |