OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 11 #include "base/callback.h" |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
13 #include "chrome/browser/autofill/personal_data_manager.h" | 14 #include "chrome/browser/autofill/personal_data_manager.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/download/download_manager.h" | 16 #include "chrome/browser/download/download_manager.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 18 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
18 #include "chrome/browser/history/history.h" | 19 #include "chrome/browser/history/history.h" |
19 #include "chrome/browser/io_thread.h" | 20 #include "chrome/browser/io_thread.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( | 73 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( |
73 this, &BrowsingDataRemover::OnAppCacheDeleted)), | 74 this, &BrowsingDataRemover::OnAppCacheDeleted)), |
74 appcaches_to_be_deleted_count_(0), | 75 appcaches_to_be_deleted_count_(0), |
75 next_cache_state_(STATE_NONE), | 76 next_cache_state_(STATE_NONE), |
76 cache_(NULL), | 77 cache_(NULL), |
77 main_context_getter_(profile->GetRequestContext()), | 78 main_context_getter_(profile->GetRequestContext()), |
78 media_context_getter_(profile->GetRequestContextForMedia()), | 79 media_context_getter_(profile->GetRequestContextForMedia()), |
79 waiting_for_clear_databases_(false), | 80 waiting_for_clear_databases_(false), |
80 waiting_for_clear_history_(false), | 81 waiting_for_clear_history_(false), |
81 waiting_for_clear_networking_history_(false), | 82 waiting_for_clear_networking_history_(false), |
83 waiting_for_clear_cookies_(false), | |
82 waiting_for_clear_cache_(false), | 84 waiting_for_clear_cache_(false), |
83 waiting_for_clear_appcache_(false), | 85 waiting_for_clear_appcache_(false), |
84 waiting_for_clear_gears_data_(false), | 86 waiting_for_clear_gears_data_(false), |
85 waiting_for_clear_file_systems_(false) { | 87 waiting_for_clear_file_systems_(false) { |
86 DCHECK(profile); | 88 DCHECK(profile); |
87 } | 89 } |
88 | 90 |
89 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | 91 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
90 TimePeriod time_period, | 92 TimePeriod time_period, |
91 base::Time delete_end) | 93 base::Time delete_end) |
(...skipping 10 matching lines...) Expand all Loading... | |
102 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( | 104 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_deleted_callback_( |
103 this, &BrowsingDataRemover::OnAppCacheDeleted)), | 105 this, &BrowsingDataRemover::OnAppCacheDeleted)), |
104 appcaches_to_be_deleted_count_(0), | 106 appcaches_to_be_deleted_count_(0), |
105 next_cache_state_(STATE_NONE), | 107 next_cache_state_(STATE_NONE), |
106 cache_(NULL), | 108 cache_(NULL), |
107 main_context_getter_(profile->GetRequestContext()), | 109 main_context_getter_(profile->GetRequestContext()), |
108 media_context_getter_(profile->GetRequestContextForMedia()), | 110 media_context_getter_(profile->GetRequestContextForMedia()), |
109 waiting_for_clear_databases_(false), | 111 waiting_for_clear_databases_(false), |
110 waiting_for_clear_history_(false), | 112 waiting_for_clear_history_(false), |
111 waiting_for_clear_networking_history_(false), | 113 waiting_for_clear_networking_history_(false), |
114 waiting_for_clear_cookies_(false), | |
112 waiting_for_clear_cache_(false), | 115 waiting_for_clear_cache_(false), |
113 waiting_for_clear_appcache_(false), | 116 waiting_for_clear_appcache_(false), |
114 waiting_for_clear_lso_data_(false), | 117 waiting_for_clear_lso_data_(false), |
115 waiting_for_clear_gears_data_(false), | 118 waiting_for_clear_gears_data_(false), |
116 waiting_for_clear_file_systems_(false) { | 119 waiting_for_clear_file_systems_(false) { |
117 DCHECK(profile); | 120 DCHECK(profile); |
118 } | 121 } |
119 | 122 |
120 BrowsingDataRemover::~BrowsingDataRemover() { | 123 BrowsingDataRemover::~BrowsingDataRemover() { |
121 DCHECK(all_done()); | 124 DCHECK(all_done()); |
122 } | 125 } |
123 | 126 |
124 void BrowsingDataRemover::Remove(int remove_mask) { | 127 void BrowsingDataRemover::Remove(int remove_mask) { |
125 DCHECK(!removing_); | 128 DCHECK(!removing_); |
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
126 removing_ = true; | 130 removing_ = true; |
127 | 131 |
128 if (remove_mask & REMOVE_HISTORY) { | 132 if (remove_mask & REMOVE_HISTORY) { |
129 HistoryService* history_service = | 133 HistoryService* history_service = |
130 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 134 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
131 if (history_service) { | 135 if (history_service) { |
132 std::set<GURL> restrict_urls; | 136 std::set<GURL> restrict_urls; |
133 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); | 137 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
134 waiting_for_clear_history_ = true; | 138 waiting_for_clear_history_ = true; |
135 history_service->ExpireHistoryBetween(restrict_urls, | 139 history_service->ExpireHistoryBetween(restrict_urls, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); | 198 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); |
195 download_manager->ClearLastDownloadPath(); | 199 download_manager->ClearLastDownloadPath(); |
196 } | 200 } |
197 | 201 |
198 if (remove_mask & REMOVE_COOKIES) { | 202 if (remove_mask & REMOVE_COOKIES) { |
199 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); | 203 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); |
200 // Since we are running on the UI thread don't call GetURLRequestContext(). | 204 // Since we are running on the UI thread don't call GetURLRequestContext(). |
201 net::CookieMonster* cookie_monster = NULL; | 205 net::CookieMonster* cookie_monster = NULL; |
202 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext(); | 206 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext(); |
203 if (rq_context) { | 207 if (rq_context) { |
204 cookie_monster = rq_context->DONTUSEME_GetCookieStore()-> | 208 cookie_monster = rq_context->GetURLRequestContext()->cookie_store()-> |
205 GetCookieMonster(); | 209 GetCookieMonster(); |
206 } | 210 } |
207 if (cookie_monster) | 211 if (cookie_monster) { |
208 cookie_monster->DeleteAllCreatedBetween(delete_begin_, delete_end_, true); | 212 waiting_for_clear_cookies_ = true; |
213 cookie_monster->DeleteAllCreatedBetweenAsync( | |
214 delete_begin_, delete_end_, true, | |
215 base::Bind(&BrowsingDataRemover::OnCookiesDeleted, | |
216 base::Unretained(this))); | |
217 } | |
209 | 218 |
210 // REMOVE_COOKIES is actually "cookies and other site data" so we make sure | 219 // REMOVE_COOKIES is actually "cookies and other site data" so we make sure |
211 // to remove other data such local databases, STS state, etc. These only can | 220 // to remove other data such local databases, STS state, etc. These only can |
212 // be removed if a WEBKIT thread exists, so check that first: | 221 // be removed if a WEBKIT thread exists, so check that first: |
213 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT)) { | 222 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT)) { |
214 // We assume the end time is now. | 223 // We assume the end time is now. |
215 profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_); | 224 profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_); |
216 } | 225 } |
217 | 226 |
218 database_tracker_ = profile_->GetDatabaseTracker(); | 227 database_tracker_ = profile_->GetDatabaseTracker(); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 | 635 |
627 ClearGearsData(profile_dir); | 636 ClearGearsData(profile_dir); |
628 OnClearedGearsData(); | 637 OnClearedGearsData(); |
629 } | 638 } |
630 | 639 |
631 void BrowsingDataRemover::OnWaitableEventSignaled( | 640 void BrowsingDataRemover::OnWaitableEventSignaled( |
632 base::WaitableEvent* waitable_event) { | 641 base::WaitableEvent* waitable_event) { |
633 waiting_for_clear_lso_data_ = false; | 642 waiting_for_clear_lso_data_ = false; |
634 NotifyAndDeleteIfDone(); | 643 NotifyAndDeleteIfDone(); |
635 } | 644 } |
645 | |
646 void BrowsingDataRemover::OnCookiesDeleted(int num_deleted) { | |
647 waiting_for_clear_cookies_ = false; | |
648 MessageLoop::current()->PostTask( | |
ycxiao
2011/07/15 20:43:39
Post a Task here, because this callback make be in
erikwright (departed)
2011/07/17 17:21:56
Add a comment in the code to this effect.
On 2011
| |
649 FROM_HERE, | |
650 base::Bind(&BrowsingDataRemover::NotifyAndDeleteIfDone, | |
651 base::Unretained(this))); | |
652 } | |
OLD | NEW |