| 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_impl.h" | 5 #include "content/browser/browsing_data/browsing_data_remover_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/metrics/user_metrics.h" | 18 #include "base/metrics/user_metrics.h" |
| 19 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h" | 19 #include "content/browser/browsing_data/storage_partition_http_cache_data_remove
r.h" |
| 20 #include "chrome/browser/profiles/profile.h" | |
| 21 #include "chrome/common/pref_names.h" | |
| 22 #include "components/prefs/pref_service.h" | |
| 23 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 24 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/browsing_data_filter_builder.h" | 22 #include "content/public/browser/browsing_data_filter_builder.h" |
| 23 #include "content/public/browser/browsing_data_remover_delegate.h" |
| 26 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
| 27 #include "content/public/browser/download_manager.h" | 25 #include "content/public/browser/download_manager.h" |
| 28 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/browser/storage_partition.h" | 27 #include "content/public/browser/storage_partition.h" |
| 30 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 31 #include "net/cookies/cookie_store.h" | 29 #include "net/cookies/cookie_store.h" |
| 32 #include "net/http/http_network_session.h" | 30 #include "net/http/http_network_session.h" |
| 33 #include "net/http/http_transaction_factory.h" | 31 #include "net/http/http_transaction_factory.h" |
| 34 #include "net/http/transport_security_state.h" | 32 #include "net/http/transport_security_state.h" |
| 35 #include "net/ssl/channel_id_service.h" | 33 #include "net/ssl/channel_id_service.h" |
| 36 #include "net/ssl/channel_id_store.h" | 34 #include "net/ssl/channel_id_store.h" |
| 37 #include "net/url_request/url_request_context.h" | 35 #include "net/url_request/url_request_context.h" |
| 38 #include "net/url_request/url_request_context_getter.h" | 36 #include "net/url_request/url_request_context_getter.h" |
| 39 #include "ppapi/features/features.h" | 37 #include "ppapi/features/features.h" |
| 40 #include "storage/browser/quota/special_storage_policy.h" | 38 #include "storage/browser/quota/special_storage_policy.h" |
| 41 #include "url/origin.h" | 39 #include "url/origin.h" |
| 42 | 40 |
| 43 using base::UserMetricsAction; | 41 using base::UserMetricsAction; |
| 44 using content::BrowserContext; | 42 |
| 45 using content::BrowserThread; | 43 namespace content { |
| 46 using content::BrowsingDataFilterBuilder; | |
| 47 using content::DOMStorageContext; | |
| 48 | 44 |
| 49 namespace { | 45 namespace { |
| 50 | 46 |
| 51 // Returns whether |origin| matches |origin_type_mask| given the special | 47 // Returns whether |origin| matches |origin_type_mask| given the special |
| 52 // storage |policy|; and if |predicate| is not null, then also whether | 48 // storage |policy|; and if |predicate| is not null, then also whether |
| 53 // it matches |predicate|. If |origin_type_mask| contains embedder-specific | 49 // it matches |predicate|. If |origin_type_mask| contains embedder-specific |
| 54 // datatypes, |embedder_matcher| must not be null; the decision for those | 50 // datatypes, |embedder_matcher| must not be null; the decision for those |
| 55 // datatypes will be delegated to it. | 51 // datatypes will be delegated to it. |
| 56 bool DoesOriginMatchMaskAndURLs( | 52 bool DoesOriginMatchMaskAndURLs( |
| 57 int origin_type_mask, | 53 int origin_type_mask, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 156 } |
| 161 | 157 |
| 162 void BrowsingDataRemoverImpl::SubTask::CompletionCallback() { | 158 void BrowsingDataRemoverImpl::SubTask::CompletionCallback() { |
| 163 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 159 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 164 DCHECK(is_pending_); | 160 DCHECK(is_pending_); |
| 165 is_pending_ = false; | 161 is_pending_ = false; |
| 166 forward_callback_.Run(); | 162 forward_callback_.Run(); |
| 167 } | 163 } |
| 168 | 164 |
| 169 BrowsingDataRemoverImpl::BrowsingDataRemoverImpl( | 165 BrowsingDataRemoverImpl::BrowsingDataRemoverImpl( |
| 170 content::BrowserContext* browser_context) | 166 BrowserContext* browser_context) |
| 171 : browser_context_(browser_context), | 167 : browser_context_(browser_context), |
| 172 remove_mask_(-1), | 168 remove_mask_(-1), |
| 173 origin_type_mask_(-1), | 169 origin_type_mask_(-1), |
| 174 is_removing_(false), | 170 is_removing_(false), |
| 175 sub_task_forward_callback_( | 171 sub_task_forward_callback_( |
| 176 base::Bind(&BrowsingDataRemoverImpl::NotifyIfDone, | 172 base::Bind(&BrowsingDataRemoverImpl::NotifyIfDone, |
| 177 base::Unretained(this))), | 173 base::Unretained(this))), |
| 178 synchronous_clear_operations_(sub_task_forward_callback_), | 174 synchronous_clear_operations_(sub_task_forward_callback_), |
| 179 clear_embedder_data_(sub_task_forward_callback_), | 175 clear_embedder_data_(sub_task_forward_callback_), |
| 180 clear_cache_(sub_task_forward_callback_), | 176 clear_cache_(sub_task_forward_callback_), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 196 // (albeit unsucessfuly) processed, so they can unregister themselves. | 192 // (albeit unsucessfuly) processed, so they can unregister themselves. |
| 197 // TODO(bauerb): If it becomes a problem that browsing data might not actually | 193 // TODO(bauerb): If it becomes a problem that browsing data might not actually |
| 198 // be fully cleared when an observer is notified, add a success flag. | 194 // be fully cleared when an observer is notified, add a success flag. |
| 199 while (!task_queue_.empty()) { | 195 while (!task_queue_.empty()) { |
| 200 if (observer_list_.HasObserver(task_queue_.front().observer)) | 196 if (observer_list_.HasObserver(task_queue_.front().observer)) |
| 201 task_queue_.front().observer->OnBrowsingDataRemoverDone(); | 197 task_queue_.front().observer->OnBrowsingDataRemoverDone(); |
| 202 task_queue_.pop(); | 198 task_queue_.pop(); |
| 203 } | 199 } |
| 204 } | 200 } |
| 205 | 201 |
| 206 void BrowsingDataRemoverImpl::Shutdown() { | |
| 207 embedder_delegate_.reset(); | |
| 208 } | |
| 209 | |
| 210 void BrowsingDataRemoverImpl::SetRemoving(bool is_removing) { | 202 void BrowsingDataRemoverImpl::SetRemoving(bool is_removing) { |
| 211 DCHECK_NE(is_removing_, is_removing); | 203 DCHECK_NE(is_removing_, is_removing); |
| 212 is_removing_ = is_removing; | 204 is_removing_ = is_removing; |
| 213 } | 205 } |
| 214 | 206 |
| 215 void BrowsingDataRemoverImpl::SetEmbedderDelegate( | 207 void BrowsingDataRemoverImpl::SetEmbedderDelegate( |
| 216 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) { | 208 BrowsingDataRemoverDelegate* embedder_delegate) { |
| 217 embedder_delegate_ = std::move(embedder_delegate); | 209 embedder_delegate_ = embedder_delegate; |
| 218 } | |
| 219 | |
| 220 BrowsingDataRemoverDelegate* | |
| 221 BrowsingDataRemoverImpl::GetEmbedderDelegate() const { | |
| 222 return embedder_delegate_.get(); | |
| 223 } | 210 } |
| 224 | 211 |
| 225 bool BrowsingDataRemoverImpl::DoesOriginMatchMask( | 212 bool BrowsingDataRemoverImpl::DoesOriginMatchMask( |
| 226 int origin_type_mask, | 213 int origin_type_mask, |
| 227 const GURL& origin, | 214 const GURL& origin, |
| 228 storage::SpecialStoragePolicy* policy) const { | 215 storage::SpecialStoragePolicy* policy) const { |
| 229 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; | 216 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; |
| 230 if (embedder_delegate_) | 217 if (embedder_delegate_) |
| 231 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); | 218 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); |
| 232 | 219 |
| 233 return DoesOriginMatchMaskAndURLs(origin_type_mask, | 220 return DoesOriginMatchMaskAndURLs(origin_type_mask, |
| 234 base::Callback<bool(const GURL&)>(), | 221 base::Callback<bool(const GURL&)>(), |
| 235 embedder_matcher, origin, policy); | 222 embedder_matcher, origin, policy); |
| 236 } | 223 } |
| 237 | 224 |
| 238 void BrowsingDataRemoverImpl::Remove(const base::Time& delete_begin, | 225 void BrowsingDataRemoverImpl::Remove(const base::Time& delete_begin, |
| 239 const base::Time& delete_end, | 226 const base::Time& delete_end, |
| 240 int remove_mask, | 227 int remove_mask, |
| 241 int origin_type_mask) { | 228 int origin_type_mask) { |
| 242 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, | 229 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, |
| 243 std::unique_ptr<BrowsingDataFilterBuilder>(), nullptr); | 230 std::unique_ptr<BrowsingDataFilterBuilder>(), nullptr); |
| 244 } | 231 } |
| 245 | 232 |
| 246 void BrowsingDataRemoverImpl::RemoveAndReply( | 233 void BrowsingDataRemoverImpl::RemoveAndReply(const base::Time& delete_begin, |
| 247 const base::Time& delete_begin, | 234 const base::Time& delete_end, |
| 248 const base::Time& delete_end, | 235 int remove_mask, |
| 249 int remove_mask, | 236 int origin_type_mask, |
| 250 int origin_type_mask, | 237 Observer* observer) { |
| 251 Observer* observer) { | |
| 252 DCHECK(observer); | 238 DCHECK(observer); |
| 253 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, | 239 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, |
| 254 std::unique_ptr<BrowsingDataFilterBuilder>(), observer); | 240 std::unique_ptr<BrowsingDataFilterBuilder>(), observer); |
| 255 } | 241 } |
| 256 | 242 |
| 257 void BrowsingDataRemoverImpl::RemoveWithFilter( | 243 void BrowsingDataRemoverImpl::RemoveWithFilter( |
| 258 const base::Time& delete_begin, | 244 const base::Time& delete_begin, |
| 259 const base::Time& delete_end, | 245 const base::Time& delete_end, |
| 260 int remove_mask, | 246 int remove_mask, |
| 261 int origin_type_mask, | 247 int origin_type_mask, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 285 int origin_type_mask, | 271 int origin_type_mask, |
| 286 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, | 272 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, |
| 287 Observer* observer) { | 273 Observer* observer) { |
| 288 DCHECK(!observer || observer_list_.HasObserver(observer)) | 274 DCHECK(!observer || observer_list_.HasObserver(observer)) |
| 289 << "Every observer must register itself (by calling AddObserver()) " | 275 << "Every observer must register itself (by calling AddObserver()) " |
| 290 << "before observing a removal task."; | 276 << "before observing a removal task."; |
| 291 | 277 |
| 292 // Remove() and RemoveAndReply() pass a null pointer to indicate no filter. | 278 // Remove() and RemoveAndReply() pass a null pointer to indicate no filter. |
| 293 // No filter is equivalent to one that |IsEmptyBlacklist()|. | 279 // No filter is equivalent to one that |IsEmptyBlacklist()|. |
| 294 if (!filter_builder) { | 280 if (!filter_builder) { |
| 295 filter_builder = BrowsingDataFilterBuilder::Create( | 281 filter_builder = |
| 296 BrowsingDataFilterBuilder::BLACKLIST); | 282 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST); |
| 297 DCHECK(filter_builder->IsEmptyBlacklist()); | 283 DCHECK(filter_builder->IsEmptyBlacklist()); |
| 298 } | 284 } |
| 299 | 285 |
| 300 task_queue_.emplace( | 286 task_queue_.emplace(delete_begin, delete_end, remove_mask, origin_type_mask, |
| 301 delete_begin, | 287 std::move(filter_builder), observer); |
| 302 delete_end, | |
| 303 remove_mask, | |
| 304 origin_type_mask, | |
| 305 std::move(filter_builder), | |
| 306 observer); | |
| 307 | 288 |
| 308 // If this is the only scheduled task, execute it immediately. Otherwise, | 289 // If this is the only scheduled task, execute it immediately. Otherwise, |
| 309 // it will be automatically executed when all tasks scheduled before it | 290 // it will be automatically executed when all tasks scheduled before it |
| 310 // finish. | 291 // finish. |
| 311 if (task_queue_.size() == 1) { | 292 if (task_queue_.size() == 1) { |
| 312 SetRemoving(true); | 293 SetRemoving(true); |
| 313 RunNextTask(); | 294 RunNextTask(); |
| 314 } | 295 } |
| 315 } | 296 } |
| 316 | 297 |
| 317 void BrowsingDataRemoverImpl::RunNextTask() { | 298 void BrowsingDataRemoverImpl::RunNextTask() { |
| 318 DCHECK(!task_queue_.empty()); | 299 DCHECK(!task_queue_.empty()); |
| 319 const RemovalTask& removal_task = task_queue_.front(); | 300 const RemovalTask& removal_task = task_queue_.front(); |
| 320 | 301 |
| 321 RemoveImpl(removal_task.delete_begin, | 302 RemoveImpl(removal_task.delete_begin, removal_task.delete_end, |
| 322 removal_task.delete_end, | 303 removal_task.remove_mask, *removal_task.filter_builder, |
| 323 removal_task.remove_mask, | |
| 324 *removal_task.filter_builder, | |
| 325 removal_task.origin_type_mask); | 304 removal_task.origin_type_mask); |
| 326 } | 305 } |
| 327 | 306 |
| 328 void BrowsingDataRemoverImpl::RemoveImpl( | 307 void BrowsingDataRemoverImpl::RemoveImpl( |
| 329 const base::Time& delete_begin, | 308 const base::Time& delete_begin, |
| 330 const base::Time& delete_end, | 309 const base::Time& delete_end, |
| 331 int remove_mask, | 310 int remove_mask, |
| 332 const BrowsingDataFilterBuilder& filter_builder, | 311 const BrowsingDataFilterBuilder& filter_builder, |
| 333 int origin_type_mask) { | 312 int origin_type_mask) { |
| 334 // =============== README before adding more storage backends =============== | 313 // =============== README before adding more storage backends =============== |
| (...skipping 21 matching lines...) Expand all Loading... |
| 356 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE; | 335 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE; |
| 357 if (remove_mask & DATA_TYPE_COOKIES && | 336 if (remove_mask & DATA_TYPE_COOKIES && |
| 358 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { | 337 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { |
| 359 choice = | 338 choice = |
| 360 remove_mask & DATA_TYPE_CACHE ? BOTH_COOKIES_AND_CACHE : ONLY_COOKIES; | 339 remove_mask & DATA_TYPE_CACHE ? BOTH_COOKIES_AND_CACHE : ONLY_COOKIES; |
| 361 } else if (remove_mask & DATA_TYPE_CACHE) { | 340 } else if (remove_mask & DATA_TYPE_CACHE) { |
| 362 choice = ONLY_CACHE; | 341 choice = ONLY_CACHE; |
| 363 } | 342 } |
| 364 | 343 |
| 365 UMA_HISTOGRAM_ENUMERATION( | 344 UMA_HISTOGRAM_ENUMERATION( |
| 366 "History.ClearBrowsingData.UserDeletedCookieOrCache", | 345 "History.ClearBrowsingData.UserDeletedCookieOrCache", choice, |
| 367 choice, MAX_CHOICE_VALUE); | 346 MAX_CHOICE_VALUE); |
| 368 | |
| 369 // Managed devices and supervised users can have restrictions on history | |
| 370 // deletion. | |
| 371 // TODO(crbug.com/668114): This should be provided via ContentBrowserClient | |
| 372 // once BrowsingDataRemoverImpl moves to content. | |
| 373 PrefService* prefs = | |
| 374 Profile::FromBrowserContext(browser_context_)->GetPrefs(); | |
| 375 bool may_delete_history = | |
| 376 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory); | |
| 377 | 347 |
| 378 ////////////////////////////////////////////////////////////////////////////// | 348 ////////////////////////////////////////////////////////////////////////////// |
| 379 // INITIALIZATION | 349 // INITIALIZATION |
| 380 base::Callback<bool(const GURL& url)> filter = | 350 base::Callback<bool(const GURL& url)> filter = |
| 381 filter_builder.BuildGeneralFilter(); | 351 filter_builder.BuildGeneralFilter(); |
| 382 | 352 |
| 383 ////////////////////////////////////////////////////////////////////////////// | 353 ////////////////////////////////////////////////////////////////////////////// |
| 384 // DATA_TYPE_DOWNLOADS | 354 // DATA_TYPE_DOWNLOADS |
| 385 if ((remove_mask & DATA_TYPE_DOWNLOADS) && may_delete_history) { | 355 if ((remove_mask & DATA_TYPE_DOWNLOADS) && |
| 356 (!embedder_delegate_ || embedder_delegate_->MayRemoveDownloadHistory())) { |
| 386 base::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); | 357 base::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); |
| 387 content::DownloadManager* download_manager = | 358 DownloadManager* download_manager = |
| 388 BrowserContext::GetDownloadManager(browser_context_); | 359 BrowserContext::GetDownloadManager(browser_context_); |
| 389 download_manager->RemoveDownloadsByURLAndTime(filter, | 360 download_manager->RemoveDownloadsByURLAndTime(filter, delete_begin_, |
| 390 delete_begin_, delete_end_); | 361 delete_end_); |
| 391 } | 362 } |
| 392 | 363 |
| 393 ////////////////////////////////////////////////////////////////////////////// | 364 ////////////////////////////////////////////////////////////////////////////// |
| 394 // DATA_TYPE_CHANNEL_IDS | 365 // DATA_TYPE_CHANNEL_IDS |
| 395 // Channel IDs are not separated for protected and unprotected web | 366 // Channel IDs are not separated for protected and unprotected web |
| 396 // origins. We check the origin_type_mask_ to prevent unintended deletion. | 367 // origins. We check the origin_type_mask_ to prevent unintended deletion. |
| 397 if (remove_mask & DATA_TYPE_CHANNEL_IDS && | 368 if (remove_mask & DATA_TYPE_CHANNEL_IDS && |
| 398 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { | 369 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { |
| 399 base::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs")); | 370 base::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs")); |
| 400 // Since we are running on the UI thread don't call GetURLRequestContext(). | 371 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 401 scoped_refptr<net::URLRequestContextGetter> rq_context = | 372 scoped_refptr<net::URLRequestContextGetter> rq_context = |
| 402 content::BrowserContext::GetDefaultStoragePartition(browser_context_)-> | 373 BrowserContext::GetDefaultStoragePartition(browser_context_) |
| 403 GetURLRequestContext(); | 374 ->GetURLRequestContext(); |
| 404 clear_channel_ids_.Start(); | 375 clear_channel_ids_.Start(); |
| 405 BrowserThread::PostTask( | 376 BrowserThread::PostTask( |
| 406 BrowserThread::IO, FROM_HERE, | 377 BrowserThread::IO, FROM_HERE, |
| 407 base::BindOnce(&ClearChannelIDsOnIOThread, | 378 base::BindOnce(&ClearChannelIDsOnIOThread, |
| 408 filter_builder.BuildChannelIDFilter(), delete_begin_, | 379 filter_builder.BuildChannelIDFilter(), delete_begin_, |
| 409 delete_end_, std::move(rq_context), | 380 delete_end_, std::move(rq_context), |
| 410 clear_channel_ids_.GetCompletionCallback())); | 381 clear_channel_ids_.GetCompletionCallback())); |
| 411 } | 382 } |
| 412 | 383 |
| 413 ////////////////////////////////////////////////////////////////////////////// | 384 ////////////////////////////////////////////////////////////////////////////// |
| 414 // STORAGE PARTITION DATA | 385 // STORAGE PARTITION DATA |
| 415 uint32_t storage_partition_remove_mask = 0; | 386 uint32_t storage_partition_remove_mask = 0; |
| 416 | 387 |
| 417 // We ignore the DATA_TYPE_COOKIES request if UNPROTECTED_WEB is not set, | 388 // We ignore the DATA_TYPE_COOKIES request if UNPROTECTED_WEB is not set, |
| 418 // so that callers who request DATA_TYPE_SITE_DATA with another origin type | 389 // so that callers who request DATA_TYPE_SITE_DATA with another origin type |
| 419 // don't accidentally remove the cookies that are associated with the | 390 // don't accidentally remove the cookies that are associated with the |
| 420 // UNPROTECTED_WEB origin. This is necessary because cookies are not separated | 391 // UNPROTECTED_WEB origin. This is necessary because cookies are not separated |
| 421 // between UNPROTECTED_WEB and other origin types. | 392 // between UNPROTECTED_WEB and other origin types. |
| 422 if (remove_mask & DATA_TYPE_COOKIES && | 393 if (remove_mask & DATA_TYPE_COOKIES && |
| 423 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { | 394 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { |
| 424 storage_partition_remove_mask |= | 395 storage_partition_remove_mask |= StoragePartition::REMOVE_DATA_MASK_COOKIES; |
| 425 content::StoragePartition::REMOVE_DATA_MASK_COOKIES; | |
| 426 } | 396 } |
| 427 if (remove_mask & DATA_TYPE_LOCAL_STORAGE) { | 397 if (remove_mask & DATA_TYPE_LOCAL_STORAGE) { |
| 428 storage_partition_remove_mask |= | 398 storage_partition_remove_mask |= |
| 429 content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; | 399 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; |
| 430 } | 400 } |
| 431 if (remove_mask & DATA_TYPE_INDEXED_DB) { | 401 if (remove_mask & DATA_TYPE_INDEXED_DB) { |
| 432 storage_partition_remove_mask |= | 402 storage_partition_remove_mask |= |
| 433 content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; | 403 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; |
| 434 } | 404 } |
| 435 if (remove_mask & DATA_TYPE_WEB_SQL) { | 405 if (remove_mask & DATA_TYPE_WEB_SQL) { |
| 436 storage_partition_remove_mask |= | 406 storage_partition_remove_mask |= StoragePartition::REMOVE_DATA_MASK_WEBSQL; |
| 437 content::StoragePartition::REMOVE_DATA_MASK_WEBSQL; | |
| 438 } | 407 } |
| 439 if (remove_mask & DATA_TYPE_APP_CACHE) { | 408 if (remove_mask & DATA_TYPE_APP_CACHE) { |
| 440 storage_partition_remove_mask |= | 409 storage_partition_remove_mask |= |
| 441 content::StoragePartition::REMOVE_DATA_MASK_APPCACHE; | 410 StoragePartition::REMOVE_DATA_MASK_APPCACHE; |
| 442 } | 411 } |
| 443 if (remove_mask & DATA_TYPE_SERVICE_WORKERS) { | 412 if (remove_mask & DATA_TYPE_SERVICE_WORKERS) { |
| 444 storage_partition_remove_mask |= | 413 storage_partition_remove_mask |= |
| 445 content::StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS; | 414 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS; |
| 446 } | 415 } |
| 447 if (remove_mask & DATA_TYPE_CACHE_STORAGE) { | 416 if (remove_mask & DATA_TYPE_CACHE_STORAGE) { |
| 448 storage_partition_remove_mask |= | 417 storage_partition_remove_mask |= |
| 449 content::StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE; | 418 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE; |
| 450 } | 419 } |
| 451 if (remove_mask & DATA_TYPE_FILE_SYSTEMS) { | 420 if (remove_mask & DATA_TYPE_FILE_SYSTEMS) { |
| 452 storage_partition_remove_mask |= | 421 storage_partition_remove_mask |= |
| 453 content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; | 422 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; |
| 454 } | 423 } |
| 455 | 424 |
| 456 // Content Decryption Modules used by Encrypted Media store licenses in a | 425 // Content Decryption Modules used by Encrypted Media store licenses in a |
| 457 // private filesystem. These are different than content licenses used by | 426 // private filesystem. These are different than content licenses used by |
| 458 // Flash (which are deleted father down in this method). | 427 // Flash (which are deleted father down in this method). |
| 459 if (remove_mask & DATA_TYPE_MEDIA_LICENSES) { | 428 if (remove_mask & DATA_TYPE_MEDIA_LICENSES) { |
| 460 storage_partition_remove_mask |= | 429 storage_partition_remove_mask |= |
| 461 content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA; | 430 StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA; |
| 462 } | 431 } |
| 463 | 432 |
| 464 content::StoragePartition* storage_partition; | 433 StoragePartition* storage_partition; |
| 465 if (storage_partition_for_testing_) { | 434 if (storage_partition_for_testing_) { |
| 466 storage_partition = storage_partition_for_testing_; | 435 storage_partition = storage_partition_for_testing_; |
| 467 } else { | 436 } else { |
| 468 storage_partition = | 437 storage_partition = |
| 469 BrowserContext::GetDefaultStoragePartition(browser_context_); | 438 BrowserContext::GetDefaultStoragePartition(browser_context_); |
| 470 } | 439 } |
| 471 | 440 |
| 472 if (storage_partition_remove_mask) { | 441 if (storage_partition_remove_mask) { |
| 473 clear_storage_partition_data_.Start(); | 442 clear_storage_partition_data_.Start(); |
| 474 | 443 |
| 475 uint32_t quota_storage_remove_mask = | 444 uint32_t quota_storage_remove_mask = |
| 476 ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | 445 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; |
| 477 | 446 |
| 478 if (delete_begin_ == base::Time() || | 447 if (delete_begin_ == base::Time() || |
| 479 ((origin_type_mask_ & ~ORIGIN_TYPE_UNPROTECTED_WEB) != 0)) { | 448 ((origin_type_mask_ & ~ORIGIN_TYPE_UNPROTECTED_WEB) != 0)) { |
| 480 // If we're deleting since the beginning of time, or we're removing | 449 // If we're deleting since the beginning of time, or we're removing |
| 481 // protected origins, then remove persistent quota data. | 450 // protected origins, then remove persistent quota data. |
| 482 quota_storage_remove_mask |= | 451 quota_storage_remove_mask |= |
| 483 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | 452 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; |
| 484 } | 453 } |
| 485 | 454 |
| 486 // If cookies are supposed to be conditionally deleted from the storage | 455 // If cookies are supposed to be conditionally deleted from the storage |
| 487 // partition, create a cookie matcher function. | 456 // partition, create a cookie matcher function. |
| 488 content::StoragePartition::CookieMatcherFunction cookie_matcher; | 457 StoragePartition::CookieMatcherFunction cookie_matcher; |
| 489 if (!filter_builder.IsEmptyBlacklist() && | 458 if (!filter_builder.IsEmptyBlacklist() && |
| 490 (storage_partition_remove_mask & | 459 (storage_partition_remove_mask & |
| 491 content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) { | 460 StoragePartition::REMOVE_DATA_MASK_COOKIES)) { |
| 492 cookie_matcher = filter_builder.BuildCookieFilter(); | 461 cookie_matcher = filter_builder.BuildCookieFilter(); |
| 493 } | 462 } |
| 494 | 463 |
| 495 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; | 464 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; |
| 496 if (embedder_delegate_) | 465 if (embedder_delegate_) |
| 497 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); | 466 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); |
| 498 | 467 |
| 499 storage_partition->ClearData( | 468 storage_partition->ClearData( |
| 500 storage_partition_remove_mask, quota_storage_remove_mask, | 469 storage_partition_remove_mask, quota_storage_remove_mask, |
| 501 base::Bind(&DoesOriginMatchMaskAndURLs, origin_type_mask_, filter, | 470 base::Bind(&DoesOriginMatchMaskAndURLs, origin_type_mask_, filter, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 514 clear_cache_.Start(); | 483 clear_cache_.Start(); |
| 515 storage_partition->ClearHttpAndMediaCaches( | 484 storage_partition->ClearHttpAndMediaCaches( |
| 516 delete_begin, delete_end, | 485 delete_begin, delete_end, |
| 517 filter_builder.IsEmptyBlacklist() ? base::Callback<bool(const GURL&)>() | 486 filter_builder.IsEmptyBlacklist() ? base::Callback<bool(const GURL&)>() |
| 518 : filter, | 487 : filter, |
| 519 clear_cache_.GetCompletionCallback()); | 488 clear_cache_.GetCompletionCallback()); |
| 520 | 489 |
| 521 // Tell the shader disk cache to clear. | 490 // Tell the shader disk cache to clear. |
| 522 base::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); | 491 base::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); |
| 523 storage_partition_remove_mask |= | 492 storage_partition_remove_mask |= |
| 524 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; | 493 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; |
| 525 } | 494 } |
| 526 | 495 |
| 527 ////////////////////////////////////////////////////////////////////////////// | 496 ////////////////////////////////////////////////////////////////////////////// |
| 528 // Auth cache. | 497 // Auth cache. |
| 529 if (remove_mask & DATA_TYPE_COOKIES) { | 498 if (remove_mask & DATA_TYPE_COOKIES) { |
| 530 scoped_refptr<net::URLRequestContextGetter> request_context = | 499 scoped_refptr<net::URLRequestContextGetter> request_context = |
| 531 BrowserContext::GetDefaultStoragePartition(browser_context_) | 500 BrowserContext::GetDefaultStoragePartition(browser_context_) |
| 532 ->GetURLRequestContext(); | 501 ->GetURLRequestContext(); |
| 533 clear_http_auth_cache_.Start(); | 502 clear_http_auth_cache_.Start(); |
| 534 BrowserThread::PostTaskAndReply( | 503 BrowserThread::PostTaskAndReply( |
| 535 BrowserThread::IO, FROM_HERE, | 504 BrowserThread::IO, FROM_HERE, |
| 536 base::BindOnce(&ClearHttpAuthCacheOnIOThread, | 505 base::BindOnce(&ClearHttpAuthCacheOnIOThread, |
| 537 std::move(request_context), delete_begin_), | 506 std::move(request_context), delete_begin_), |
| 538 clear_http_auth_cache_.GetCompletionCallback()); | 507 clear_http_auth_cache_.GetCompletionCallback()); |
| 539 } | 508 } |
| 540 | 509 |
| 541 ////////////////////////////////////////////////////////////////////////////// | 510 ////////////////////////////////////////////////////////////////////////////// |
| 542 // Embedder data. | 511 // Embedder data. |
| 543 if (embedder_delegate_) { | 512 if (embedder_delegate_) { |
| 544 clear_embedder_data_.Start(); | 513 clear_embedder_data_.Start(); |
| 545 embedder_delegate_->RemoveEmbedderData( | 514 embedder_delegate_->RemoveEmbedderData( |
| 546 delete_begin_, | 515 delete_begin_, delete_end_, remove_mask, filter_builder, |
| 547 delete_end_, | 516 origin_type_mask, clear_embedder_data_.GetCompletionCallback()); |
| 548 remove_mask, | |
| 549 filter_builder, | |
| 550 origin_type_mask, | |
| 551 clear_embedder_data_.GetCompletionCallback()); | |
| 552 } | 517 } |
| 553 | 518 |
| 554 // Notify in case all actions taken were synchronous. | 519 // Notify in case all actions taken were synchronous. |
| 555 synchronous_clear_operations_.GetCompletionCallback().Run(); | 520 synchronous_clear_operations_.GetCompletionCallback().Run(); |
| 556 } | 521 } |
| 557 | 522 |
| 558 void BrowsingDataRemoverImpl::AddObserver(Observer* observer) { | 523 void BrowsingDataRemoverImpl::AddObserver(Observer* observer) { |
| 559 observer_list_.AddObserver(observer); | 524 observer_list_.AddObserver(observer); |
| 560 } | 525 } |
| 561 | 526 |
| 562 void BrowsingDataRemoverImpl::RemoveObserver(Observer* observer) { | 527 void BrowsingDataRemoverImpl::RemoveObserver(Observer* observer) { |
| 563 observer_list_.RemoveObserver(observer); | 528 observer_list_.RemoveObserver(observer); |
| 564 } | 529 } |
| 565 | 530 |
| 566 void BrowsingDataRemoverImpl::SetWouldCompleteCallbackForTesting( | 531 void BrowsingDataRemoverImpl::SetWouldCompleteCallbackForTesting( |
| 567 const base::Callback<void(const base::Closure& continue_to_completion)>& | 532 const base::Callback<void(const base::Closure& continue_to_completion)>& |
| 568 callback) { | 533 callback) { |
| 569 would_complete_callback_ = callback; | 534 would_complete_callback_ = callback; |
| 570 } | 535 } |
| 571 | 536 |
| 572 void BrowsingDataRemoverImpl::OverrideStoragePartitionForTesting( | 537 void BrowsingDataRemoverImpl::OverrideStoragePartitionForTesting( |
| 573 content::StoragePartition* storage_partition) { | 538 StoragePartition* storage_partition) { |
| 574 storage_partition_for_testing_ = storage_partition; | 539 storage_partition_for_testing_ = storage_partition; |
| 575 } | 540 } |
| 576 | 541 |
| 577 const base::Time& BrowsingDataRemoverImpl::GetLastUsedBeginTime() { | 542 const base::Time& BrowsingDataRemoverImpl::GetLastUsedBeginTime() { |
| 578 return delete_begin_; | 543 return delete_begin_; |
| 579 } | 544 } |
| 580 | 545 |
| 581 const base::Time& BrowsingDataRemoverImpl::GetLastUsedEndTime() { | 546 const base::Time& BrowsingDataRemoverImpl::GetLastUsedEndTime() { |
| 582 return delete_end_; | 547 return delete_end_; |
| 583 } | 548 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 601 delete_end(delete_end), | 566 delete_end(delete_end), |
| 602 remove_mask(remove_mask), | 567 remove_mask(remove_mask), |
| 603 origin_type_mask(origin_type_mask), | 568 origin_type_mask(origin_type_mask), |
| 604 filter_builder(std::move(filter_builder)), | 569 filter_builder(std::move(filter_builder)), |
| 605 observer(observer) {} | 570 observer(observer) {} |
| 606 | 571 |
| 607 BrowsingDataRemoverImpl::RemovalTask::~RemovalTask() {} | 572 BrowsingDataRemoverImpl::RemovalTask::~RemovalTask() {} |
| 608 | 573 |
| 609 bool BrowsingDataRemoverImpl::AllDone() { | 574 bool BrowsingDataRemoverImpl::AllDone() { |
| 610 return !synchronous_clear_operations_.is_pending() && | 575 return !synchronous_clear_operations_.is_pending() && |
| 611 !clear_embedder_data_.is_pending() && | 576 !clear_embedder_data_.is_pending() && !clear_cache_.is_pending() && |
| 612 !clear_cache_.is_pending() && | |
| 613 !clear_channel_ids_.is_pending() && | 577 !clear_channel_ids_.is_pending() && |
| 614 !clear_http_auth_cache_.is_pending() && | 578 !clear_http_auth_cache_.is_pending() && |
| 615 !clear_storage_partition_data_.is_pending(); | 579 !clear_storage_partition_data_.is_pending(); |
| 616 } | 580 } |
| 617 | 581 |
| 618 void BrowsingDataRemoverImpl::Notify() { | 582 void BrowsingDataRemoverImpl::Notify() { |
| 619 // Some tests call |RemoveImpl| directly, without using the task scheduler. | 583 // Some tests call |RemoveImpl| directly, without using the task scheduler. |
| 620 // TODO(msramek): Improve those tests so we don't have to do this. Tests | 584 // TODO(msramek): Improve those tests so we don't have to do this. Tests |
| 621 // relying on |RemoveImpl| do so because they need to pass in | 585 // relying on |RemoveImpl| do so because they need to pass in |
| 622 // BrowsingDataFilterBuilder while still keeping ownership of it. Making | 586 // BrowsingDataFilterBuilder while still keeping ownership of it. Making |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 636 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 673 base::WeakPtr<BrowsingDataRemoverImpl> weak_ptr = | 637 base::WeakPtr<BrowsingDataRemoverImpl> weak_ptr = |
| 674 weak_ptr_factory_.GetWeakPtr(); | 638 weak_ptr_factory_.GetWeakPtr(); |
| 675 | 639 |
| 676 // Immediately bind the weak pointer to the UI thread. This makes it easier | 640 // Immediately bind the weak pointer to the UI thread. This makes it easier |
| 677 // to discover potential misuse on the IO thread. | 641 // to discover potential misuse on the IO thread. |
| 678 weak_ptr.get(); | 642 weak_ptr.get(); |
| 679 | 643 |
| 680 return weak_ptr; | 644 return weak_ptr; |
| 681 } | 645 } |
| 646 |
| 647 } // namespace content |
| OLD | NEW |