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

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

Issue 8919017: Split UserMetrics into API vs. implementation. Move API to content/public. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Version for commit (merged again). Created 9 years 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) 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/bind.h"
(...skipping 25 matching lines...) Expand all
36 #include "chrome/browser/sessions/session_service.h" 36 #include "chrome/browser/sessions/session_service.h"
37 #include "chrome/browser/sessions/session_service_factory.h" 37 #include "chrome/browser/sessions/session_service_factory.h"
38 #include "chrome/browser/sessions/tab_restore_service.h" 38 #include "chrome/browser/sessions/tab_restore_service.h"
39 #include "chrome/browser/sessions/tab_restore_service_factory.h" 39 #include "chrome/browser/sessions/tab_restore_service_factory.h"
40 #include "chrome/browser/webdata/web_data_service.h" 40 #include "chrome/browser/webdata/web_data_service.h"
41 #include "chrome/common/chrome_notification_types.h" 41 #include "chrome/common/chrome_notification_types.h"
42 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
43 #include "chrome/common/url_constants.h" 43 #include "chrome/common/url_constants.h"
44 #include "content/browser/download/download_manager.h" 44 #include "content/browser/download/download_manager.h"
45 #include "content/browser/in_process_webkit/webkit_context.h" 45 #include "content/browser/in_process_webkit/webkit_context.h"
46 #include "content/browser/user_metrics.h"
47 #include "content/public/browser/browser_thread.h" 46 #include "content/public/browser/browser_thread.h"
48 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
49 #include "content/public/browser/plugin_data_remover.h" 48 #include "content/public/browser/plugin_data_remover.h"
49 #include "content/public/browser/user_metrics.h"
50 #include "net/base/cookie_monster.h" 50 #include "net/base/cookie_monster.h"
51 #include "net/base/net_errors.h" 51 #include "net/base/net_errors.h"
52 #include "net/base/transport_security_state.h" 52 #include "net/base/transport_security_state.h"
53 #include "net/disk_cache/disk_cache.h" 53 #include "net/disk_cache/disk_cache.h"
54 #include "net/http/http_cache.h" 54 #include "net/http/http_cache.h"
55 #include "net/url_request/url_request_context.h" 55 #include "net/url_request/url_request_context.h"
56 #include "net/url_request/url_request_context_getter.h" 56 #include "net/url_request/url_request_context_getter.h"
57 #include "webkit/quota/quota_manager.h" 57 #include "webkit/quota/quota_manager.h"
58 #include "webkit/quota/quota_types.h" 58 #include "webkit/quota/quota_types.h"
59 59
60 using content::BrowserThread; 60 using content::BrowserThread;
61 using content::UserMetricsAction;
61 62
62 // Done so that we can use PostTask on BrowsingDataRemovers and not have 63 // Done so that we can use PostTask on BrowsingDataRemovers and not have
63 // BrowsingDataRemover implement RefCounted. 64 // BrowsingDataRemover implement RefCounted.
64 DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowsingDataRemover); 65 DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowsingDataRemover);
65 66
66 bool BrowsingDataRemover::removing_ = false; 67 bool BrowsingDataRemover::removing_ = false;
67 68
68 BrowsingDataRemover::NotificationDetails::NotificationDetails() 69 BrowsingDataRemover::NotificationDetails::NotificationDetails()
69 : removal_begin(base::Time()), 70 : removal_begin(base::Time()),
70 removal_mask(-1) { 71 removal_mask(-1) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 void BrowsingDataRemover::Remove(int remove_mask) { 147 void BrowsingDataRemover::Remove(int remove_mask) {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
148 set_removing(true); 149 set_removing(true);
149 remove_mask_ = remove_mask; 150 remove_mask_ = remove_mask;
150 151
151 if (remove_mask & REMOVE_HISTORY) { 152 if (remove_mask & REMOVE_HISTORY) {
152 HistoryService* history_service = 153 HistoryService* history_service =
153 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 154 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
154 if (history_service) { 155 if (history_service) {
155 std::set<GURL> restrict_urls; 156 std::set<GURL> restrict_urls;
156 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); 157 content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
157 waiting_for_clear_history_ = true; 158 waiting_for_clear_history_ = true;
158 history_service->ExpireHistoryBetween(restrict_urls, 159 history_service->ExpireHistoryBetween(restrict_urls,
159 delete_begin_, delete_end_, 160 delete_begin_, delete_end_,
160 &request_consumer_, 161 &request_consumer_,
161 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, 162 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
162 base::Unretained(this))); 163 base::Unretained(this)));
163 } 164 }
164 165
165 // Need to clear the host cache and accumulated speculative data, as it also 166 // Need to clear the host cache and accumulated speculative data, as it also
166 // reveals some history. 167 // reveals some history.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 prerender::PrerenderManager* prerender_manager = 205 prerender::PrerenderManager* prerender_manager =
205 prerender::PrerenderManagerFactory::GetForProfile(profile_); 206 prerender::PrerenderManagerFactory::GetForProfile(profile_);
206 if (prerender_manager) { 207 if (prerender_manager) {
207 prerender_manager->ClearData( 208 prerender_manager->ClearData(
208 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | 209 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
209 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); 210 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
210 } 211 }
211 } 212 }
212 213
213 if (remove_mask & REMOVE_DOWNLOADS) { 214 if (remove_mask & REMOVE_DOWNLOADS) {
214 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); 215 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
215 DownloadManager* download_manager = 216 DownloadManager* download_manager =
216 DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager(); 217 DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager();
217 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); 218 download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_);
218 download_manager->ClearLastDownloadPath(); 219 download_manager->ClearLastDownloadPath();
219 } 220 }
220 221
221 if (remove_mask & REMOVE_COOKIES) { 222 if (remove_mask & REMOVE_COOKIES) {
222 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); 223 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
223 // Since we are running on the UI thread don't call GetURLRequestContext(). 224 // Since we are running on the UI thread don't call GetURLRequestContext().
224 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext(); 225 net::URLRequestContextGetter* rq_context = profile_->GetRequestContext();
225 if (rq_context) { 226 if (rq_context) {
226 waiting_for_clear_cookies_ = true; 227 waiting_for_clear_cookies_ = true;
227 BrowserThread::PostTask( 228 BrowserThread::PostTask(
228 BrowserThread::IO, FROM_HERE, 229 BrowserThread::IO, FROM_HERE,
229 base::Bind(&BrowsingDataRemover::ClearCookiesOnIOThread, 230 base::Bind(&BrowsingDataRemover::ClearCookiesOnIOThread,
230 base::Unretained(this), base::Unretained(rq_context))); 231 base::Unretained(this), base::Unretained(rq_context)));
231 } 232 }
232 } 233 }
(...skipping 16 matching lines...) Expand all
249 if (quota_manager_) { 250 if (quota_manager_) {
250 waiting_for_clear_quota_managed_data_ = true; 251 waiting_for_clear_quota_managed_data_ = true;
251 BrowserThread::PostTask( 252 BrowserThread::PostTask(
252 BrowserThread::IO, FROM_HERE, 253 BrowserThread::IO, FROM_HERE,
253 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread, 254 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread,
254 base::Unretained(this))); 255 base::Unretained(this)));
255 } 256 }
256 } 257 }
257 258
258 if (remove_mask & REMOVE_PLUGIN_DATA) { 259 if (remove_mask & REMOVE_PLUGIN_DATA) {
259 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); 260 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
260 261
261 waiting_for_clear_plugin_data_ = true; 262 waiting_for_clear_plugin_data_ = true;
262 if (!plugin_data_remover_.get()) { 263 if (!plugin_data_remover_.get()) {
263 plugin_data_remover_.reset( 264 plugin_data_remover_.reset(
264 content::PluginDataRemover::Create(profile_->GetResourceContext())); 265 content::PluginDataRemover::Create(profile_->GetResourceContext()));
265 } 266 }
266 base::WaitableEvent* event = 267 base::WaitableEvent* event =
267 plugin_data_remover_->StartRemoving(delete_begin_); 268 plugin_data_remover_->StartRemoving(delete_begin_);
268 watcher_.StartWatching(event, this); 269 watcher_.StartWatching(event, this);
269 } 270 }
270 271
271 if (remove_mask & REMOVE_PASSWORDS) { 272 if (remove_mask & REMOVE_PASSWORDS) {
272 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords")); 273 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
273 PasswordStore* password_store = 274 PasswordStore* password_store =
274 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); 275 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS);
275 276
276 if (password_store) 277 if (password_store)
277 password_store->RemoveLoginsCreatedBetween(delete_begin_, delete_end_); 278 password_store->RemoveLoginsCreatedBetween(delete_begin_, delete_end_);
278 } 279 }
279 280
280 if (remove_mask & REMOVE_FORM_DATA) { 281 if (remove_mask & REMOVE_FORM_DATA) {
281 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill")); 282 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
282 WebDataService* web_data_service = 283 WebDataService* web_data_service =
283 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 284 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
284 285
285 if (web_data_service) { 286 if (web_data_service) {
286 web_data_service->RemoveFormElementsAddedBetween(delete_begin_, 287 web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
287 delete_end_); 288 delete_end_);
288 web_data_service->RemoveAutofillProfilesAndCreditCardsModifiedBetween( 289 web_data_service->RemoveAutofillProfilesAndCreditCardsModifiedBetween(
289 delete_begin_, delete_end_); 290 delete_begin_, delete_end_);
290 PersonalDataManager* data_manager = 291 PersonalDataManager* data_manager =
291 PersonalDataManagerFactory::GetForProfile(profile_); 292 PersonalDataManagerFactory::GetForProfile(profile_);
292 if (data_manager) { 293 if (data_manager) {
293 data_manager->Refresh(); 294 data_manager->Refresh();
294 } 295 }
295 } 296 }
296 } 297 }
297 298
298 if (remove_mask & REMOVE_CACHE) { 299 if (remove_mask & REMOVE_CACHE) {
299 // Tell the renderers to clear their cache. 300 // Tell the renderers to clear their cache.
300 WebCacheManager::GetInstance()->ClearCache(); 301 WebCacheManager::GetInstance()->ClearCache();
301 302
302 // Invoke DoClearCache on the IO thread. 303 // Invoke DoClearCache on the IO thread.
303 waiting_for_clear_cache_ = true; 304 waiting_for_clear_cache_ = true;
304 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); 305 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache"));
305 306
306 BrowserThread::PostTask( 307 BrowserThread::PostTask(
307 BrowserThread::IO, FROM_HERE, 308 BrowserThread::IO, FROM_HERE,
308 base::Bind(&BrowsingDataRemover::ClearCacheOnIOThread, 309 base::Bind(&BrowsingDataRemover::ClearCacheOnIOThread,
309 base::Unretained(this))); 310 base::Unretained(this)));
310 311
311 // The PrerenderManager may have a page actively being prerendered, which 312 // The PrerenderManager may have a page actively being prerendered, which
312 // is essentially a preemptively cached page. 313 // is essentially a preemptively cached page.
313 prerender::PrerenderManager* prerender_manager = 314 prerender::PrerenderManager* prerender_manager =
314 prerender::PrerenderManagerFactory::GetForProfile(profile_); 315 prerender::PrerenderManagerFactory::GetForProfile(profile_);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 GetURLRequestContext()->cookie_store()->GetCookieMonster(); 618 GetURLRequestContext()->cookie_store()->GetCookieMonster();
618 if (cookie_monster) { 619 if (cookie_monster) {
619 cookie_monster->DeleteAllCreatedBetweenAsync( 620 cookie_monster->DeleteAllCreatedBetweenAsync(
620 delete_begin_, delete_end_, 621 delete_begin_, delete_end_,
621 base::Bind(&BrowsingDataRemover::OnClearedCookies, 622 base::Bind(&BrowsingDataRemover::OnClearedCookies,
622 base::Unretained(this))); 623 base::Unretained(this)));
623 } else { 624 } else {
624 OnClearedCookies(0); 625 OnClearedCookies(0);
625 } 626 }
626 } 627 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_context_menu_controller.cc ('k') | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698