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

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

Issue 8907015: Adding chrome::NOTIFICATION_BROWSING_DATA_REMOVED. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Jochen's comments. 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 27 matching lines...) Expand all
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" 46 #include "content/browser/user_metrics.h"
47 #include "content/public/browser/browser_thread.h" 47 #include "content/public/browser/browser_thread.h"
48 #include "content/public/browser/notification_source.h" 48 #include "content/public/browser/notification_service.h"
49 #include "content/public/browser/plugin_data_remover.h" 49 #include "content/public/browser/plugin_data_remover.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 61
62 // Done so that we can use PostTask on BrowsingDataRemovers and not have 62 // Done so that we can use PostTask on BrowsingDataRemovers and not have
63 // BrowsingDataRemover implement RefCounted. 63 // BrowsingDataRemover implement RefCounted.
64 DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowsingDataRemover); 64 DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowsingDataRemover);
65 65
66 bool BrowsingDataRemover::removing_ = false; 66 bool BrowsingDataRemover::removing_ = false;
67 67
68 BrowsingDataRemover::NotificationDetails::NotificationDetails()
69 : removal_begin(base::Time()),
70 removal_mask(-1) {
71 }
72
73 BrowsingDataRemover::NotificationDetails::NotificationDetails(
74 const BrowsingDataRemover::NotificationDetails& details)
75 : removal_begin(details.removal_begin),
76 removal_mask(details.removal_mask) {
77 }
78
79 BrowsingDataRemover::NotificationDetails::NotificationDetails(
80 base::Time removal_begin,
81 int removal_mask)
82 : removal_begin(removal_begin),
83 removal_mask(removal_mask) {
84 }
85
86 BrowsingDataRemover::NotificationDetails::~NotificationDetails() {}
87
68 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, 88 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
69 base::Time delete_begin, 89 base::Time delete_begin,
70 base::Time delete_end) 90 base::Time delete_end)
71 : profile_(profile), 91 : profile_(profile),
72 quota_manager_(NULL), 92 quota_manager_(NULL),
73 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), 93 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()),
74 delete_begin_(delete_begin), 94 delete_begin_(delete_begin),
75 delete_end_(delete_end), 95 delete_end_(delete_end),
76 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( 96 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_(
77 this, &BrowsingDataRemover::DoClearCache)), 97 this, &BrowsingDataRemover::DoClearCache)),
78 next_cache_state_(STATE_NONE), 98 next_cache_state_(STATE_NONE),
79 cache_(NULL), 99 cache_(NULL),
80 main_context_getter_(profile->GetRequestContext()), 100 main_context_getter_(profile->GetRequestContext()),
81 media_context_getter_(profile->GetRequestContextForMedia()), 101 media_context_getter_(profile->GetRequestContextForMedia()),
82 waiting_for_clear_history_(false), 102 waiting_for_clear_history_(false),
83 waiting_for_clear_quota_managed_data_(false), 103 waiting_for_clear_quota_managed_data_(false),
84 waiting_for_clear_networking_history_(false), 104 waiting_for_clear_networking_history_(false),
85 waiting_for_clear_cookies_(false), 105 waiting_for_clear_cookies_(false),
86 waiting_for_clear_cache_(false), 106 waiting_for_clear_cache_(false),
87 waiting_for_clear_lso_data_(false) { 107 waiting_for_clear_lso_data_(false),
108 remove_mask_(0) {
88 DCHECK(profile); 109 DCHECK(profile);
89 } 110 }
90 111
91 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, 112 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
92 TimePeriod time_period, 113 TimePeriod time_period,
93 base::Time delete_end) 114 base::Time delete_end)
94 : profile_(profile), 115 : profile_(profile),
95 quota_manager_(NULL), 116 quota_manager_(NULL),
96 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), 117 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()),
97 delete_begin_(CalculateBeginDeleteTime(time_period)), 118 delete_begin_(CalculateBeginDeleteTime(time_period)),
98 delete_end_(delete_end), 119 delete_end_(delete_end),
99 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( 120 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_(
100 this, &BrowsingDataRemover::DoClearCache)), 121 this, &BrowsingDataRemover::DoClearCache)),
101 next_cache_state_(STATE_NONE), 122 next_cache_state_(STATE_NONE),
102 cache_(NULL), 123 cache_(NULL),
103 main_context_getter_(profile->GetRequestContext()), 124 main_context_getter_(profile->GetRequestContext()),
104 media_context_getter_(profile->GetRequestContextForMedia()), 125 media_context_getter_(profile->GetRequestContextForMedia()),
105 waiting_for_clear_history_(false), 126 waiting_for_clear_history_(false),
106 waiting_for_clear_quota_managed_data_(false), 127 waiting_for_clear_quota_managed_data_(false),
107 waiting_for_clear_networking_history_(false), 128 waiting_for_clear_networking_history_(false),
108 waiting_for_clear_cookies_(false), 129 waiting_for_clear_cookies_(false),
109 waiting_for_clear_cache_(false), 130 waiting_for_clear_cache_(false),
110 waiting_for_clear_lso_data_(false) { 131 waiting_for_clear_lso_data_(false),
132 remove_mask_(0) {
111 DCHECK(profile); 133 DCHECK(profile);
112 } 134 }
113 135
114 BrowsingDataRemover::~BrowsingDataRemover() { 136 BrowsingDataRemover::~BrowsingDataRemover() {
115 DCHECK(all_done()); 137 DCHECK(all_done());
116 } 138 }
117 139
118 // Static. 140 // Static.
119 void BrowsingDataRemover::set_removing(bool removing) { 141 void BrowsingDataRemover::set_removing(bool removing) {
120 DCHECK(removing_ != removing); 142 DCHECK(removing_ != removing);
121 removing_ = removing; 143 removing_ = removing;
122 } 144 }
123 145
124 void BrowsingDataRemover::Remove(int remove_mask) { 146 void BrowsingDataRemover::Remove(int remove_mask) {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
126 set_removing(true); 148 set_removing(true);
149 remove_mask_ = remove_mask;
127 150
128 if (remove_mask & REMOVE_HISTORY) { 151 if (remove_mask & REMOVE_HISTORY) {
129 HistoryService* history_service = 152 HistoryService* history_service =
130 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 153 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
131 if (history_service) { 154 if (history_service) {
132 std::set<GURL> restrict_urls; 155 std::set<GURL> restrict_urls;
133 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); 156 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
134 waiting_for_clear_history_ = true; 157 waiting_for_clear_history_ = true;
135 history_service->ExpireHistoryBetween(restrict_urls, 158 history_service->ExpireHistoryBetween(restrict_urls,
136 delete_begin_, delete_end_, 159 delete_begin_, delete_end_,
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 366 }
344 367
345 void BrowsingDataRemover::Observe(int type, 368 void BrowsingDataRemover::Observe(int type,
346 const content::NotificationSource& source, 369 const content::NotificationSource& source,
347 const content::NotificationDetails& details) { 370 const content::NotificationDetails& details) {
348 // TODO(brettw) bug 1139736: This should also observe session 371 // TODO(brettw) bug 1139736: This should also observe session
349 // clearing (what about other things such as passwords, etc.?) and wait for 372 // clearing (what about other things such as passwords, etc.?) and wait for
350 // them to complete before continuing. 373 // them to complete before continuing.
351 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); 374 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED);
352 TemplateURLService* model = content::Source<TemplateURLService>(source).ptr(); 375 TemplateURLService* model = content::Source<TemplateURLService>(source).ptr();
353 if (model->profile() == profile_->GetOriginalProfile()) { 376 if (model->profile() == profile_) {
354 registrar_.RemoveAll(); 377 registrar_.RemoveAll();
355 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); 378 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_);
356 NotifyAndDeleteIfDone(); 379 NotifyAndDeleteIfDone();
357 } 380 }
358 } 381 }
359 382
360 void BrowsingDataRemover::NotifyAndDeleteIfDone() { 383 void BrowsingDataRemover::NotifyAndDeleteIfDone() {
361 // TODO(brettw) bug 1139736: see TODO in Observe() above. 384 // TODO(brettw) bug 1139736: see TODO in Observe() above.
362 if (!all_done()) 385 if (!all_done())
363 return; 386 return;
364 387
365 // The NetLog contains download history, but may also contain form data, 388 // The NetLog contains download history, but may also contain form data,
366 // cookies and passwords. Simplest just to always clear it. Must be cleared 389 // cookies and passwords. Simplest just to always clear it. Must be cleared
367 // after the cache, as cleaning up the disk cache exposes some of the history 390 // after the cache, as cleaning up the disk cache exposes some of the history
368 // in the NetLog. 391 // in the NetLog.
369 if (g_browser_process->net_log()) 392 if (g_browser_process->net_log())
370 g_browser_process->net_log()->ClearAllPassivelyCapturedEvents(); 393 g_browser_process->net_log()->ClearAllPassivelyCapturedEvents();
371 394
372 set_removing(false); 395 set_removing(false);
396
397 // Send global notification, then notify any explicit observers.
398 BrowsingDataRemover::NotificationDetails details(delete_begin_, remove_mask_);
399 content::NotificationService::current()->Notify(
400 chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
401 content::Source<Profile>(profile_),
402 content::Details<BrowsingDataRemover::NotificationDetails>(&details));
403
373 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); 404 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone());
374 405
375 // History requests aren't happy if you delete yourself from the callback. 406 // History requests aren't happy if you delete yourself from the callback.
376 // As such, we do a delete later. 407 // As such, we do a delete later.
377 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 408 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
378 } 409 }
379 410
380 void BrowsingDataRemover::ClearedNetworkHistory() { 411 void BrowsingDataRemover::ClearedNetworkHistory() {
381 waiting_for_clear_networking_history_ = false; 412 waiting_for_clear_networking_history_ = false;
382 413
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 GetURLRequestContext()->cookie_store()->GetCookieMonster(); 617 GetURLRequestContext()->cookie_store()->GetCookieMonster();
587 if (cookie_monster) { 618 if (cookie_monster) {
588 cookie_monster->DeleteAllCreatedBetweenAsync( 619 cookie_monster->DeleteAllCreatedBetweenAsync(
589 delete_begin_, delete_end_, 620 delete_begin_, delete_end_,
590 base::Bind(&BrowsingDataRemover::OnClearedCookies, 621 base::Bind(&BrowsingDataRemover::OnClearedCookies,
591 base::Unretained(this))); 622 base::Unretained(this)));
592 } else { 623 } else {
593 OnClearedCookies(0); 624 OnClearedCookies(0);
594 } 625 }
595 } 626 }
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