| OLD | NEW |
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "chrome/browser/history/web_history_service.h" | 43 #include "chrome/browser/history/web_history_service.h" |
| 44 #include "chrome/browser/history/web_history_service_factory.h" | 44 #include "chrome/browser/history/web_history_service_factory.h" |
| 45 #include "chrome/browser/profiles/profile.h" | 45 #include "chrome/browser/profiles/profile.h" |
| 46 #include "chrome/common/chrome_constants.h" | 46 #include "chrome/common/chrome_constants.h" |
| 47 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 48 #include "chrome/common/importer/imported_favicon_usage.h" | 48 #include "chrome/common/importer/imported_favicon_usage.h" |
| 49 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
| 50 #include "chrome/common/url_constants.h" | 50 #include "chrome/common/url_constants.h" |
| 51 #include "components/dom_distiller/core/url_constants.h" | 51 #include "components/dom_distiller/core/url_constants.h" |
| 52 #include "components/history/core/browser/history_client.h" | 52 #include "components/history/core/browser/history_client.h" |
| 53 #include "components/history/core/browser/history_service_observer.h" |
| 53 #include "components/history/core/browser/history_types.h" | 54 #include "components/history/core/browser/history_types.h" |
| 54 #include "components/history/core/browser/in_memory_database.h" | 55 #include "components/history/core/browser/in_memory_database.h" |
| 55 #include "components/history/core/browser/keyword_search_term.h" | 56 #include "components/history/core/browser/keyword_search_term.h" |
| 56 #include "components/history/core/common/thumbnail_score.h" | 57 #include "components/history/core/common/thumbnail_score.h" |
| 57 #include "components/visitedlink/browser/visitedlink_master.h" | 58 #include "components/visitedlink/browser/visitedlink_master.h" |
| 58 #include "content/public/browser/browser_thread.h" | 59 #include "content/public/browser/browser_thread.h" |
| 59 #include "content/public/browser/download_item.h" | 60 #include "content/public/browser/download_item.h" |
| 60 #include "content/public/browser/notification_service.h" | 61 #include "content/public/browser/notification_service.h" |
| 61 #include "sync/api/sync_error_factory.h" | 62 #include "sync/api/sync_error_factory.h" |
| 62 #include "third_party/skia/include/core/SkBitmap.h" | 63 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 160 } |
| 160 | 161 |
| 161 virtual void NotifyFaviconChanged(const std::set<GURL>& urls) OVERRIDE { | 162 virtual void NotifyFaviconChanged(const std::set<GURL>& urls) OVERRIDE { |
| 162 // Send the notification to the history service on the main thread. | 163 // Send the notification to the history service on the main thread. |
| 163 service_task_runner_->PostTask( | 164 service_task_runner_->PostTask( |
| 164 FROM_HERE, | 165 FROM_HERE, |
| 165 base::Bind( | 166 base::Bind( |
| 166 &HistoryService::NotifyFaviconChanged, history_service_, urls)); | 167 &HistoryService::NotifyFaviconChanged, history_service_, urls)); |
| 167 } | 168 } |
| 168 | 169 |
| 170 virtual void NotifyURLVisited(ui::PageTransition transition, |
| 171 const history::URLRow& row, |
| 172 const history::RedirectList& redirects, |
| 173 const base::Time& visit_time) OVERRIDE { |
| 174 service_task_runner_->PostTask(FROM_HERE, |
| 175 base::Bind(&HistoryService::NotifyURLVisited, |
| 176 history_service_, |
| 177 transition, |
| 178 row, |
| 179 redirects, |
| 180 visit_time)); |
| 181 } |
| 182 |
| 169 virtual void BroadcastNotifications( | 183 virtual void BroadcastNotifications( |
| 170 int type, | 184 int type, |
| 171 scoped_ptr<history::HistoryDetails> details) OVERRIDE { | 185 scoped_ptr<history::HistoryDetails> details) OVERRIDE { |
| 172 // Send the notification on the history thread. | 186 // Send the notification on the history thread. |
| 173 if (content::NotificationService::current()) { | 187 if (content::NotificationService::current()) { |
| 174 content::Details<history::HistoryDetails> det(details.get()); | 188 content::Details<history::HistoryDetails> det(details.get()); |
| 175 content::NotificationService::current()->Notify( | 189 content::NotificationService::current()->Notify( |
| 176 type, content::Source<Profile>(profile_), det); | 190 type, content::Source<Profile>(profile_), det); |
| 177 } | 191 } |
| 178 // Send the notification to the history service on the main thread. | 192 // Send the notification to the history service on the main thread. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 keyword_id, term); | 341 keyword_id, term); |
| 328 } | 342 } |
| 329 | 343 |
| 330 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { | 344 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { |
| 331 DCHECK(thread_) << "History service being called after cleanup"; | 345 DCHECK(thread_) << "History service being called after cleanup"; |
| 332 DCHECK(thread_checker_.CalledOnValidThread()); | 346 DCHECK(thread_checker_.CalledOnValidThread()); |
| 333 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::URLsNoLongerBookmarked, | 347 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::URLsNoLongerBookmarked, |
| 334 urls); | 348 urls); |
| 335 } | 349 } |
| 336 | 350 |
| 351 void HistoryService::AddHistoryServiceObserver( |
| 352 history::HistoryServiceObserver* observer) { |
| 353 history_service_observers_.AddObserver(observer); |
| 354 } |
| 355 |
| 356 void HistoryService::RemoveHistoryServiceObserver( |
| 357 history::HistoryServiceObserver* observer) { |
| 358 history_service_observers_.RemoveObserver(observer); |
| 359 } |
| 360 |
| 337 void HistoryService::ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, | 361 void HistoryService::ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, |
| 338 base::CancelableTaskTracker* tracker) { | 362 base::CancelableTaskTracker* tracker) { |
| 339 DCHECK(thread_) << "History service being called after cleanup"; | 363 DCHECK(thread_) << "History service being called after cleanup"; |
| 340 DCHECK(thread_checker_.CalledOnValidThread()); | 364 DCHECK(thread_checker_.CalledOnValidThread()); |
| 341 base::CancelableTaskTracker::IsCanceledCallback is_canceled; | 365 base::CancelableTaskTracker::IsCanceledCallback is_canceled; |
| 342 tracker->NewTrackedTaskId(&is_canceled); | 366 tracker->NewTrackedTaskId(&is_canceled); |
| 343 // Use base::ThreadTaskRunnerHandler::Get() to get a message loop proxy to | 367 // Use base::ThreadTaskRunnerHandler::Get() to get a message loop proxy to |
| 344 // the current message loop so that we can forward the call to the method | 368 // the current message loop so that we can forward the call to the method |
| 345 // HistoryDBTask::DoneRunOnMainThread in the correct thread. | 369 // HistoryDBTask::DoneRunOnMainThread in the correct thread. |
| 346 thread_->message_loop_proxy()->PostTask( | 370 thread_->message_loop_proxy()->PostTask( |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 return false; | 990 return false; |
| 967 } | 991 } |
| 968 | 992 |
| 969 history_dir_ = history_dir; | 993 history_dir_ = history_dir; |
| 970 no_db_ = no_db; | 994 no_db_ = no_db; |
| 971 | 995 |
| 972 if (profile_) { | 996 if (profile_) { |
| 973 std::string languages = | 997 std::string languages = |
| 974 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | 998 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 975 in_memory_url_index_.reset(new history::InMemoryURLIndex( | 999 in_memory_url_index_.reset(new history::InMemoryURLIndex( |
| 976 profile_, history_dir_, languages, history_client_)); | 1000 profile_, this, history_dir_, languages, history_client_)); |
| 977 in_memory_url_index_->Init(); | 1001 in_memory_url_index_->Init(); |
| 978 } | 1002 } |
| 979 | 1003 |
| 980 // Create the history backend. | 1004 // Create the history backend. |
| 981 scoped_refptr<HistoryBackend> backend( | 1005 scoped_refptr<HistoryBackend> backend( |
| 982 new HistoryBackend(history_dir_, | 1006 new HistoryBackend(history_dir_, |
| 983 new BackendDelegate( | 1007 new BackendDelegate( |
| 984 weak_ptr_factory_.GetWeakPtr(), | 1008 weak_ptr_factory_.GetWeakPtr(), |
| 985 base::ThreadTaskRunnerHandle::Get(), | 1009 base::ThreadTaskRunnerHandle::Get(), |
| 986 profile_), | 1010 profile_), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 delete_directive); | 1113 delete_directive); |
| 1090 } | 1114 } |
| 1091 | 1115 |
| 1092 void HistoryService::SetInMemoryBackend( | 1116 void HistoryService::SetInMemoryBackend( |
| 1093 scoped_ptr<history::InMemoryHistoryBackend> mem_backend) { | 1117 scoped_ptr<history::InMemoryHistoryBackend> mem_backend) { |
| 1094 DCHECK(thread_checker_.CalledOnValidThread()); | 1118 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1095 DCHECK(!in_memory_backend_) << "Setting mem DB twice"; | 1119 DCHECK(!in_memory_backend_) << "Setting mem DB twice"; |
| 1096 in_memory_backend_.reset(mem_backend.release()); | 1120 in_memory_backend_.reset(mem_backend.release()); |
| 1097 | 1121 |
| 1098 // The database requires additional initialization once we own it. | 1122 // The database requires additional initialization once we own it. |
| 1099 in_memory_backend_->AttachToHistoryService(profile_); | 1123 in_memory_backend_->AttachToHistoryService(profile_, this); |
| 1100 } | 1124 } |
| 1101 | 1125 |
| 1102 void HistoryService::NotifyProfileError(sql::InitStatus init_status) { | 1126 void HistoryService::NotifyProfileError(sql::InitStatus init_status) { |
| 1103 DCHECK(thread_checker_.CalledOnValidThread()); | 1127 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1104 if (history_client_) | 1128 if (history_client_) |
| 1105 history_client_->NotifyProfileError(init_status); | 1129 history_client_->NotifyProfileError(init_status); |
| 1106 } | 1130 } |
| 1107 | 1131 |
| 1108 void HistoryService::DeleteURL(const GURL& url) { | 1132 void HistoryService::DeleteURL(const GURL& url) { |
| 1109 DCHECK(thread_) << "History service being called after cleanup"; | 1133 DCHECK(thread_) << "History service being called after cleanup"; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 content::Source<Profile>(profile_), | 1238 content::Source<Profile>(profile_), |
| 1215 content::Details<HistoryService>(this)); | 1239 content::Details<HistoryService>(this)); |
| 1216 } | 1240 } |
| 1217 | 1241 |
| 1218 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { | 1242 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { |
| 1219 DCHECK(thread_checker_.CalledOnValidThread()); | 1243 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1220 history::URLDatabase* db = InMemoryDatabase(); | 1244 history::URLDatabase* db = InMemoryDatabase(); |
| 1221 return db && (db->GetRowForURL(url, url_row) != 0); | 1245 return db && (db->GetRowForURL(url, url_row) != 0); |
| 1222 } | 1246 } |
| 1223 | 1247 |
| 1248 void HistoryService::NotifyURLVisited(ui::PageTransition transition, |
| 1249 const history::URLRow& row, |
| 1250 const history::RedirectList& redirects, |
| 1251 const base::Time& visit_time) { |
| 1252 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1253 FOR_EACH_OBSERVER(history::HistoryServiceObserver, |
| 1254 history_service_observers_, |
| 1255 OnURLVisited(transition, row, redirects, visit_time)); |
| 1256 } |
| 1257 |
| 1224 void HistoryService::AddVisitDatabaseObserver( | 1258 void HistoryService::AddVisitDatabaseObserver( |
| 1225 history::VisitDatabaseObserver* observer) { | 1259 history::VisitDatabaseObserver* observer) { |
| 1226 DCHECK(thread_checker_.CalledOnValidThread()); | 1260 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1227 visit_database_observers_.AddObserver(observer); | 1261 visit_database_observers_.AddObserver(observer); |
| 1228 } | 1262 } |
| 1229 | 1263 |
| 1230 void HistoryService::RemoveVisitDatabaseObserver( | 1264 void HistoryService::RemoveVisitDatabaseObserver( |
| 1231 history::VisitDatabaseObserver* observer) { | 1265 history::VisitDatabaseObserver* observer) { |
| 1232 DCHECK(thread_checker_.CalledOnValidThread()); | 1266 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1233 visit_database_observers_.RemoveObserver(observer); | 1267 visit_database_observers_.RemoveObserver(observer); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1245 const HistoryService::OnFaviconChangedCallback& callback) { | 1279 const HistoryService::OnFaviconChangedCallback& callback) { |
| 1246 DCHECK(thread_checker_.CalledOnValidThread()); | 1280 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1247 return favicon_changed_callback_list_.Add(callback); | 1281 return favicon_changed_callback_list_.Add(callback); |
| 1248 } | 1282 } |
| 1249 | 1283 |
| 1250 void HistoryService::NotifyFaviconChanged( | 1284 void HistoryService::NotifyFaviconChanged( |
| 1251 const std::set<GURL>& changed_favicons) { | 1285 const std::set<GURL>& changed_favicons) { |
| 1252 DCHECK(thread_checker_.CalledOnValidThread()); | 1286 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1253 favicon_changed_callback_list_.Notify(changed_favicons); | 1287 favicon_changed_callback_list_.Notify(changed_favicons); |
| 1254 } | 1288 } |
| OLD | NEW |