Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/browser/browsing_data_remover.cc

Issue 9419033: Move creation of BrowserContext objects that live in content to content, instead of depending on th… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fix memory leaks in tests Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "net/base/origin_bound_cert_service.h" 51 #include "net/base/origin_bound_cert_service.h"
52 #include "net/base/origin_bound_cert_store.h" 52 #include "net/base/origin_bound_cert_store.h"
53 #include "net/base/transport_security_state.h" 53 #include "net/base/transport_security_state.h"
54 #include "net/disk_cache/disk_cache.h" 54 #include "net/disk_cache/disk_cache.h"
55 #include "net/http/http_cache.h" 55 #include "net/http/http_cache.h"
56 #include "net/url_request/url_request_context.h" 56 #include "net/url_request/url_request_context.h"
57 #include "net/url_request/url_request_context_getter.h" 57 #include "net/url_request/url_request_context_getter.h"
58 #include "webkit/quota/quota_manager.h" 58 #include "webkit/quota/quota_manager.h"
59 #include "webkit/quota/quota_types.h" 59 #include "webkit/quota/quota_types.h"
60 60
61 using content::BrowserContext;
61 using content::BrowserThread; 62 using content::BrowserThread;
62 using content::DownloadManager; 63 using content::DownloadManager;
63 using content::UserMetricsAction; 64 using content::UserMetricsAction;
64 65
65 bool BrowsingDataRemover::removing_ = false; 66 bool BrowsingDataRemover::removing_ = false;
66 67
67 BrowsingDataRemover::NotificationDetails::NotificationDetails() 68 BrowsingDataRemover::NotificationDetails::NotificationDetails()
68 : removal_begin(base::Time()), 69 : removal_begin(base::Time()),
69 removal_mask(-1) { 70 removal_mask(-1) {
70 } 71 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 base::Bind(&BrowsingDataRemover::ClearOriginBoundCertsOnIOThread, 277 base::Bind(&BrowsingDataRemover::ClearOriginBoundCertsOnIOThread,
277 base::Unretained(this), base::Unretained(rq_context))); 278 base::Unretained(this), base::Unretained(rq_context)));
278 } 279 }
279 } 280 }
280 281
281 if (remove_mask & REMOVE_LOCAL_STORAGE) { 282 if (remove_mask & REMOVE_LOCAL_STORAGE) {
282 // Remove data such as local databases, STS state, etc. These only can 283 // Remove data such as local databases, STS state, etc. These only can
283 // be removed if a WEBKIT thread exists, so check that first: 284 // be removed if a WEBKIT thread exists, so check that first:
284 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { 285 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) {
285 // We assume the end time is now. 286 // We assume the end time is now.
286 profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_); 287 BrowserContext::GetWebKitContext(profile_)->
288 DeleteDataModifiedSince(delete_begin_);
287 } 289 }
288 } 290 }
289 291
290 if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL || 292 if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL ||
291 remove_mask & REMOVE_APPCACHE || remove_mask & REMOVE_FILE_SYSTEMS) { 293 remove_mask & REMOVE_APPCACHE || remove_mask & REMOVE_FILE_SYSTEMS) {
292 quota_manager_ = profile_->GetQuotaManager(); 294 if (!quota_manager_)
293 if (quota_manager_) { 295 quota_manager_ = content::BrowserContext::GetQuotaManager(profile_);
294 waiting_for_clear_quota_managed_data_ = true; 296 waiting_for_clear_quota_managed_data_ = true;
295 BrowserThread::PostTask( 297 BrowserThread::PostTask(
296 BrowserThread::IO, FROM_HERE, 298 BrowserThread::IO, FROM_HERE,
297 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread, 299 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread,
298 base::Unretained(this))); 300 base::Unretained(this)));
299 }
300 } 301 }
301 302
302 if (remove_mask & REMOVE_PLUGIN_DATA) { 303 if (remove_mask & REMOVE_PLUGIN_DATA) {
303 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); 304 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
304 305
305 waiting_for_clear_plugin_data_ = true; 306 waiting_for_clear_plugin_data_ = true;
306 if (!plugin_data_remover_.get()) { 307 if (!plugin_data_remover_.get()) {
307 plugin_data_remover_.reset( 308 plugin_data_remover_.reset(
308 content::PluginDataRemover::Create(profile_->GetResourceContext())); 309 content::PluginDataRemover::Create(profile_->GetResourceContext()));
309 } 310 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 376
376 void BrowsingDataRemover::RemoveObserver(Observer* observer) { 377 void BrowsingDataRemover::RemoveObserver(Observer* observer) {
377 observer_list_.RemoveObserver(observer); 378 observer_list_.RemoveObserver(observer);
378 } 379 }
379 380
380 void BrowsingDataRemover::OnHistoryDeletionDone() { 381 void BrowsingDataRemover::OnHistoryDeletionDone() {
381 waiting_for_clear_history_ = false; 382 waiting_for_clear_history_ = false;
382 NotifyAndDeleteIfDone(); 383 NotifyAndDeleteIfDone();
383 } 384 }
384 385
386 void BrowsingDataRemover::OverrideQuotaManagerForTesting(
387 quota::QuotaManager* quota_manager) {
388 quota_manager_ = quota_manager;
389 }
390
385 base::Time BrowsingDataRemover::CalculateBeginDeleteTime( 391 base::Time BrowsingDataRemover::CalculateBeginDeleteTime(
386 TimePeriod time_period) { 392 TimePeriod time_period) {
387 base::TimeDelta diff; 393 base::TimeDelta diff;
388 base::Time delete_begin_time = base::Time::Now(); 394 base::Time delete_begin_time = base::Time::Now();
389 switch (time_period) { 395 switch (time_period) {
390 case LAST_HOUR: 396 case LAST_HOUR:
391 diff = base::TimeDelta::FromHours(1); 397 diff = base::TimeDelta::FromHours(1);
392 break; 398 break;
393 case LAST_DAY: 399 case LAST_DAY:
394 diff = base::TimeDelta::FromHours(24); 400 diff = base::TimeDelta::FromHours(24);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // the user-specified timeframe, and deal with the resulting set in 565 // the user-specified timeframe, and deal with the resulting set in
560 // OnGotQuotaManagedOrigins(). 566 // OnGotQuotaManagedOrigins().
561 quota_managed_origins_to_delete_count_ = 0; 567 quota_managed_origins_to_delete_count_ = 0;
562 quota_managed_storage_types_to_delete_count_ = 2; 568 quota_managed_storage_types_to_delete_count_ = 2;
563 569
564 if (delete_begin_ == base::Time()) { 570 if (delete_begin_ == base::Time()) {
565 // If we're deleting since the beginning of time, ask the QuotaManager for 571 // If we're deleting since the beginning of time, ask the QuotaManager for
566 // all origins with persistent quota modified within the user-specified 572 // all origins with persistent quota modified within the user-specified
567 // timeframe, and deal with the resulting set in 573 // timeframe, and deal with the resulting set in
568 // OnGotPersistentQuotaManagedOrigins. 574 // OnGotPersistentQuotaManagedOrigins.
569 profile_->GetQuotaManager()->GetOriginsModifiedSince( 575 quota_manager_->GetOriginsModifiedSince(
570 quota::kStorageTypePersistent, delete_begin_, 576 quota::kStorageTypePersistent, delete_begin_,
571 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, 577 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins,
572 base::Unretained(this))); 578 base::Unretained(this)));
573 } else { 579 } else {
574 // Otherwise, we don't need to deal with persistent storage. 580 // Otherwise, we don't need to deal with persistent storage.
575 --quota_managed_storage_types_to_delete_count_; 581 --quota_managed_storage_types_to_delete_count_;
576 } 582 }
577 583
578 // Do the same for temporary quota, regardless, passing the resulting set into 584 // Do the same for temporary quota, regardless, passing the resulting set into
579 // OnGotTemporaryQuotaManagedOrigins. 585 // OnGotTemporaryQuotaManagedOrigins.
580 profile_->GetQuotaManager()->GetOriginsModifiedSince( 586 quota_manager_->GetOriginsModifiedSince(
581 quota::kStorageTypeTemporary, delete_begin_, 587 quota::kStorageTypeTemporary, delete_begin_,
582 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, 588 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins,
583 base::Unretained(this))); 589 base::Unretained(this)));
584 } 590 }
585 591
586 void BrowsingDataRemover::OnGotQuotaManagedOrigins( 592 void BrowsingDataRemover::OnGotQuotaManagedOrigins(
587 const std::set<GURL>& origins, quota::StorageType type) { 593 const std::set<GURL>& origins, quota::StorageType type) {
588 DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0); 594 DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0);
589 // Walk through the origins passed in, delete quota of |type| from each that 595 // Walk through the origins passed in, delete quota of |type| from each that
590 // isn't protected. 596 // isn't protected.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 BrowserThread::UI, FROM_HERE, 684 BrowserThread::UI, FROM_HERE,
679 base::Bind(&BrowsingDataRemover::OnClearedOriginBoundCerts, 685 base::Bind(&BrowsingDataRemover::OnClearedOriginBoundCerts,
680 base::Unretained(this))); 686 base::Unretained(this)));
681 } 687 }
682 688
683 void BrowsingDataRemover::OnClearedOriginBoundCerts() { 689 void BrowsingDataRemover::OnClearedOriginBoundCerts() {
684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
685 waiting_for_clear_origin_bound_certs_ = false; 691 waiting_for_clear_origin_bound_certs_ = false;
686 NotifyAndDeleteIfDone(); 692 NotifyAndDeleteIfDone();
687 } 693 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_remover.h ('k') | chrome/browser/browsing_data_remover_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698