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_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/bind.h" | 10 #include "base/bind.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 cache_(NULL), | 96 cache_(NULL), |
97 main_context_getter_(profile->GetRequestContext()), | 97 main_context_getter_(profile->GetRequestContext()), |
98 media_context_getter_(profile->GetRequestContextForMedia()), | 98 media_context_getter_(profile->GetRequestContextForMedia()), |
99 waiting_for_clear_cache_(false), | 99 waiting_for_clear_cache_(false), |
100 waiting_for_clear_cookies_(false), | 100 waiting_for_clear_cookies_(false), |
101 waiting_for_clear_history_(false), | 101 waiting_for_clear_history_(false), |
102 waiting_for_clear_networking_history_(false), | 102 waiting_for_clear_networking_history_(false), |
103 waiting_for_clear_origin_bound_certs_(false), | 103 waiting_for_clear_origin_bound_certs_(false), |
104 waiting_for_clear_plugin_data_(false), | 104 waiting_for_clear_plugin_data_(false), |
105 waiting_for_clear_quota_managed_data_(false), | 105 waiting_for_clear_quota_managed_data_(false), |
106 remove_mask_(0) { | 106 remove_mask_(0), |
| 107 remove_origin_(GURL()), |
| 108 remove_protected_(false) { |
107 DCHECK(profile); | 109 DCHECK(profile); |
108 } | 110 } |
109 | 111 |
110 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | 112 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
111 TimePeriod time_period, | 113 TimePeriod time_period, |
112 base::Time delete_end) | 114 base::Time delete_end) |
113 : profile_(profile), | 115 : profile_(profile), |
114 quota_manager_(NULL), | 116 quota_manager_(NULL), |
115 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | 117 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
116 delete_begin_(CalculateBeginDeleteTime(time_period)), | 118 delete_begin_(CalculateBeginDeleteTime(time_period)), |
117 delete_end_(delete_end), | 119 delete_end_(delete_end), |
118 next_cache_state_(STATE_NONE), | 120 next_cache_state_(STATE_NONE), |
119 cache_(NULL), | 121 cache_(NULL), |
120 main_context_getter_(profile->GetRequestContext()), | 122 main_context_getter_(profile->GetRequestContext()), |
121 media_context_getter_(profile->GetRequestContextForMedia()), | 123 media_context_getter_(profile->GetRequestContextForMedia()), |
122 waiting_for_clear_cache_(false), | 124 waiting_for_clear_cache_(false), |
123 waiting_for_clear_cookies_(false), | 125 waiting_for_clear_cookies_(false), |
124 waiting_for_clear_history_(false), | 126 waiting_for_clear_history_(false), |
125 waiting_for_clear_networking_history_(false), | 127 waiting_for_clear_networking_history_(false), |
126 waiting_for_clear_origin_bound_certs_(false), | 128 waiting_for_clear_origin_bound_certs_(false), |
127 waiting_for_clear_plugin_data_(false), | 129 waiting_for_clear_plugin_data_(false), |
128 waiting_for_clear_quota_managed_data_(false), | 130 waiting_for_clear_quota_managed_data_(false), |
129 remove_mask_(0) { | 131 remove_mask_(0), |
| 132 remove_origin_(GURL()), |
| 133 remove_protected_(false) { |
130 DCHECK(profile); | 134 DCHECK(profile); |
131 } | 135 } |
132 | 136 |
133 BrowsingDataRemover::~BrowsingDataRemover() { | 137 BrowsingDataRemover::~BrowsingDataRemover() { |
134 DCHECK(all_done()); | 138 DCHECK(all_done()); |
135 } | 139 } |
136 | 140 |
137 // Static. | 141 // Static. |
138 void BrowsingDataRemover::set_removing(bool removing) { | 142 void BrowsingDataRemover::set_removing(bool removing) { |
139 DCHECK(removing_ != removing); | 143 DCHECK(removing_ != removing); |
140 removing_ = removing; | 144 removing_ = removing; |
141 } | 145 } |
142 | 146 |
143 // Static. | 147 // Static. |
144 int BrowsingDataRemover::GenerateQuotaClientMask(int remove_mask) { | 148 int BrowsingDataRemover::GenerateQuotaClientMask(int remove_mask) { |
145 int quota_client_mask = 0; | 149 int quota_client_mask = 0; |
146 if (remove_mask & BrowsingDataRemover::REMOVE_FILE_SYSTEMS) | 150 if (remove_mask & BrowsingDataRemover::REMOVE_FILE_SYSTEMS) |
147 quota_client_mask |= quota::QuotaClient::kFileSystem; | 151 quota_client_mask |= quota::QuotaClient::kFileSystem; |
148 if (remove_mask & BrowsingDataRemover::REMOVE_WEBSQL) | 152 if (remove_mask & BrowsingDataRemover::REMOVE_WEBSQL) |
149 quota_client_mask |= quota::QuotaClient::kDatabase; | 153 quota_client_mask |= quota::QuotaClient::kDatabase; |
150 if (remove_mask & BrowsingDataRemover::REMOVE_APPCACHE) | 154 if (remove_mask & BrowsingDataRemover::REMOVE_APPCACHE) |
151 quota_client_mask |= quota::QuotaClient::kAppcache; | 155 quota_client_mask |= quota::QuotaClient::kAppcache; |
152 if (remove_mask & BrowsingDataRemover::REMOVE_INDEXEDDB) | 156 if (remove_mask & BrowsingDataRemover::REMOVE_INDEXEDDB) |
153 quota_client_mask |= quota::QuotaClient::kIndexedDatabase; | 157 quota_client_mask |= quota::QuotaClient::kIndexedDatabase; |
154 | 158 |
155 return quota_client_mask; | 159 return quota_client_mask; |
156 } | 160 } |
157 | 161 |
158 void BrowsingDataRemover::Remove(int remove_mask) { | 162 void BrowsingDataRemover::Remove(int remove_mask) { |
| 163 RemoveImpl(remove_mask, GURL(), false); |
| 164 } |
| 165 |
| 166 void BrowsingDataRemover::RemoveImpl(int remove_mask, |
| 167 const GURL& origin, |
| 168 bool remove_protected_origins) { |
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
160 set_removing(true); | 170 set_removing(true); |
161 remove_mask_ = remove_mask; | 171 remove_mask_ = remove_mask; |
| 172 remove_origin_ = origin; |
| 173 remove_protected_ = remove_protected_origins; |
162 | 174 |
163 if (remove_mask & REMOVE_HISTORY) { | 175 if (remove_mask & REMOVE_HISTORY) { |
164 HistoryService* history_service = | 176 HistoryService* history_service = |
165 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 177 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
166 if (history_service) { | 178 if (history_service) { |
167 std::set<GURL> restrict_urls; | 179 std::set<GURL> restrict_urls; |
| 180 if (!remove_origin_.is_empty()) |
| 181 restrict_urls.insert(remove_origin_); |
168 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); | 182 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
169 waiting_for_clear_history_ = true; | 183 waiting_for_clear_history_ = true; |
170 history_service->ExpireHistoryBetween(restrict_urls, | 184 history_service->ExpireHistoryBetween(restrict_urls, |
171 delete_begin_, delete_end_, | 185 delete_begin_, delete_end_, |
172 &request_consumer_, | 186 &request_consumer_, |
173 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, | 187 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, |
174 base::Unretained(this))); | 188 base::Unretained(this))); |
175 } | 189 } |
176 | 190 |
177 // Need to clear the host cache and accumulated speculative data, as it also | 191 // Need to clear the host cache and accumulated speculative data, as it also |
178 // reveals some history. | 192 // reveals some history: we have no mechanism to track when these items were |
| 193 // created, so we'll clear them all. Better safe than sorry. |
179 if (g_browser_process->io_thread()) { | 194 if (g_browser_process->io_thread()) { |
180 waiting_for_clear_networking_history_ = true; | 195 waiting_for_clear_networking_history_ = true; |
181 BrowserThread::PostTask( | 196 BrowserThread::PostTask( |
182 BrowserThread::IO, FROM_HERE, | 197 BrowserThread::IO, FROM_HERE, |
183 base::Bind(&BrowsingDataRemover::ClearNetworkingHistory, | 198 base::Bind(&BrowsingDataRemover::ClearNetworkingHistory, |
184 base::Unretained(this), g_browser_process->io_thread())); | 199 base::Unretained(this), g_browser_process->io_thread())); |
185 } | 200 } |
186 | 201 |
187 // As part of history deletion we also delete the auto-generated keywords. | 202 // As part of history deletion we also delete the auto-generated keywords. |
188 TemplateURLService* keywords_model = | 203 TemplateURLService* keywords_model = |
189 TemplateURLServiceFactory::GetForProfile(profile_); | 204 TemplateURLServiceFactory::GetForProfile(profile_); |
190 if (keywords_model && !keywords_model->loaded()) { | 205 if (keywords_model && !keywords_model->loaded()) { |
191 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 206 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
192 content::Source<TemplateURLService>(keywords_model)); | 207 content::Source<TemplateURLService>(keywords_model)); |
193 keywords_model->Load(); | 208 keywords_model->Load(); |
194 } else if (keywords_model) { | 209 } else if (keywords_model) { |
195 keywords_model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); | 210 keywords_model->RemoveAutoGeneratedForOriginBetween(remove_origin_, |
| 211 delete_begin_, delete_end_); |
196 } | 212 } |
197 | 213 |
198 // We also delete the list of recently closed tabs. Since these expire, | |
199 // they can't be more than a day old, so we can simply clear them all. | |
200 TabRestoreService* tab_service = | |
201 TabRestoreServiceFactory::GetForProfile(profile_); | |
202 if (tab_service) { | |
203 tab_service->ClearEntries(); | |
204 tab_service->DeleteLastSession(); | |
205 } | |
206 | |
207 // We also delete the last session when we delete the history. | |
208 SessionService* session_service = | |
209 SessionServiceFactory::GetForProfile(profile_); | |
210 if (session_service) | |
211 session_service->DeleteLastSession(); | |
212 | |
213 // The PrerenderManager keeps history of prerendered pages, so clear that. | 214 // The PrerenderManager keeps history of prerendered pages, so clear that. |
214 // It also may have a prerendered page. If so, the page could be considered | 215 // It also may have a prerendered page. If so, the page could be |
215 // to have a small amount of historical information, so delete it, too. | 216 // considered to have a small amount of historical information, so delete |
| 217 // it, too. |
216 prerender::PrerenderManager* prerender_manager = | 218 prerender::PrerenderManager* prerender_manager = |
217 prerender::PrerenderManagerFactory::GetForProfile(profile_); | 219 prerender::PrerenderManagerFactory::GetForProfile(profile_); |
218 if (prerender_manager) { | 220 if (prerender_manager) { |
219 prerender_manager->ClearData( | 221 prerender_manager->ClearData( |
220 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | | 222 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | |
221 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); | 223 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); |
222 } | 224 } |
| 225 |
| 226 // If the caller is removing history for all hosts, then clear ancillary |
| 227 // historical information. |
| 228 if (remove_origin_.is_empty()) { |
| 229 // We also delete the list of recently closed tabs. Since these expire, |
| 230 // they can't be more than a day old, so we can simply clear them all. |
| 231 TabRestoreService* tab_service = |
| 232 TabRestoreServiceFactory::GetForProfile(profile_); |
| 233 if (tab_service) { |
| 234 tab_service->ClearEntries(); |
| 235 tab_service->DeleteLastSession(); |
| 236 } |
| 237 |
| 238 // We also delete the last session when we delete the history. |
| 239 SessionService* session_service = |
| 240 SessionServiceFactory::GetForProfile(profile_); |
| 241 if (session_service) |
| 242 session_service->DeleteLastSession(); |
| 243 } |
223 } | 244 } |
224 | 245 |
225 if (remove_mask & REMOVE_DOWNLOADS) { | 246 if (remove_mask & REMOVE_DOWNLOADS) { |
226 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); | 247 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); |
227 DownloadManager* download_manager = | 248 DownloadManager* download_manager = |
228 DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager(); | 249 DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager(); |
229 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); | 250 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); |
230 download_manager->ClearLastDownloadPath(); | 251 download_manager->ClearLastDownloadPath(); |
231 } | 252 } |
232 | 253 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 BrowserThread::UI, FROM_HERE, | 679 BrowserThread::UI, FROM_HERE, |
659 base::Bind(&BrowsingDataRemover::OnClearedOriginBoundCerts, | 680 base::Bind(&BrowsingDataRemover::OnClearedOriginBoundCerts, |
660 base::Unretained(this))); | 681 base::Unretained(this))); |
661 } | 682 } |
662 | 683 |
663 void BrowsingDataRemover::OnClearedOriginBoundCerts() { | 684 void BrowsingDataRemover::OnClearedOriginBoundCerts() { |
664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
665 waiting_for_clear_origin_bound_certs_ = false; | 686 waiting_for_clear_origin_bound_certs_ = false; |
666 NotifyAndDeleteIfDone(); | 687 NotifyAndDeleteIfDone(); |
667 } | 688 } |
OLD | NEW |