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" | |
54 #include "components/history/core/browser/history_types.h" | 53 #include "components/history/core/browser/history_types.h" |
55 #include "components/history/core/browser/in_memory_database.h" | 54 #include "components/history/core/browser/in_memory_database.h" |
56 #include "components/history/core/browser/keyword_search_term.h" | 55 #include "components/history/core/browser/keyword_search_term.h" |
57 #include "components/history/core/common/thumbnail_score.h" | 56 #include "components/history/core/common/thumbnail_score.h" |
58 #include "components/visitedlink/browser/visitedlink_master.h" | 57 #include "components/visitedlink/browser/visitedlink_master.h" |
59 #include "content/public/browser/browser_thread.h" | 58 #include "content/public/browser/browser_thread.h" |
60 #include "content/public/browser/download_item.h" | 59 #include "content/public/browser/download_item.h" |
61 #include "content/public/browser/notification_service.h" | 60 #include "content/public/browser/notification_service.h" |
62 #include "sync/api/sync_error_factory.h" | 61 #include "sync/api/sync_error_factory.h" |
63 #include "third_party/skia/include/core/SkBitmap.h" | 62 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 base::Time visit_time) OVERRIDE { | 172 base::Time visit_time) OVERRIDE { |
174 service_task_runner_->PostTask(FROM_HERE, | 173 service_task_runner_->PostTask(FROM_HERE, |
175 base::Bind(&HistoryService::NotifyURLVisited, | 174 base::Bind(&HistoryService::NotifyURLVisited, |
176 history_service_, | 175 history_service_, |
177 transition, | 176 transition, |
178 row, | 177 row, |
179 redirects, | 178 redirects, |
180 visit_time)); | 179 visit_time)); |
181 } | 180 } |
182 | 181 |
| 182 virtual void NotifyAddVisit(const history::BriefVisitInfo& info) OVERRIDE { |
| 183 service_task_runner_->PostTask( |
| 184 FROM_HERE, |
| 185 base::Bind(&HistoryService::NotifyAddVisit, history_service_, info)); |
| 186 } |
| 187 |
183 virtual void BroadcastNotifications( | 188 virtual void BroadcastNotifications( |
184 int type, | 189 int type, |
185 scoped_ptr<history::HistoryDetails> details) OVERRIDE { | 190 scoped_ptr<history::HistoryDetails> details) OVERRIDE { |
186 // Send the notification on the history thread. | 191 // Send the notification on the history thread. |
187 if (content::NotificationService::current()) { | 192 if (content::NotificationService::current()) { |
188 content::Details<history::HistoryDetails> det(details.get()); | 193 content::Details<history::HistoryDetails> det(details.get()); |
189 content::NotificationService::current()->Notify( | 194 content::NotificationService::current()->Notify( |
190 type, content::Source<Profile>(profile_), det); | 195 type, content::Source<Profile>(profile_), det); |
191 } | 196 } |
192 // Send the notification to the history service on the main thread. | 197 // Send the notification to the history service on the main thread. |
193 service_task_runner_->PostTask( | 198 service_task_runner_->PostTask( |
194 FROM_HERE, | 199 FROM_HERE, |
195 base::Bind(&HistoryService::BroadcastNotificationsHelper, | 200 base::Bind(&HistoryService::BroadcastNotificationsHelper, |
196 history_service_, type, base::Passed(&details))); | 201 history_service_, type, base::Passed(&details))); |
197 } | 202 } |
198 | 203 |
199 virtual void DBLoaded() OVERRIDE { | 204 virtual void DBLoaded() OVERRIDE { |
200 service_task_runner_->PostTask( | 205 service_task_runner_->PostTask( |
201 FROM_HERE, | 206 FROM_HERE, |
202 base::Bind(&HistoryService::OnDBLoaded, history_service_)); | 207 base::Bind(&HistoryService::OnDBLoaded, history_service_)); |
203 } | 208 } |
204 | 209 |
205 virtual void NotifyVisitDBObserversOnAddVisit( | |
206 const history::BriefVisitInfo& info) OVERRIDE { | |
207 service_task_runner_->PostTask( | |
208 FROM_HERE, | |
209 base::Bind(&HistoryService::NotifyVisitDBObserversOnAddVisit, | |
210 history_service_, info)); | |
211 } | |
212 | |
213 private: | 210 private: |
214 const base::WeakPtr<HistoryService> history_service_; | 211 const base::WeakPtr<HistoryService> history_service_; |
215 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | 212 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
216 Profile* const profile_; | 213 Profile* const profile_; |
217 }; | 214 }; |
218 | 215 |
219 // The history thread is intentionally not a BrowserThread because the | 216 // The history thread is intentionally not a BrowserThread because the |
220 // sync integration unit tests depend on being able to create more than one | 217 // sync integration unit tests depend on being able to create more than one |
221 // history thread. | 218 // history thread. |
222 HistoryService::HistoryService() | 219 HistoryService::HistoryService() |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 keyword_id, term); | 338 keyword_id, term); |
342 } | 339 } |
343 | 340 |
344 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { | 341 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { |
345 DCHECK(thread_) << "History service being called after cleanup"; | 342 DCHECK(thread_) << "History service being called after cleanup"; |
346 DCHECK(thread_checker_.CalledOnValidThread()); | 343 DCHECK(thread_checker_.CalledOnValidThread()); |
347 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::URLsNoLongerBookmarked, | 344 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::URLsNoLongerBookmarked, |
348 urls); | 345 urls); |
349 } | 346 } |
350 | 347 |
351 void HistoryService::AddHistoryServiceObserver( | 348 void HistoryService::AddObserver(Observer* observer) { |
352 history::HistoryServiceObserver* observer) { | 349 observers_.AddObserver(observer); |
353 history_service_observers_.AddObserver(observer); | |
354 } | 350 } |
355 | 351 |
356 void HistoryService::RemoveHistoryServiceObserver( | 352 void HistoryService::RemoveObserver(Observer* observer) { |
357 history::HistoryServiceObserver* observer) { | 353 observers_.RemoveObserver(observer); |
358 history_service_observers_.RemoveObserver(observer); | |
359 } | 354 } |
360 | 355 |
361 void HistoryService::ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, | 356 void HistoryService::ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, |
362 base::CancelableTaskTracker* tracker) { | 357 base::CancelableTaskTracker* tracker) { |
363 DCHECK(thread_) << "History service being called after cleanup"; | 358 DCHECK(thread_) << "History service being called after cleanup"; |
364 DCHECK(thread_checker_.CalledOnValidThread()); | 359 DCHECK(thread_checker_.CalledOnValidThread()); |
365 base::CancelableTaskTracker::IsCanceledCallback is_canceled; | 360 base::CancelableTaskTracker::IsCanceledCallback is_canceled; |
366 tracker->NewTrackedTaskId(&is_canceled); | 361 tracker->NewTrackedTaskId(&is_canceled); |
367 // Use base::ThreadTaskRunnerHandler::Get() to get a message loop proxy to | 362 // Use base::ThreadTaskRunnerHandler::Get() to get a message loop proxy to |
368 // the current message loop so that we can forward the call to the method | 363 // the current message loop so that we can forward the call to the method |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 DCHECK(thread_checker_.CalledOnValidThread()); | 1238 DCHECK(thread_checker_.CalledOnValidThread()); |
1244 history::URLDatabase* db = InMemoryDatabase(); | 1239 history::URLDatabase* db = InMemoryDatabase(); |
1245 return db && (db->GetRowForURL(url, url_row) != 0); | 1240 return db && (db->GetRowForURL(url, url_row) != 0); |
1246 } | 1241 } |
1247 | 1242 |
1248 void HistoryService::NotifyURLVisited(ui::PageTransition transition, | 1243 void HistoryService::NotifyURLVisited(ui::PageTransition transition, |
1249 const history::URLRow& row, | 1244 const history::URLRow& row, |
1250 const history::RedirectList& redirects, | 1245 const history::RedirectList& redirects, |
1251 base::Time visit_time) { | 1246 base::Time visit_time) { |
1252 DCHECK(thread_checker_.CalledOnValidThread()); | 1247 DCHECK(thread_checker_.CalledOnValidThread()); |
1253 FOR_EACH_OBSERVER(history::HistoryServiceObserver, | 1248 FOR_EACH_OBSERVER(HistoryService::Observer, |
1254 history_service_observers_, | 1249 observers_, |
1255 OnURLVisited(transition, row, redirects, visit_time)); | 1250 OnURLVisited(transition, row, redirects, visit_time)); |
1256 } | 1251 } |
1257 | 1252 |
1258 void HistoryService::AddVisitDatabaseObserver( | 1253 void HistoryService::NotifyAddVisit(const history::BriefVisitInfo& info) { |
1259 history::VisitDatabaseObserver* observer) { | |
1260 DCHECK(thread_checker_.CalledOnValidThread()); | 1254 DCHECK(thread_checker_.CalledOnValidThread()); |
1261 visit_database_observers_.AddObserver(observer); | 1255 FOR_EACH_OBSERVER(HistoryService::Observer, observers_, OnAddVisit(info)); |
1262 } | |
1263 | |
1264 void HistoryService::RemoveVisitDatabaseObserver( | |
1265 history::VisitDatabaseObserver* observer) { | |
1266 DCHECK(thread_checker_.CalledOnValidThread()); | |
1267 visit_database_observers_.RemoveObserver(observer); | |
1268 } | |
1269 | |
1270 void HistoryService::NotifyVisitDBObserversOnAddVisit( | |
1271 const history::BriefVisitInfo& info) { | |
1272 DCHECK(thread_checker_.CalledOnValidThread()); | |
1273 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_, | |
1274 OnAddVisit(info)); | |
1275 } | 1256 } |
1276 | 1257 |
1277 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription> | 1258 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription> |
1278 HistoryService::AddFaviconChangedCallback( | 1259 HistoryService::AddFaviconChangedCallback( |
1279 const HistoryService::OnFaviconChangedCallback& callback) { | 1260 const HistoryService::OnFaviconChangedCallback& callback) { |
1280 DCHECK(thread_checker_.CalledOnValidThread()); | 1261 DCHECK(thread_checker_.CalledOnValidThread()); |
1281 return favicon_changed_callback_list_.Add(callback); | 1262 return favicon_changed_callback_list_.Add(callback); |
1282 } | 1263 } |
1283 | 1264 |
1284 void HistoryService::NotifyFaviconChanged( | 1265 void HistoryService::NotifyFaviconChanged( |
1285 const std::set<GURL>& changed_favicons) { | 1266 const std::set<GURL>& changed_favicons) { |
1286 DCHECK(thread_checker_.CalledOnValidThread()); | 1267 DCHECK(thread_checker_.CalledOnValidThread()); |
1287 favicon_changed_callback_list_.Notify(changed_favicons); | 1268 favicon_changed_callback_list_.Notify(changed_favicons); |
1288 } | 1269 } |
OLD | NEW |