| 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 } | 210 } |
| 219 | 211 |
| 220 BrowsingDataRemoverDelegate* | 212 BrowsingDataRemoverDelegate* BrowsingDataRemoverImpl::GetEmbedderDelegate() |
| 221 BrowsingDataRemoverImpl::GetEmbedderDelegate() const { | 213 const { |
| 222 return embedder_delegate_.get(); | 214 return embedder_delegate_; |
| 223 } | 215 } |
| 224 | 216 |
| 225 bool BrowsingDataRemoverImpl::DoesOriginMatchMask( | 217 bool BrowsingDataRemoverImpl::DoesOriginMatchMask( |
| 226 int origin_type_mask, | 218 int origin_type_mask, |
| 227 const GURL& origin, | 219 const GURL& origin, |
| 228 storage::SpecialStoragePolicy* policy) const { | 220 storage::SpecialStoragePolicy* policy) const { |
| 229 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; | 221 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; |
| 230 if (embedder_delegate_) | 222 if (embedder_delegate_) |
| 231 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); | 223 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); |
| 232 | 224 |
| 233 return DoesOriginMatchMaskAndURLs(origin_type_mask, | 225 return DoesOriginMatchMaskAndURLs(origin_type_mask, |
| 234 base::Callback<bool(const GURL&)>(), | 226 base::Callback<bool(const GURL&)>(), |
| 235 embedder_matcher, origin, policy); | 227 embedder_matcher, origin, policy); |
| 236 } | 228 } |
| 237 | 229 |
| 238 void BrowsingDataRemoverImpl::Remove(const base::Time& delete_begin, | 230 void BrowsingDataRemoverImpl::Remove(const base::Time& delete_begin, |
| 239 const base::Time& delete_end, | 231 const base::Time& delete_end, |
| 240 int remove_mask, | 232 int remove_mask, |
| 241 int origin_type_mask) { | 233 int origin_type_mask) { |
| 242 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, | 234 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, |
| 243 std::unique_ptr<BrowsingDataFilterBuilder>(), nullptr); | 235 std::unique_ptr<BrowsingDataFilterBuilder>(), nullptr); |
| 244 } | 236 } |
| 245 | 237 |
| 246 void BrowsingDataRemoverImpl::RemoveAndReply( | 238 void BrowsingDataRemoverImpl::RemoveAndReply(const base::Time& delete_begin, |
| 247 const base::Time& delete_begin, | 239 const base::Time& delete_end, |
| 248 const base::Time& delete_end, | 240 int remove_mask, |
| 249 int remove_mask, | 241 int origin_type_mask, |
| 250 int origin_type_mask, | 242 Observer* observer) { |
| 251 Observer* observer) { | |
| 252 DCHECK(observer); | 243 DCHECK(observer); |
| 253 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, | 244 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, |
| 254 std::unique_ptr<BrowsingDataFilterBuilder>(), observer); | 245 std::unique_ptr<BrowsingDataFilterBuilder>(), observer); |
| 255 } | 246 } |
| 256 | 247 |
| 257 void BrowsingDataRemoverImpl::RemoveWithFilter( | 248 void BrowsingDataRemoverImpl::RemoveWithFilter( |
| 258 const base::Time& delete_begin, | 249 const base::Time& delete_begin, |
| 259 const base::Time& delete_end, | 250 const base::Time& delete_end, |
| 260 int remove_mask, | 251 int remove_mask, |
| 261 int origin_type_mask, | 252 int origin_type_mask, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 285 int origin_type_mask, | 276 int origin_type_mask, |
| 286 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, | 277 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, |
| 287 Observer* observer) { | 278 Observer* observer) { |
| 288 DCHECK(!observer || observer_list_.HasObserver(observer)) | 279 DCHECK(!observer || observer_list_.HasObserver(observer)) |
| 289 << "Every observer must register itself (by calling AddObserver()) " | 280 << "Every observer must register itself (by calling AddObserver()) " |
| 290 << "before observing a removal task."; | 281 << "before observing a removal task."; |
| 291 | 282 |
| 292 // Remove() and RemoveAndReply() pass a null pointer to indicate no filter. | 283 // Remove() and RemoveAndReply() pass a null pointer to indicate no filter. |
| 293 // No filter is equivalent to one that |IsEmptyBlacklist()|. | 284 // No filter is equivalent to one that |IsEmptyBlacklist()|. |
| 294 if (!filter_builder) { | 285 if (!filter_builder) { |
| 295 filter_builder = BrowsingDataFilterBuilder::Create( | 286 filter_builder = |
| 296 BrowsingDataFilterBuilder::BLACKLIST); | 287 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST); |
| 297 DCHECK(filter_builder->IsEmptyBlacklist()); | 288 DCHECK(filter_builder->IsEmptyBlacklist()); |
| 298 } | 289 } |
| 299 | 290 |
| 300 task_queue_.emplace( | 291 task_queue_.emplace(delete_begin, delete_end, remove_mask, origin_type_mask, |
| 301 delete_begin, | 292 std::move(filter_builder), observer); |
| 302 delete_end, | |
| 303 remove_mask, | |
| 304 origin_type_mask, | |
| 305 std::move(filter_builder), | |
| 306 observer); | |
| 307 | 293 |
| 308 // If this is the only scheduled task, execute it immediately. Otherwise, | 294 // If this is the only scheduled task, execute it immediately. Otherwise, |
| 309 // it will be automatically executed when all tasks scheduled before it | 295 // it will be automatically executed when all tasks scheduled before it |
| 310 // finish. | 296 // finish. |
| 311 if (task_queue_.size() == 1) { | 297 if (task_queue_.size() == 1) { |
| 312 SetRemoving(true); | 298 SetRemoving(true); |
| 313 RunNextTask(); | 299 RunNextTask(); |
| 314 } | 300 } |
| 315 } | 301 } |
| 316 | 302 |
| 317 void BrowsingDataRemoverImpl::RunNextTask() { | 303 void BrowsingDataRemoverImpl::RunNextTask() { |
| 318 DCHECK(!task_queue_.empty()); | 304 DCHECK(!task_queue_.empty()); |
| 319 const RemovalTask& removal_task = task_queue_.front(); | 305 const RemovalTask& removal_task = task_queue_.front(); |
| 320 | 306 |
| 321 RemoveImpl(removal_task.delete_begin, | 307 RemoveImpl(removal_task.delete_begin, removal_task.delete_end, |
| 322 removal_task.delete_end, | 308 removal_task.remove_mask, *removal_task.filter_builder, |
| 323 removal_task.remove_mask, | |
| 324 *removal_task.filter_builder, | |
| 325 removal_task.origin_type_mask); | 309 removal_task.origin_type_mask); |
| 326 } | 310 } |
| 327 | 311 |
| 328 void BrowsingDataRemoverImpl::RemoveImpl( | 312 void BrowsingDataRemoverImpl::RemoveImpl( |
| 329 const base::Time& delete_begin, | 313 const base::Time& delete_begin, |
| 330 const base::Time& delete_end, | 314 const base::Time& delete_end, |
| 331 int remove_mask, | 315 int remove_mask, |
| 332 const BrowsingDataFilterBuilder& filter_builder, | 316 const BrowsingDataFilterBuilder& filter_builder, |
| 333 int origin_type_mask) { | 317 int origin_type_mask) { |
| 334 // =============== README before adding more storage backends =============== | 318 // =============== README before adding more storage backends =============== |
| (...skipping 21 matching lines...) Expand all Loading... |
| 356 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE; | 340 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE; |
| 357 if (remove_mask & DATA_TYPE_COOKIES && | 341 if (remove_mask & DATA_TYPE_COOKIES && |
| 358 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { | 342 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { |
| 359 choice = | 343 choice = |
| 360 remove_mask & DATA_TYPE_CACHE ? BOTH_COOKIES_AND_CACHE : ONLY_COOKIES; | 344 remove_mask & DATA_TYPE_CACHE ? BOTH_COOKIES_AND_CACHE : ONLY_COOKIES; |
| 361 } else if (remove_mask & DATA_TYPE_CACHE) { | 345 } else if (remove_mask & DATA_TYPE_CACHE) { |
| 362 choice = ONLY_CACHE; | 346 choice = ONLY_CACHE; |
| 363 } | 347 } |
| 364 | 348 |
| 365 UMA_HISTOGRAM_ENUMERATION( | 349 UMA_HISTOGRAM_ENUMERATION( |
| 366 "History.ClearBrowsingData.UserDeletedCookieOrCache", | 350 "History.ClearBrowsingData.UserDeletedCookieOrCache", choice, |
| 367 choice, MAX_CHOICE_VALUE); | 351 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 | 352 |
| 378 ////////////////////////////////////////////////////////////////////////////// | 353 ////////////////////////////////////////////////////////////////////////////// |
| 379 // INITIALIZATION | 354 // INITIALIZATION |
| 380 base::Callback<bool(const GURL& url)> filter = | 355 base::Callback<bool(const GURL& url)> filter = |
| 381 filter_builder.BuildGeneralFilter(); | 356 filter_builder.BuildGeneralFilter(); |
| 382 | 357 |
| 383 ////////////////////////////////////////////////////////////////////////////// | 358 ////////////////////////////////////////////////////////////////////////////// |
| 384 // DATA_TYPE_DOWNLOADS | 359 // DATA_TYPE_DOWNLOADS |
| 385 if ((remove_mask & DATA_TYPE_DOWNLOADS) && may_delete_history) { | 360 if ((remove_mask & DATA_TYPE_DOWNLOADS) && |
| 361 GetContentClient()->browser()->MayDeleteHistory(browser_context_)) { |
| 386 base::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); | 362 base::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); |
| 387 content::DownloadManager* download_manager = | 363 DownloadManager* download_manager = |
| 388 BrowserContext::GetDownloadManager(browser_context_); | 364 BrowserContext::GetDownloadManager(browser_context_); |
| 389 download_manager->RemoveDownloadsByURLAndTime(filter, | 365 download_manager->RemoveDownloadsByURLAndTime(filter, delete_begin_, |
| 390 delete_begin_, delete_end_); | 366 delete_end_); |
| 391 } | 367 } |
| 392 | 368 |
| 393 ////////////////////////////////////////////////////////////////////////////// | 369 ////////////////////////////////////////////////////////////////////////////// |
| 394 // DATA_TYPE_CHANNEL_IDS | 370 // DATA_TYPE_CHANNEL_IDS |
| 395 // Channel IDs are not separated for protected and unprotected web | 371 // Channel IDs are not separated for protected and unprotected web |
| 396 // origins. We check the origin_type_mask_ to prevent unintended deletion. | 372 // origins. We check the origin_type_mask_ to prevent unintended deletion. |
| 397 if (remove_mask & DATA_TYPE_CHANNEL_IDS && | 373 if (remove_mask & DATA_TYPE_CHANNEL_IDS && |
| 398 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { | 374 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { |
| 399 base::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs")); | 375 base::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs")); |
| 400 // Since we are running on the UI thread don't call GetURLRequestContext(). | 376 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 401 scoped_refptr<net::URLRequestContextGetter> rq_context = | 377 scoped_refptr<net::URLRequestContextGetter> rq_context = |
| 402 content::BrowserContext::GetDefaultStoragePartition(browser_context_)-> | 378 BrowserContext::GetDefaultStoragePartition(browser_context_) |
| 403 GetURLRequestContext(); | 379 ->GetURLRequestContext(); |
| 404 clear_channel_ids_.Start(); | 380 clear_channel_ids_.Start(); |
| 405 BrowserThread::PostTask( | 381 BrowserThread::PostTask( |
| 406 BrowserThread::IO, FROM_HERE, | 382 BrowserThread::IO, FROM_HERE, |
| 407 base::Bind(&ClearChannelIDsOnIOThread, | 383 base::Bind(&ClearChannelIDsOnIOThread, |
| 408 filter_builder.BuildChannelIDFilter(), | 384 filter_builder.BuildChannelIDFilter(), delete_begin_, |
| 409 delete_begin_, delete_end_, std::move(rq_context), | 385 delete_end_, std::move(rq_context), |
| 410 clear_channel_ids_.GetCompletionCallback())); | 386 clear_channel_ids_.GetCompletionCallback())); |
| 411 } | 387 } |
| 412 | 388 |
| 413 ////////////////////////////////////////////////////////////////////////////// | 389 ////////////////////////////////////////////////////////////////////////////// |
| 414 // STORAGE PARTITION DATA | 390 // STORAGE PARTITION DATA |
| 415 uint32_t storage_partition_remove_mask = 0; | 391 uint32_t storage_partition_remove_mask = 0; |
| 416 | 392 |
| 417 // We ignore the DATA_TYPE_COOKIES request if UNPROTECTED_WEB is not set, | 393 // 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 | 394 // 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 | 395 // don't accidentally remove the cookies that are associated with the |
| 420 // UNPROTECTED_WEB origin. This is necessary because cookies are not separated | 396 // UNPROTECTED_WEB origin. This is necessary because cookies are not separated |
| 421 // between UNPROTECTED_WEB and other origin types. | 397 // between UNPROTECTED_WEB and other origin types. |
| 422 if (remove_mask & DATA_TYPE_COOKIES && | 398 if (remove_mask & DATA_TYPE_COOKIES && |
| 423 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { | 399 origin_type_mask_ & ORIGIN_TYPE_UNPROTECTED_WEB) { |
| 424 storage_partition_remove_mask |= | 400 storage_partition_remove_mask |= StoragePartition::REMOVE_DATA_MASK_COOKIES; |
| 425 content::StoragePartition::REMOVE_DATA_MASK_COOKIES; | |
| 426 } | 401 } |
| 427 if (remove_mask & DATA_TYPE_LOCAL_STORAGE) { | 402 if (remove_mask & DATA_TYPE_LOCAL_STORAGE) { |
| 428 storage_partition_remove_mask |= | 403 storage_partition_remove_mask |= |
| 429 content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; | 404 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; |
| 430 } | 405 } |
| 431 if (remove_mask & DATA_TYPE_INDEXED_DB) { | 406 if (remove_mask & DATA_TYPE_INDEXED_DB) { |
| 432 storage_partition_remove_mask |= | 407 storage_partition_remove_mask |= |
| 433 content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; | 408 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; |
| 434 } | 409 } |
| 435 if (remove_mask & DATA_TYPE_WEB_SQL) { | 410 if (remove_mask & DATA_TYPE_WEB_SQL) { |
| 436 storage_partition_remove_mask |= | 411 storage_partition_remove_mask |= StoragePartition::REMOVE_DATA_MASK_WEBSQL; |
| 437 content::StoragePartition::REMOVE_DATA_MASK_WEBSQL; | |
| 438 } | 412 } |
| 439 if (remove_mask & DATA_TYPE_APP_CACHE) { | 413 if (remove_mask & DATA_TYPE_APP_CACHE) { |
| 440 storage_partition_remove_mask |= | 414 storage_partition_remove_mask |= |
| 441 content::StoragePartition::REMOVE_DATA_MASK_APPCACHE; | 415 StoragePartition::REMOVE_DATA_MASK_APPCACHE; |
| 442 } | 416 } |
| 443 if (remove_mask & DATA_TYPE_SERVICE_WORKERS) { | 417 if (remove_mask & DATA_TYPE_SERVICE_WORKERS) { |
| 444 storage_partition_remove_mask |= | 418 storage_partition_remove_mask |= |
| 445 content::StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS; | 419 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS; |
| 446 } | 420 } |
| 447 if (remove_mask & DATA_TYPE_CACHE_STORAGE) { | 421 if (remove_mask & DATA_TYPE_CACHE_STORAGE) { |
| 448 storage_partition_remove_mask |= | 422 storage_partition_remove_mask |= |
| 449 content::StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE; | 423 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE; |
| 450 } | 424 } |
| 451 if (remove_mask & DATA_TYPE_FILE_SYSTEMS) { | 425 if (remove_mask & DATA_TYPE_FILE_SYSTEMS) { |
| 452 storage_partition_remove_mask |= | 426 storage_partition_remove_mask |= |
| 453 content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; | 427 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; |
| 454 } | 428 } |
| 455 | 429 |
| 456 // Content Decryption Modules used by Encrypted Media store licenses in a | 430 // Content Decryption Modules used by Encrypted Media store licenses in a |
| 457 // private filesystem. These are different than content licenses used by | 431 // private filesystem. These are different than content licenses used by |
| 458 // Flash (which are deleted father down in this method). | 432 // Flash (which are deleted father down in this method). |
| 459 if (remove_mask & DATA_TYPE_MEDIA_LICENSES) { | 433 if (remove_mask & DATA_TYPE_MEDIA_LICENSES) { |
| 460 storage_partition_remove_mask |= | 434 storage_partition_remove_mask |= |
| 461 content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA; | 435 StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA; |
| 462 } | 436 } |
| 463 | 437 |
| 464 content::StoragePartition* storage_partition; | 438 content::StoragePartition* storage_partition; |
| 465 if (storage_partition_for_testing_) { | 439 if (storage_partition_for_testing_) { |
| 466 storage_partition = storage_partition_for_testing_; | 440 storage_partition = storage_partition_for_testing_; |
| 467 } else { | 441 } else { |
| 468 storage_partition = | 442 storage_partition = |
| 469 BrowserContext::GetDefaultStoragePartition(browser_context_); | 443 BrowserContext::GetDefaultStoragePartition(browser_context_); |
| 470 } | 444 } |
| 471 | 445 |
| 472 if (storage_partition_remove_mask) { | 446 if (storage_partition_remove_mask) { |
| 473 clear_storage_partition_data_.Start(); | 447 clear_storage_partition_data_.Start(); |
| 474 | 448 |
| 475 uint32_t quota_storage_remove_mask = | 449 uint32_t quota_storage_remove_mask = |
| 476 ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | 450 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; |
| 477 | 451 |
| 478 if (delete_begin_ == base::Time() || | 452 if (delete_begin_ == base::Time() || |
| 479 ((origin_type_mask_ & ~ORIGIN_TYPE_UNPROTECTED_WEB) != 0)) { | 453 ((origin_type_mask_ & ~ORIGIN_TYPE_UNPROTECTED_WEB) != 0)) { |
| 480 // If we're deleting since the beginning of time, or we're removing | 454 // If we're deleting since the beginning of time, or we're removing |
| 481 // protected origins, then remove persistent quota data. | 455 // protected origins, then remove persistent quota data. |
| 482 quota_storage_remove_mask |= | 456 quota_storage_remove_mask |= |
| 483 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | 457 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; |
| 484 } | 458 } |
| 485 | 459 |
| 486 // If cookies are supposed to be conditionally deleted from the storage | 460 // If cookies are supposed to be conditionally deleted from the storage |
| 487 // partition, create a cookie matcher function. | 461 // partition, create a cookie matcher function. |
| 488 content::StoragePartition::CookieMatcherFunction cookie_matcher; | 462 StoragePartition::CookieMatcherFunction cookie_matcher; |
| 489 if (!filter_builder.IsEmptyBlacklist() && | 463 if (!filter_builder.IsEmptyBlacklist() && |
| 490 (storage_partition_remove_mask & | 464 (storage_partition_remove_mask & |
| 491 content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) { | 465 StoragePartition::REMOVE_DATA_MASK_COOKIES)) { |
| 492 cookie_matcher = filter_builder.BuildCookieFilter(); | 466 cookie_matcher = filter_builder.BuildCookieFilter(); |
| 493 } | 467 } |
| 494 | 468 |
| 495 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; | 469 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; |
| 496 if (embedder_delegate_) | 470 if (embedder_delegate_) |
| 497 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); | 471 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); |
| 498 | 472 |
| 499 storage_partition->ClearData( | 473 storage_partition->ClearData( |
| 500 storage_partition_remove_mask, quota_storage_remove_mask, | 474 storage_partition_remove_mask, quota_storage_remove_mask, |
| 501 base::Bind(&DoesOriginMatchMaskAndURLs, origin_type_mask_, filter, | 475 base::Bind(&DoesOriginMatchMaskAndURLs, origin_type_mask_, filter, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 514 clear_cache_.Start(); | 488 clear_cache_.Start(); |
| 515 storage_partition->ClearHttpAndMediaCaches( | 489 storage_partition->ClearHttpAndMediaCaches( |
| 516 delete_begin, delete_end, | 490 delete_begin, delete_end, |
| 517 filter_builder.IsEmptyBlacklist() ? base::Callback<bool(const GURL&)>() | 491 filter_builder.IsEmptyBlacklist() ? base::Callback<bool(const GURL&)>() |
| 518 : filter, | 492 : filter, |
| 519 clear_cache_.GetCompletionCallback()); | 493 clear_cache_.GetCompletionCallback()); |
| 520 | 494 |
| 521 // Tell the shader disk cache to clear. | 495 // Tell the shader disk cache to clear. |
| 522 base::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); | 496 base::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); |
| 523 storage_partition_remove_mask |= | 497 storage_partition_remove_mask |= |
| 524 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; | 498 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; |
| 525 } | 499 } |
| 526 | 500 |
| 527 ////////////////////////////////////////////////////////////////////////////// | 501 ////////////////////////////////////////////////////////////////////////////// |
| 528 // Auth cache. | 502 // Auth cache. |
| 529 if (remove_mask & DATA_TYPE_COOKIES) { | 503 if (remove_mask & DATA_TYPE_COOKIES) { |
| 530 scoped_refptr<net::URLRequestContextGetter> request_context = | 504 scoped_refptr<net::URLRequestContextGetter> request_context = |
| 531 BrowserContext::GetDefaultStoragePartition(browser_context_) | 505 BrowserContext::GetDefaultStoragePartition(browser_context_) |
| 532 ->GetURLRequestContext(); | 506 ->GetURLRequestContext(); |
| 533 clear_http_auth_cache_.Start(); | 507 clear_http_auth_cache_.Start(); |
| 534 BrowserThread::PostTaskAndReply( | 508 BrowserThread::PostTaskAndReply( |
| 535 BrowserThread::IO, FROM_HERE, | 509 BrowserThread::IO, FROM_HERE, |
| 536 base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context), | 510 base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context), |
| 537 delete_begin_), | 511 delete_begin_), |
| 538 clear_http_auth_cache_.GetCompletionCallback()); | 512 clear_http_auth_cache_.GetCompletionCallback()); |
| 539 } | 513 } |
| 540 | 514 |
| 541 ////////////////////////////////////////////////////////////////////////////// | 515 ////////////////////////////////////////////////////////////////////////////// |
| 542 // Embedder data. | 516 // Embedder data. |
| 543 if (embedder_delegate_) { | 517 if (embedder_delegate_) { |
| 544 clear_embedder_data_.Start(); | 518 clear_embedder_data_.Start(); |
| 545 embedder_delegate_->RemoveEmbedderData( | 519 embedder_delegate_->RemoveEmbedderData( |
| 546 delete_begin_, | 520 delete_begin_, delete_end_, remove_mask, filter_builder, |
| 547 delete_end_, | 521 origin_type_mask, clear_embedder_data_.GetCompletionCallback()); |
| 548 remove_mask, | |
| 549 filter_builder, | |
| 550 origin_type_mask, | |
| 551 clear_embedder_data_.GetCompletionCallback()); | |
| 552 } | 522 } |
| 553 | 523 |
| 554 // Notify in case all actions taken were synchronous. | 524 // Notify in case all actions taken were synchronous. |
| 555 synchronous_clear_operations_.GetCompletionCallback().Run(); | 525 synchronous_clear_operations_.GetCompletionCallback().Run(); |
| 556 } | 526 } |
| 557 | 527 |
| 558 void BrowsingDataRemoverImpl::AddObserver(Observer* observer) { | 528 void BrowsingDataRemoverImpl::AddObserver(Observer* observer) { |
| 559 observer_list_.AddObserver(observer); | 529 observer_list_.AddObserver(observer); |
| 560 } | 530 } |
| 561 | 531 |
| 562 void BrowsingDataRemoverImpl::RemoveObserver(Observer* observer) { | 532 void BrowsingDataRemoverImpl::RemoveObserver(Observer* observer) { |
| 563 observer_list_.RemoveObserver(observer); | 533 observer_list_.RemoveObserver(observer); |
| 564 } | 534 } |
| 565 | 535 |
| 566 void BrowsingDataRemoverImpl::SetWouldCompleteCallbackForTesting( | 536 void BrowsingDataRemoverImpl::SetWouldCompleteCallbackForTesting( |
| 567 const base::Callback<void(const base::Closure& continue_to_completion)>& | 537 const base::Callback<void(const base::Closure& continue_to_completion)>& |
| 568 callback) { | 538 callback) { |
| 569 would_complete_callback_ = callback; | 539 would_complete_callback_ = callback; |
| 570 } | 540 } |
| 571 | 541 |
| 572 void BrowsingDataRemoverImpl::OverrideStoragePartitionForTesting( | 542 void BrowsingDataRemoverImpl::OverrideStoragePartitionForTesting( |
| 573 content::StoragePartition* storage_partition) { | 543 StoragePartition* storage_partition) { |
| 574 storage_partition_for_testing_ = storage_partition; | 544 storage_partition_for_testing_ = storage_partition; |
| 575 } | 545 } |
| 576 | 546 |
| 577 const base::Time& BrowsingDataRemoverImpl::GetLastUsedBeginTime() { | 547 const base::Time& BrowsingDataRemoverImpl::GetLastUsedBeginTime() { |
| 578 return delete_begin_; | 548 return delete_begin_; |
| 579 } | 549 } |
| 580 | 550 |
| 581 const base::Time& BrowsingDataRemoverImpl::GetLastUsedEndTime() { | 551 const base::Time& BrowsingDataRemoverImpl::GetLastUsedEndTime() { |
| 582 return delete_end_; | 552 return delete_end_; |
| 583 } | 553 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 601 delete_end(delete_end), | 571 delete_end(delete_end), |
| 602 remove_mask(remove_mask), | 572 remove_mask(remove_mask), |
| 603 origin_type_mask(origin_type_mask), | 573 origin_type_mask(origin_type_mask), |
| 604 filter_builder(std::move(filter_builder)), | 574 filter_builder(std::move(filter_builder)), |
| 605 observer(observer) {} | 575 observer(observer) {} |
| 606 | 576 |
| 607 BrowsingDataRemoverImpl::RemovalTask::~RemovalTask() {} | 577 BrowsingDataRemoverImpl::RemovalTask::~RemovalTask() {} |
| 608 | 578 |
| 609 bool BrowsingDataRemoverImpl::AllDone() { | 579 bool BrowsingDataRemoverImpl::AllDone() { |
| 610 return !synchronous_clear_operations_.is_pending() && | 580 return !synchronous_clear_operations_.is_pending() && |
| 611 !clear_embedder_data_.is_pending() && | 581 !clear_embedder_data_.is_pending() && !clear_cache_.is_pending() && |
| 612 !clear_cache_.is_pending() && | |
| 613 !clear_channel_ids_.is_pending() && | 582 !clear_channel_ids_.is_pending() && |
| 614 !clear_http_auth_cache_.is_pending() && | 583 !clear_http_auth_cache_.is_pending() && |
| 615 !clear_storage_partition_data_.is_pending(); | 584 !clear_storage_partition_data_.is_pending(); |
| 616 } | 585 } |
| 617 | 586 |
| 618 void BrowsingDataRemoverImpl::Notify() { | 587 void BrowsingDataRemoverImpl::Notify() { |
| 619 // Some tests call |RemoveImpl| directly, without using the task scheduler. | 588 // 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 | 589 // 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 | 590 // relying on |RemoveImpl| do so because they need to pass in |
| 622 // BrowsingDataFilterBuilder while still keeping ownership of it. Making | 591 // 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); | 641 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 673 base::WeakPtr<BrowsingDataRemoverImpl> weak_ptr = | 642 base::WeakPtr<BrowsingDataRemoverImpl> weak_ptr = |
| 674 weak_ptr_factory_.GetWeakPtr(); | 643 weak_ptr_factory_.GetWeakPtr(); |
| 675 | 644 |
| 676 // Immediately bind the weak pointer to the UI thread. This makes it easier | 645 // Immediately bind the weak pointer to the UI thread. This makes it easier |
| 677 // to discover potential misuse on the IO thread. | 646 // to discover potential misuse on the IO thread. |
| 678 weak_ptr.get(); | 647 weak_ptr.get(); |
| 679 | 648 |
| 680 return weak_ptr; | 649 return weak_ptr; |
| 681 } | 650 } |
| 651 |
| 652 } // namespace content |
| OLD | NEW |