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

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: Struct. Rebase onto a slightly less red trunk. 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::NotificationDetail::NotificationDetail(
69 base::Time removal_begin,
70 int removal_mask)
71 : removal_begin(removal_begin),
72 removal_mask(removal_mask) {
73 }
74
75 BrowsingDataRemover::NotificationDetail::~NotificationDetail() {}
76
68 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, 77 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
69 base::Time delete_begin, 78 base::Time delete_begin,
70 base::Time delete_end) 79 base::Time delete_end)
71 : profile_(profile), 80 : profile_(profile),
72 quota_manager_(NULL), 81 quota_manager_(NULL),
73 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), 82 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()),
74 delete_begin_(delete_begin), 83 delete_begin_(delete_begin),
75 delete_end_(delete_end), 84 delete_end_(delete_end),
76 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( 85 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_(
77 this, &BrowsingDataRemover::DoClearCache)), 86 this, &BrowsingDataRemover::DoClearCache)),
78 next_cache_state_(STATE_NONE), 87 next_cache_state_(STATE_NONE),
79 cache_(NULL), 88 cache_(NULL),
80 main_context_getter_(profile->GetRequestContext()), 89 main_context_getter_(profile->GetRequestContext()),
81 media_context_getter_(profile->GetRequestContextForMedia()), 90 media_context_getter_(profile->GetRequestContextForMedia()),
82 waiting_for_clear_history_(false), 91 waiting_for_clear_history_(false),
83 waiting_for_clear_quota_managed_data_(false), 92 waiting_for_clear_quota_managed_data_(false),
84 waiting_for_clear_networking_history_(false), 93 waiting_for_clear_networking_history_(false),
85 waiting_for_clear_cookies_(false), 94 waiting_for_clear_cookies_(false),
86 waiting_for_clear_cache_(false), 95 waiting_for_clear_cache_(false),
87 waiting_for_clear_lso_data_(false) { 96 waiting_for_clear_lso_data_(false),
97 remove_mask_(0) {
88 DCHECK(profile); 98 DCHECK(profile);
89 } 99 }
90 100
91 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, 101 BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
92 TimePeriod time_period, 102 TimePeriod time_period,
93 base::Time delete_end) 103 base::Time delete_end)
94 : profile_(profile), 104 : profile_(profile),
95 quota_manager_(NULL), 105 quota_manager_(NULL),
96 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), 106 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()),
97 delete_begin_(CalculateBeginDeleteTime(time_period)), 107 delete_begin_(CalculateBeginDeleteTime(time_period)),
98 delete_end_(delete_end), 108 delete_end_(delete_end),
99 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( 109 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_(
100 this, &BrowsingDataRemover::DoClearCache)), 110 this, &BrowsingDataRemover::DoClearCache)),
101 next_cache_state_(STATE_NONE), 111 next_cache_state_(STATE_NONE),
102 cache_(NULL), 112 cache_(NULL),
103 main_context_getter_(profile->GetRequestContext()), 113 main_context_getter_(profile->GetRequestContext()),
104 media_context_getter_(profile->GetRequestContextForMedia()), 114 media_context_getter_(profile->GetRequestContextForMedia()),
105 waiting_for_clear_history_(false), 115 waiting_for_clear_history_(false),
106 waiting_for_clear_quota_managed_data_(false), 116 waiting_for_clear_quota_managed_data_(false),
107 waiting_for_clear_networking_history_(false), 117 waiting_for_clear_networking_history_(false),
108 waiting_for_clear_cookies_(false), 118 waiting_for_clear_cookies_(false),
109 waiting_for_clear_cache_(false), 119 waiting_for_clear_cache_(false),
110 waiting_for_clear_lso_data_(false) { 120 waiting_for_clear_lso_data_(false),
121 remove_mask_(0) {
111 DCHECK(profile); 122 DCHECK(profile);
112 } 123 }
113 124
114 BrowsingDataRemover::~BrowsingDataRemover() { 125 BrowsingDataRemover::~BrowsingDataRemover() {
115 DCHECK(all_done()); 126 DCHECK(all_done());
116 } 127 }
117 128
118 // Static. 129 // Static.
119 void BrowsingDataRemover::set_removing(bool removing) { 130 void BrowsingDataRemover::set_removing(bool removing) {
120 DCHECK(removing_ != removing); 131 DCHECK(removing_ != removing);
121 removing_ = removing; 132 removing_ = removing;
122 } 133 }
123 134
124 void BrowsingDataRemover::Remove(int remove_mask) { 135 void BrowsingDataRemover::Remove(int remove_mask) {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
126 set_removing(true); 137 set_removing(true);
138 remove_mask_ = remove_mask;
127 139
128 if (remove_mask & REMOVE_HISTORY) { 140 if (remove_mask & REMOVE_HISTORY) {
129 HistoryService* history_service = 141 HistoryService* history_service =
130 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 142 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
131 if (history_service) { 143 if (history_service) {
132 std::set<GURL> restrict_urls; 144 std::set<GURL> restrict_urls;
133 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History")); 145 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
134 waiting_for_clear_history_ = true; 146 waiting_for_clear_history_ = true;
135 history_service->ExpireHistoryBetween(restrict_urls, 147 history_service->ExpireHistoryBetween(restrict_urls,
136 delete_begin_, delete_end_, 148 delete_begin_, delete_end_,
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return; 375 return;
364 376
365 // The NetLog contains download history, but may also contain form data, 377 // The NetLog contains download history, but may also contain form data,
366 // cookies and passwords. Simplest just to always clear it. Must be cleared 378 // 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 379 // after the cache, as cleaning up the disk cache exposes some of the history
368 // in the NetLog. 380 // in the NetLog.
369 if (g_browser_process->net_log()) 381 if (g_browser_process->net_log())
370 g_browser_process->net_log()->ClearAllPassivelyCapturedEvents(); 382 g_browser_process->net_log()->ClearAllPassivelyCapturedEvents();
371 383
372 set_removing(false); 384 set_removing(false);
385
386 // Send global notification, then notify any explicit observers.
387 BrowsingDataRemover::NotificationDetail details(delete_begin_, remove_mask_);
388 content::NotificationService::current()->Notify(
389 chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
390 content::Source<Profile>(profile_->GetOriginalProfile()),
jochen (gone - plz use gerrit) 2011/12/13 13:18:48 can you invoke the browsing data deleter on the in
Mike West 2011/12/13 14:23:26 Yup. I should just use the profile here, not the o
391 content::Details<BrowsingDataRemover::NotificationDetail>(&details));
392
373 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone()); 393 FOR_EACH_OBSERVER(Observer, observer_list_, OnBrowsingDataRemoverDone());
374 394
375 // History requests aren't happy if you delete yourself from the callback. 395 // History requests aren't happy if you delete yourself from the callback.
376 // As such, we do a delete later. 396 // As such, we do a delete later.
377 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 397 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
378 } 398 }
379 399
380 void BrowsingDataRemover::ClearedNetworkHistory() { 400 void BrowsingDataRemover::ClearedNetworkHistory() {
381 waiting_for_clear_networking_history_ = false; 401 waiting_for_clear_networking_history_ = false;
382 402
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 GetURLRequestContext()->cookie_store()->GetCookieMonster(); 606 GetURLRequestContext()->cookie_store()->GetCookieMonster();
587 if (cookie_monster) { 607 if (cookie_monster) {
588 cookie_monster->DeleteAllCreatedBetweenAsync( 608 cookie_monster->DeleteAllCreatedBetweenAsync(
589 delete_begin_, delete_end_, 609 delete_begin_, delete_end_,
590 base::Bind(&BrowsingDataRemover::OnClearedCookies, 610 base::Bind(&BrowsingDataRemover::OnClearedCookies,
591 base::Unretained(this))); 611 base::Unretained(this)));
592 } else { 612 } else {
593 OnClearedCookies(0); 613 OnClearedCookies(0);
594 } 614 }
595 } 615 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698