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

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

Issue 115674: More NotificationRegistrar conversions. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 7 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
« no previous file with comments | « chrome/browser/browsing_data_remover.h ('k') | chrome/browser/google_url_tracker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/chrome_thread.h" 7 #include "chrome/browser/chrome_thread.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/download/download_manager.h" 9 #include "chrome/browser/download/download_manager.h"
10 #include "chrome/browser/history/history.h" 10 #include "chrome/browser/history/history.h"
(...skipping 23 matching lines...) Expand all
34 BrowsingDataRemover* remover) { 34 BrowsingDataRemover* remover) {
35 } 35 }
36 36
37 bool BrowsingDataRemover::removing_ = false; 37 bool BrowsingDataRemover::removing_ = false;
38 38
39 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, Time delete_begin, 39 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, Time delete_begin,
40 Time delete_end) 40 Time delete_end)
41 : profile_(profile), 41 : profile_(profile),
42 delete_begin_(delete_begin), 42 delete_begin_(delete_begin),
43 delete_end_(delete_end), 43 delete_end_(delete_end),
44 waiting_for_keywords_(false),
45 waiting_for_clear_history_(false), 44 waiting_for_clear_history_(false),
46 waiting_for_clear_cache_(false) { 45 waiting_for_clear_cache_(false) {
47 DCHECK(profile); 46 DCHECK(profile);
48 } 47 }
49 48
50 BrowsingDataRemover::~BrowsingDataRemover() { 49 BrowsingDataRemover::~BrowsingDataRemover() {
51 DCHECK(all_done()); 50 DCHECK(all_done());
52 } 51 }
53 52
54 void BrowsingDataRemover::Remove(int remove_mask) { 53 void BrowsingDataRemover::Remove(int remove_mask) {
55 DCHECK(!removing_); 54 DCHECK(!removing_);
56 removing_ = true; 55 removing_ = true;
57 56
58 if (remove_mask & REMOVE_HISTORY) { 57 if (remove_mask & REMOVE_HISTORY) {
59 HistoryService* history_service = 58 HistoryService* history_service =
60 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 59 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
61 if (history_service) { 60 if (history_service) {
62 UserMetrics::RecordAction(L"ClearBrowsingData_History", profile_); 61 UserMetrics::RecordAction(L"ClearBrowsingData_History", profile_);
63 waiting_for_clear_history_ = true; 62 waiting_for_clear_history_ = true;
64 history_service->ExpireHistoryBetween(delete_begin_, delete_end_, 63 history_service->ExpireHistoryBetween(delete_begin_, delete_end_,
65 &request_consumer_, 64 &request_consumer_,
66 NewCallback(this, &BrowsingDataRemover::OnHistoryDeletionDone)); 65 NewCallback(this, &BrowsingDataRemover::OnHistoryDeletionDone));
67 } 66 }
68 67
69 // As part of history deletion we also delete the auto-generated keywords. 68 // As part of history deletion we also delete the auto-generated keywords.
70 TemplateURLModel* keywords_model = profile_->GetTemplateURLModel(); 69 TemplateURLModel* keywords_model = profile_->GetTemplateURLModel();
71 if (keywords_model && !keywords_model->loaded()) { 70 if (keywords_model && !keywords_model->loaded()) {
72 waiting_for_keywords_ = true; 71 registrar_.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED,
73 NotificationService::current()->AddObserver( 72 Source<TemplateURLModel>(keywords_model));
74 this, NotificationType::TEMPLATE_URL_MODEL_LOADED,
75 Source<TemplateURLModel>(keywords_model));
76 keywords_model->Load(); 73 keywords_model->Load();
77 } else if (keywords_model) { 74 } else if (keywords_model) {
78 keywords_model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); 75 keywords_model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_);
79 } 76 }
80 77
81 // We also delete the list of recently closed tabs. Since these expire, 78 // We also delete the list of recently closed tabs. Since these expire,
82 // they can't be more than a day old, so we can simply clear them all. 79 // they can't be more than a day old, so we can simply clear them all.
83 TabRestoreService* tab_service = profile_->GetTabRestoreService(); 80 TabRestoreService* tab_service = profile_->GetTabRestoreService();
84 if (tab_service) { 81 if (tab_service) {
85 tab_service->ClearEntries(); 82 tab_service->ClearEntries();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 153
157 void BrowsingDataRemover::Observe(NotificationType type, 154 void BrowsingDataRemover::Observe(NotificationType type,
158 const NotificationSource& source, 155 const NotificationSource& source,
159 const NotificationDetails& details) { 156 const NotificationDetails& details) {
160 // TODO(brettw) bug 1139736: This should also observe session 157 // TODO(brettw) bug 1139736: This should also observe session
161 // clearing (what about other things such as passwords, etc.?) and wait for 158 // clearing (what about other things such as passwords, etc.?) and wait for
162 // them to complete before continuing. 159 // them to complete before continuing.
163 DCHECK(type == NotificationType::TEMPLATE_URL_MODEL_LOADED); 160 DCHECK(type == NotificationType::TEMPLATE_URL_MODEL_LOADED);
164 TemplateURLModel* model = Source<TemplateURLModel>(source).ptr(); 161 TemplateURLModel* model = Source<TemplateURLModel>(source).ptr();
165 if (model->profile() == profile_->GetOriginalProfile()) { 162 if (model->profile() == profile_->GetOriginalProfile()) {
166 NotificationService::current()->RemoveObserver( 163 registrar_.RemoveAll();
167 this,
168 NotificationType::TEMPLATE_URL_MODEL_LOADED,
169 Source<TemplateURLModel>(model));
170
171 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_); 164 model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_);
172
173 waiting_for_keywords_ = false;
174
175 NotifyAndDeleteIfDone(); 165 NotifyAndDeleteIfDone();
176 } 166 }
177 } 167 }
178 168
179 void BrowsingDataRemover::NotifyAndDeleteIfDone() { 169 void BrowsingDataRemover::NotifyAndDeleteIfDone() {
180 // TODO(brettw) bug 1139736: see TODO in Observe() above. 170 // TODO(brettw) bug 1139736: see TODO in Observe() above.
181 if (!all_done()) 171 if (!all_done())
182 return; 172 return;
183 173
184 removing_ = false; 174 removing_ = false;
(...skipping 28 matching lines...) Expand all
213 if (delete_begin.is_null()) 203 if (delete_begin.is_null())
214 cache->DoomAllEntries(); 204 cache->DoomAllEntries();
215 else 205 else
216 cache->DoomEntriesBetween(delete_begin, delete_end); 206 cache->DoomEntriesBetween(delete_begin, delete_end);
217 } 207 }
218 208
219 // Notify the UI thread that we are done. 209 // Notify the UI thread that we are done.
220 ui_loop->PostTask(FROM_HERE, NewRunnableMethod( 210 ui_loop->PostTask(FROM_HERE, NewRunnableMethod(
221 this, &BrowsingDataRemover::ClearedCache)); 211 this, &BrowsingDataRemover::ClearedCache));
222 } 212 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_remover.h ('k') | chrome/browser/google_url_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698