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

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: 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 base::Bind(&BrowsingDataRemover::ClearOriginBoundCertsOnIOThread, 256 base::Bind(&BrowsingDataRemover::ClearOriginBoundCertsOnIOThread,
256 base::Unretained(this), base::Unretained(rq_context))); 257 base::Unretained(this), base::Unretained(rq_context)));
257 } 258 }
258 } 259 }
259 260
260 if (remove_mask & REMOVE_LOCAL_STORAGE) { 261 if (remove_mask & REMOVE_LOCAL_STORAGE) {
261 // Remove data such as local databases, STS state, etc. These only can 262 // Remove data such as local databases, STS state, etc. These only can
262 // be removed if a WEBKIT thread exists, so check that first: 263 // be removed if a WEBKIT thread exists, so check that first:
263 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { 264 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) {
264 // We assume the end time is now. 265 // We assume the end time is now.
265 profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_); 266 BrowserContext::GetWebKitContext(profile_)->
267 DeleteDataModifiedSince(delete_begin_);
266 } 268 }
267 } 269 }
268 270
269 if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL || 271 if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL ||
270 remove_mask & REMOVE_APPCACHE || remove_mask & REMOVE_FILE_SYSTEMS) { 272 remove_mask & REMOVE_APPCACHE || remove_mask & REMOVE_FILE_SYSTEMS) {
271 // TODO(mkwst): At the moment, we don't have the ability to pass a mask into 273 // TODO(mkwst): At the moment, we don't have the ability to pass a mask into
272 // QuotaManager. Until then, we'll clear all quota-managed data types if any 274 // QuotaManager. Until then, we'll clear all quota-managed data types if any
273 // ought to be cleared. 275 // ought to be cleared.
274 quota_manager_ = profile_->GetQuotaManager(); 276 if (!quota_manager_)
275 if (quota_manager_) { 277 quota_manager_ = content::BrowserContext::GetQuotaManager(profile_);
276 waiting_for_clear_quota_managed_data_ = true; 278 waiting_for_clear_quota_managed_data_ = true;
277 BrowserThread::PostTask( 279 BrowserThread::PostTask(
278 BrowserThread::IO, FROM_HERE, 280 BrowserThread::IO, FROM_HERE,
279 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread, 281 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread,
280 base::Unretained(this))); 282 base::Unretained(this)));
281 }
282 } 283 }
283 284
284 if (remove_mask & REMOVE_PLUGIN_DATA) { 285 if (remove_mask & REMOVE_PLUGIN_DATA) {
285 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); 286 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
286 287
287 waiting_for_clear_plugin_data_ = true; 288 waiting_for_clear_plugin_data_ = true;
288 if (!plugin_data_remover_.get()) { 289 if (!plugin_data_remover_.get()) {
289 plugin_data_remover_.reset( 290 plugin_data_remover_.reset(
290 content::PluginDataRemover::Create(profile_->GetResourceContext())); 291 content::PluginDataRemover::Create(profile_->GetResourceContext()));
291 } 292 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 358
358 void BrowsingDataRemover::RemoveObserver(Observer* observer) { 359 void BrowsingDataRemover::RemoveObserver(Observer* observer) {
359 observer_list_.RemoveObserver(observer); 360 observer_list_.RemoveObserver(observer);
360 } 361 }
361 362
362 void BrowsingDataRemover::OnHistoryDeletionDone() { 363 void BrowsingDataRemover::OnHistoryDeletionDone() {
363 waiting_for_clear_history_ = false; 364 waiting_for_clear_history_ = false;
364 NotifyAndDeleteIfDone(); 365 NotifyAndDeleteIfDone();
365 } 366 }
366 367
368 void BrowsingDataRemover::OverrideQuotaManagerForTesting(
369 quota::QuotaManager* quota_manager) {
370 quota_manager_ = quota_manager;
371 }
372
367 base::Time BrowsingDataRemover::CalculateBeginDeleteTime( 373 base::Time BrowsingDataRemover::CalculateBeginDeleteTime(
368 TimePeriod time_period) { 374 TimePeriod time_period) {
369 base::TimeDelta diff; 375 base::TimeDelta diff;
370 base::Time delete_begin_time = base::Time::Now(); 376 base::Time delete_begin_time = base::Time::Now();
371 switch (time_period) { 377 switch (time_period) {
372 case LAST_HOUR: 378 case LAST_HOUR:
373 diff = base::TimeDelta::FromHours(1); 379 diff = base::TimeDelta::FromHours(1);
374 break; 380 break;
375 case LAST_DAY: 381 case LAST_DAY:
376 diff = base::TimeDelta::FromHours(24); 382 diff = base::TimeDelta::FromHours(24);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // the user-specified timeframe, and deal with the resulting set in 547 // the user-specified timeframe, and deal with the resulting set in
542 // OnGotQuotaManagedOrigins(). 548 // OnGotQuotaManagedOrigins().
543 quota_managed_origins_to_delete_count_ = 0; 549 quota_managed_origins_to_delete_count_ = 0;
544 quota_managed_storage_types_to_delete_count_ = 2; 550 quota_managed_storage_types_to_delete_count_ = 2;
545 551
546 if (delete_begin_ == base::Time()) { 552 if (delete_begin_ == base::Time()) {
547 // If we're deleting since the beginning of time, ask the QuotaManager for 553 // If we're deleting since the beginning of time, ask the QuotaManager for
548 // all origins with persistent quota modified within the user-specified 554 // all origins with persistent quota modified within the user-specified
549 // timeframe, and deal with the resulting set in 555 // timeframe, and deal with the resulting set in
550 // OnGotPersistentQuotaManagedOrigins. 556 // OnGotPersistentQuotaManagedOrigins.
551 profile_->GetQuotaManager()->GetOriginsModifiedSince( 557 quota_manager_->GetOriginsModifiedSince(
552 quota::kStorageTypePersistent, delete_begin_, 558 quota::kStorageTypePersistent, delete_begin_,
553 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, 559 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins,
554 base::Unretained(this))); 560 base::Unretained(this)));
555 } else { 561 } else {
556 // Otherwise, we don't need to deal with persistent storage. 562 // Otherwise, we don't need to deal with persistent storage.
557 --quota_managed_storage_types_to_delete_count_; 563 --quota_managed_storage_types_to_delete_count_;
558 } 564 }
559 565
560 // Do the same for temporary quota, regardless, passing the resulting set into 566 // Do the same for temporary quota, regardless, passing the resulting set into
561 // OnGotTemporaryQuotaManagedOrigins. 567 // OnGotTemporaryQuotaManagedOrigins.
562 profile_->GetQuotaManager()->GetOriginsModifiedSince( 568 quota_manager_->GetOriginsModifiedSince(
563 quota::kStorageTypeTemporary, delete_begin_, 569 quota::kStorageTypeTemporary, delete_begin_,
564 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, 570 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins,
565 base::Unretained(this))); 571 base::Unretained(this)));
566 } 572 }
567 573
568 void BrowsingDataRemover::OnGotQuotaManagedOrigins( 574 void BrowsingDataRemover::OnGotQuotaManagedOrigins(
569 const std::set<GURL>& origins, quota::StorageType type) { 575 const std::set<GURL>& origins, quota::StorageType type) {
570 DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0); 576 DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0);
571 // Walk through the origins passed in, delete quota of |type| from each that 577 // Walk through the origins passed in, delete quota of |type| from each that
572 // isn't protected. 578 // isn't protected.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 BrowserThread::UI, FROM_HERE, 664 BrowserThread::UI, FROM_HERE,
659 base::Bind(&BrowsingDataRemover::OnClearedOriginBoundCerts, 665 base::Bind(&BrowsingDataRemover::OnClearedOriginBoundCerts,
660 base::Unretained(this))); 666 base::Unretained(this)));
661 } 667 }
662 668
663 void BrowsingDataRemover::OnClearedOriginBoundCerts() { 669 void BrowsingDataRemover::OnClearedOriginBoundCerts() {
664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 670 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
665 waiting_for_clear_origin_bound_certs_ = false; 671 waiting_for_clear_origin_bound_certs_ = false;
666 NotifyAndDeleteIfDone(); 672 NotifyAndDeleteIfDone();
667 } 673 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698