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 14 matching lines...) Expand all Loading... |
25 #include "chrome/browser/history/history.h" | 25 #include "chrome/browser/history/history.h" |
26 | 26 |
27 #include "base/callback.h" | 27 #include "base/callback.h" |
28 #include "base/command_line.h" | 28 #include "base/command_line.h" |
29 #include "base/memory/ref_counted.h" | 29 #include "base/memory/ref_counted.h" |
30 #include "base/message_loop.h" | 30 #include "base/message_loop.h" |
31 #include "base/path_service.h" | 31 #include "base/path_service.h" |
32 #include "base/string_util.h" | 32 #include "base/string_util.h" |
33 #include "base/threading/thread.h" | 33 #include "base/threading/thread.h" |
34 #include "chrome/browser/autocomplete/history_url_provider.h" | 34 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 35 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 36 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
35 #include "chrome/browser/browser_process.h" | 37 #include "chrome/browser/browser_process.h" |
36 #include "chrome/browser/history/history_backend.h" | 38 #include "chrome/browser/history/history_backend.h" |
37 #include "chrome/browser/history/history_notifications.h" | 39 #include "chrome/browser/history/history_notifications.h" |
38 #include "chrome/browser/history/history_types.h" | 40 #include "chrome/browser/history/history_types.h" |
39 #include "chrome/browser/history/in_memory_database.h" | 41 #include "chrome/browser/history/in_memory_database.h" |
40 #include "chrome/browser/history/in_memory_history_backend.h" | 42 #include "chrome/browser/history/in_memory_history_backend.h" |
41 #include "chrome/browser/history/in_memory_url_index.h" | 43 #include "chrome/browser/history/in_memory_url_index.h" |
42 #include "chrome/browser/history/top_sites.h" | 44 #include "chrome/browser/history/top_sites.h" |
43 #include "chrome/browser/history/visit_database.h" | 45 #include "chrome/browser/history/visit_database.h" |
44 #include "chrome/browser/history/visit_filter.h" | 46 #include "chrome/browser/history/visit_filter.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 history::URLDatabase* HistoryService::InMemoryDatabase() { | 258 history::URLDatabase* HistoryService::InMemoryDatabase() { |
257 // NOTE: See comments in BackendLoaded() as to why we call | 259 // NOTE: See comments in BackendLoaded() as to why we call |
258 // LoadBackendIfNecessary() here even though it won't affect the return value | 260 // LoadBackendIfNecessary() here even though it won't affect the return value |
259 // for this call. | 261 // for this call. |
260 LoadBackendIfNecessary(); | 262 LoadBackendIfNecessary(); |
261 if (in_memory_backend_.get()) | 263 if (in_memory_backend_.get()) |
262 return in_memory_backend_->db(); | 264 return in_memory_backend_->db(); |
263 return NULL; | 265 return NULL; |
264 } | 266 } |
265 | 267 |
| 268 void HistoryService::ShutdownOnUIThread() { |
| 269 // It's possible that bookmarks haven't loaded and history is waiting for |
| 270 // bookmarks to complete loading. In such a situation history can't shutdown |
| 271 // (meaning if we invoked history_service_->Cleanup now, we would |
| 272 // deadlock). To break the deadlock we tell BookmarkModel it's about to be |
| 273 // deleted so that it can release the signal history is waiting on, allowing |
| 274 // history to shutdown (history_service_->Cleanup to complete). In such a |
| 275 // scenario history sees an incorrect view of bookmarks, but it's better |
| 276 // than a deadlock. |
| 277 BookmarkModel* bookmark_model = static_cast<BookmarkModel*>( |
| 278 BookmarkModelFactory::GetForProfileIfExists(profile_)); |
| 279 if (bookmark_model) |
| 280 bookmark_model->Shutdown(); |
| 281 |
| 282 Cleanup(); |
| 283 } |
| 284 |
266 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { | 285 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { |
267 ScheduleAndForget(PRIORITY_UI, | 286 ScheduleAndForget(PRIORITY_UI, |
268 &HistoryBackend::SetSegmentPresentationIndex, | 287 &HistoryBackend::SetSegmentPresentationIndex, |
269 segment_id, index); | 288 segment_id, index); |
270 } | 289 } |
271 | 290 |
272 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, | 291 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, |
273 TemplateURLID keyword_id, | 292 TemplateURLID keyword_id, |
274 const string16& term) { | 293 const string16& term) { |
275 ScheduleAndForget(PRIORITY_UI, | 294 ScheduleAndForget(PRIORITY_UI, |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 void HistoryService::RemoveVisitDatabaseObserver( | 933 void HistoryService::RemoveVisitDatabaseObserver( |
915 history::VisitDatabaseObserver* observer) { | 934 history::VisitDatabaseObserver* observer) { |
916 visit_database_observers_->RemoveObserver(observer); | 935 visit_database_observers_->RemoveObserver(observer); |
917 } | 936 } |
918 | 937 |
919 void HistoryService::NotifyVisitDBObserversOnAddVisit( | 938 void HistoryService::NotifyVisitDBObserversOnAddVisit( |
920 const history::BriefVisitInfo& info) { | 939 const history::BriefVisitInfo& info) { |
921 visit_database_observers_->Notify( | 940 visit_database_observers_->Notify( |
922 &history::VisitDatabaseObserver::OnAddVisit, info); | 941 &history::VisitDatabaseObserver::OnAddVisit, info); |
923 } | 942 } |
OLD | NEW |