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

Side by Side Diff: chrome/browser/history/history_service.cc

Issue 631253002: Refactor sending NOTIFICATION_HISTORY_URL_VISITED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests on Android Created 6 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // The history system runs on a background thread so that potentially slow 5 // The history system runs on a background thread so that potentially slow
6 // database operations don't delay the browser. This backend processing is 6 // database operations don't delay the browser. This backend processing is
7 // represented by HistoryBackend. The HistoryService's job is to dispatch to 7 // represented by HistoryBackend. The HistoryService's job is to dispatch to
8 // that thread. 8 // that thread.
9 // 9 //
10 // Main thread History thread 10 // Main thread History thread
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 166 }
167 167
168 virtual void NotifyFaviconChanged(const std::set<GURL>& urls) override { 168 virtual void NotifyFaviconChanged(const std::set<GURL>& urls) override {
169 // Send the notification to the history service on the main thread. 169 // Send the notification to the history service on the main thread.
170 service_task_runner_->PostTask( 170 service_task_runner_->PostTask(
171 FROM_HERE, 171 FROM_HERE,
172 base::Bind( 172 base::Bind(
173 &HistoryService::NotifyFaviconChanged, history_service_, urls)); 173 &HistoryService::NotifyFaviconChanged, history_service_, urls));
174 } 174 }
175 175
176 virtual void NotifyURLVisited(ui::PageTransition transition,
177 const history::URLRow& row,
178 const history::RedirectList& redirects,
179 base::Time visit_time) OVERRIDE {
180 service_task_runner_->PostTask(FROM_HERE,
181 base::Bind(&HistoryService::NotifyURLVisited,
182 history_service_,
183 transition,
184 row,
185 redirects,
186 visit_time));
187 }
188
176 virtual void BroadcastNotifications( 189 virtual void BroadcastNotifications(
177 int type, 190 int type,
178 scoped_ptr<history::HistoryDetails> details) override { 191 scoped_ptr<history::HistoryDetails> details) override {
179 // Send the notification on the history thread. 192 // Send the notification on the history thread.
180 if (content::NotificationService::current()) { 193 if (content::NotificationService::current()) {
181 content::Details<history::HistoryDetails> det(details.get()); 194 content::Details<history::HistoryDetails> det(details.get());
182 content::NotificationService::current()->Notify( 195 content::NotificationService::current()->Notify(
183 type, content::Source<Profile>(profile_), det); 196 type, content::Source<Profile>(profile_), det);
184 } 197 }
185 // Send the notification to the history service on the main thread. 198 // Send the notification to the history service on the main thread.
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 return false; 988 return false;
976 } 989 }
977 990
978 history_dir_ = history_dir; 991 history_dir_ = history_dir;
979 no_db_ = no_db; 992 no_db_ = no_db;
980 993
981 if (profile_) { 994 if (profile_) {
982 std::string languages = 995 std::string languages =
983 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); 996 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
984 in_memory_url_index_.reset(new history::InMemoryURLIndex( 997 in_memory_url_index_.reset(new history::InMemoryURLIndex(
985 profile_, history_dir_, languages, history_client_)); 998 profile_, this, history_dir_, languages, history_client_));
986 in_memory_url_index_->Init(); 999 in_memory_url_index_->Init();
987 } 1000 }
988 1001
989 // Create the history backend. 1002 // Create the history backend.
990 scoped_refptr<HistoryBackend> backend( 1003 scoped_refptr<HistoryBackend> backend(
991 new HistoryBackend(history_dir_, 1004 new HistoryBackend(history_dir_,
992 new BackendDelegate( 1005 new BackendDelegate(
993 weak_ptr_factory_.GetWeakPtr(), 1006 weak_ptr_factory_.GetWeakPtr(),
994 base::ThreadTaskRunnerHandle::Get(), 1007 base::ThreadTaskRunnerHandle::Get(),
995 profile_), 1008 profile_),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 delete_directive); 1111 delete_directive);
1099 } 1112 }
1100 1113
1101 void HistoryService::SetInMemoryBackend( 1114 void HistoryService::SetInMemoryBackend(
1102 scoped_ptr<history::InMemoryHistoryBackend> mem_backend) { 1115 scoped_ptr<history::InMemoryHistoryBackend> mem_backend) {
1103 DCHECK(thread_checker_.CalledOnValidThread()); 1116 DCHECK(thread_checker_.CalledOnValidThread());
1104 DCHECK(!in_memory_backend_) << "Setting mem DB twice"; 1117 DCHECK(!in_memory_backend_) << "Setting mem DB twice";
1105 in_memory_backend_.reset(mem_backend.release()); 1118 in_memory_backend_.reset(mem_backend.release());
1106 1119
1107 // The database requires additional initialization once we own it. 1120 // The database requires additional initialization once we own it.
1108 in_memory_backend_->AttachToHistoryService(profile_); 1121 in_memory_backend_->AttachToHistoryService(profile_, this);
1109 } 1122 }
1110 1123
1111 void HistoryService::NotifyProfileError(sql::InitStatus init_status) { 1124 void HistoryService::NotifyProfileError(sql::InitStatus init_status) {
1112 DCHECK(thread_checker_.CalledOnValidThread()); 1125 DCHECK(thread_checker_.CalledOnValidThread());
1113 if (history_client_) 1126 if (history_client_)
1114 history_client_->NotifyProfileError(init_status); 1127 history_client_->NotifyProfileError(init_status);
1115 } 1128 }
1116 1129
1117 void HistoryService::DeleteURL(const GURL& url) { 1130 void HistoryService::DeleteURL(const GURL& url) {
1118 DCHECK(thread_) << "History service being called after cleanup"; 1131 DCHECK(thread_) << "History service being called after cleanup";
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 history::URLDatabase* db = InMemoryDatabase(); 1242 history::URLDatabase* db = InMemoryDatabase();
1230 return db && (db->GetRowForURL(url, url_row) != 0); 1243 return db && (db->GetRowForURL(url, url_row) != 0);
1231 } 1244 }
1232 1245
1233 void HistoryService::NotifyAddVisit(const history::BriefVisitInfo& info) { 1246 void HistoryService::NotifyAddVisit(const history::BriefVisitInfo& info) {
1234 DCHECK(thread_checker_.CalledOnValidThread()); 1247 DCHECK(thread_checker_.CalledOnValidThread());
1235 FOR_EACH_OBSERVER( 1248 FOR_EACH_OBSERVER(
1236 history::HistoryServiceObserver, observers_, OnAddVisit(this, info)); 1249 history::HistoryServiceObserver, observers_, OnAddVisit(this, info));
1237 } 1250 }
1238 1251
1252 void HistoryService::NotifyURLVisited(ui::PageTransition transition,
1253 const history::URLRow& row,
1254 const history::RedirectList& redirects,
1255 base::Time visit_time) {
1256 DCHECK(thread_checker_.CalledOnValidThread());
1257 FOR_EACH_OBSERVER(history::HistoryServiceObserver,
1258 observers_,
1259 OnURLVisited(this, transition, row, redirects, visit_time));
1260 }
1261
1239 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription> 1262 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription>
1240 HistoryService::AddFaviconChangedCallback( 1263 HistoryService::AddFaviconChangedCallback(
1241 const HistoryService::OnFaviconChangedCallback& callback) { 1264 const HistoryService::OnFaviconChangedCallback& callback) {
1242 DCHECK(thread_checker_.CalledOnValidThread()); 1265 DCHECK(thread_checker_.CalledOnValidThread());
1243 return favicon_changed_callback_list_.Add(callback); 1266 return favicon_changed_callback_list_.Add(callback);
1244 } 1267 }
1245 1268
1246 void HistoryService::NotifyFaviconChanged( 1269 void HistoryService::NotifyFaviconChanged(
1247 const std::set<GURL>& changed_favicons) { 1270 const std::set<GURL>& changed_favicons) {
1248 DCHECK(thread_checker_.CalledOnValidThread()); 1271 DCHECK(thread_checker_.CalledOnValidThread());
1249 favicon_changed_callback_list_.Notify(changed_favicons); 1272 favicon_changed_callback_list_.Notify(changed_favicons);
1250 } 1273 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history_service.h ('k') | chrome/browser/history/history_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698