OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
11 // ----------- -------------- | 11 // ----------- -------------- |
12 // HistoryService <----------------> HistoryBackend | 12 // HistoryService <----------------> HistoryBackend |
13 // -> HistoryDatabase | 13 // -> HistoryDatabase |
14 // -> SQLite connection to History | 14 // -> SQLite connection to History |
15 // -> ArchivedDatabase | 15 // -> ArchivedDatabase |
16 // -> SQLite connection to Archived History | 16 // -> SQLite connection to Archived History |
17 // -> TextDatabaseManager | 17 // -> TextDatabaseManager |
18 // -> SQLite connection to one month's data | 18 // -> SQLite connection to one month's data |
19 // -> SQLite connection to one month's data | 19 // -> SQLite connection to one month's data |
20 // ... | 20 // ... |
21 // -> ThumbnailDatabase | 21 // -> ThumbnailDatabase |
22 // -> SQLite connection to Thumbnails | 22 // -> SQLite connection to Thumbnails |
23 // (and favicons) | 23 // (and favicons) |
24 | 24 |
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/memory/ref_counted.h" | 29 #include "base/memory/ref_counted.h" |
29 #include "base/message_loop.h" | 30 #include "base/message_loop.h" |
30 #include "base/path_service.h" | 31 #include "base/path_service.h" |
31 #include "base/string_util.h" | 32 #include "base/string_util.h" |
32 #include "base/threading/thread.h" | 33 #include "base/threading/thread.h" |
33 #include "chrome/browser/autocomplete/history_url_provider.h" | 34 #include "chrome/browser/autocomplete/history_url_provider.h" |
34 #include "chrome/browser/browser_process.h" | 35 #include "chrome/browser/browser_process.h" |
35 #include "chrome/browser/history/history_backend.h" | 36 #include "chrome/browser/history/history_backend.h" |
36 #include "chrome/browser/history/history_notifications.h" | 37 #include "chrome/browser/history/history_notifications.h" |
37 #include "chrome/browser/history/history_types.h" | 38 #include "chrome/browser/history/history_types.h" |
38 #include "chrome/browser/history/in_memory_database.h" | 39 #include "chrome/browser/history/in_memory_database.h" |
39 #include "chrome/browser/history/in_memory_history_backend.h" | 40 #include "chrome/browser/history/in_memory_history_backend.h" |
41 #include "chrome/browser/history/in_memory_url_index.h" | |
40 #include "chrome/browser/history/top_sites.h" | 42 #include "chrome/browser/history/top_sites.h" |
41 #include "chrome/browser/prefs/pref_service.h" | 43 #include "chrome/browser/prefs/pref_service.h" |
42 #include "chrome/browser/profiles/profile.h" | 44 #include "chrome/browser/profiles/profile.h" |
43 #include "chrome/browser/ui/profile_error_dialog.h" | 45 #include "chrome/browser/ui/profile_error_dialog.h" |
44 #include "chrome/browser/visitedlink/visitedlink_master.h" | 46 #include "chrome/browser/visitedlink/visitedlink_master.h" |
45 #include "chrome/common/chrome_constants.h" | 47 #include "chrome/common/chrome_constants.h" |
46 #include "chrome/common/chrome_notification_types.h" | 48 #include "chrome/common/chrome_notification_types.h" |
49 #include "chrome/common/chrome_switches.h" | |
47 #include "chrome/common/pref_names.h" | 50 #include "chrome/common/pref_names.h" |
48 #include "chrome/common/thumbnail_score.h" | 51 #include "chrome/common/thumbnail_score.h" |
49 #include "chrome/common/url_constants.h" | 52 #include "chrome/common/url_constants.h" |
50 #include "content/browser/download/download_persistent_store_info.h" | 53 #include "content/browser/download/download_persistent_store_info.h" |
51 #include "content/public/browser/browser_thread.h" | 54 #include "content/public/browser/browser_thread.h" |
52 #include "content/public/browser/notification_service.h" | 55 #include "content/public/browser/notification_service.h" |
53 #include "grit/chromium_strings.h" | 56 #include "grit/chromium_strings.h" |
54 #include "grit/generated_resources.h" | 57 #include "grit/generated_resources.h" |
55 #include "third_party/skia/include/core/SkBitmap.h" | 58 #include "third_party/skia/include/core/SkBitmap.h" |
56 | 59 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 return backend_loaded_; | 177 return backend_loaded_; |
175 } | 178 } |
176 | 179 |
177 void HistoryService::UnloadBackend() { | 180 void HistoryService::UnloadBackend() { |
178 if (!history_backend_) | 181 if (!history_backend_) |
179 return; // Already unloaded. | 182 return; // Already unloaded. |
180 | 183 |
181 // Get rid of the in-memory backend. | 184 // Get rid of the in-memory backend. |
182 in_memory_backend_.reset(); | 185 in_memory_backend_.reset(); |
183 | 186 |
187 // Give the InMemoryURLIndex a chance to shutdown. | |
188 if (in_memory_url_index_.get()) | |
189 in_memory_url_index_->ShutDown(); | |
190 | |
184 // The backend's destructor must run on the history thread since it is not | 191 // The backend's destructor must run on the history thread since it is not |
185 // threadsafe. So this thread must not be the last thread holding a reference | 192 // threadsafe. So this thread must not be the last thread holding a reference |
186 // to the backend, or a crash could happen. | 193 // to the backend, or a crash could happen. |
187 // | 194 // |
188 // We have a reference to the history backend. There is also an extra | 195 // We have a reference to the history backend. There is also an extra |
189 // reference held by our delegate installed in the backend, which | 196 // reference held by our delegate installed in the backend, which |
190 // HistoryBackend::Closing will release. This means if we scheduled a call | 197 // HistoryBackend::Closing will release. This means if we scheduled a call |
191 // to HistoryBackend::Closing and *then* released our backend reference, there | 198 // to HistoryBackend::Closing and *then* released our backend reference, there |
192 // will be a race between us and the backend's Closing function to see who is | 199 // will be a race between us and the backend's Closing function to see who is |
193 // the last holder of a reference. If the backend thread's Closing manages to | 200 // the last holder of a reference. If the backend thread's Closing manages to |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 history::URLDatabase* HistoryService::InMemoryDatabase() { | 243 history::URLDatabase* HistoryService::InMemoryDatabase() { |
237 // NOTE: See comments in BackendLoaded() as to why we call | 244 // NOTE: See comments in BackendLoaded() as to why we call |
238 // LoadBackendIfNecessary() here even though it won't affect the return value | 245 // LoadBackendIfNecessary() here even though it won't affect the return value |
239 // for this call. | 246 // for this call. |
240 LoadBackendIfNecessary(); | 247 LoadBackendIfNecessary(); |
241 if (in_memory_backend_.get()) | 248 if (in_memory_backend_.get()) |
242 return in_memory_backend_->db(); | 249 return in_memory_backend_->db(); |
243 return NULL; | 250 return NULL; |
244 } | 251 } |
245 | 252 |
253 #if 0 | |
Peter Kasting
2012/02/04 02:20:31
Shouldn't have #if 0s by commit time...
mrossetti
2012/02/04 04:30:53
No, again I'm embarrassed.
| |
246 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { | 254 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { |
247 // NOTE: See comments in BackendLoaded() as to why we call | 255 // NOTE: See comments in BackendLoaded() as to why we call |
248 // LoadBackendIfNecessary() here even though it won't affect the return value | 256 // LoadBackendIfNecessary() here even though it won't affect the return value |
249 // for this call. | 257 // for this call. |
250 LoadBackendIfNecessary(); | 258 LoadBackendIfNecessary(); |
251 if (in_memory_backend_.get()) | 259 if (history_backend_.get()) |
252 return in_memory_backend_->InMemoryIndex(); | 260 return history_backend_->InMemoryIndex(); |
253 return NULL; | 261 return NULL; |
254 } | 262 } |
263 #endif | |
255 | 264 |
256 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { | 265 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { |
257 ScheduleAndForget(PRIORITY_UI, | 266 ScheduleAndForget(PRIORITY_UI, |
258 &HistoryBackend::SetSegmentPresentationIndex, | 267 &HistoryBackend::SetSegmentPresentationIndex, |
259 segment_id, index); | 268 segment_id, index); |
260 } | 269 } |
261 | 270 |
262 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, | 271 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, |
263 TemplateURLID keyword_id, | 272 TemplateURLID keyword_id, |
264 const string16& term) { | 273 const string16& term) { |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 bool no_db) { | 692 bool no_db) { |
684 if (!thread_->Start()) { | 693 if (!thread_->Start()) { |
685 Cleanup(); | 694 Cleanup(); |
686 return false; | 695 return false; |
687 } | 696 } |
688 | 697 |
689 history_dir_ = history_dir; | 698 history_dir_ = history_dir; |
690 bookmark_service_ = bookmark_service; | 699 bookmark_service_ = bookmark_service; |
691 no_db_ = no_db; | 700 no_db_ = no_db; |
692 | 701 |
702 if (profile_ && !CommandLine::ForCurrentProcess()->HasSwitch( | |
703 switches::kDisableHistoryQuickProvider)) { | |
704 std::string languages = | |
705 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
706 in_memory_url_index_.reset( | |
707 new history::InMemoryURLIndex(profile_, history_dir_, languages)); | |
708 in_memory_url_index_->Init(); | |
709 } | |
710 | |
693 // Create the history backend. | 711 // Create the history backend. |
694 LoadBackendIfNecessary(); | 712 LoadBackendIfNecessary(); |
695 return true; | 713 return true; |
696 } | 714 } |
697 | 715 |
698 void HistoryService::ScheduleAutocomplete(HistoryURLProvider* provider, | 716 void HistoryService::ScheduleAutocomplete(HistoryURLProvider* provider, |
699 HistoryURLProviderParams* params) { | 717 HistoryURLProviderParams* params) { |
700 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::ScheduleAutocomplete, | 718 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::ScheduleAutocomplete, |
701 scoped_refptr<HistoryURLProvider>(provider), params); | 719 scoped_refptr<HistoryURLProvider>(provider), params); |
702 } | 720 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
853 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 871 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
854 if (ts) | 872 if (ts) |
855 ts->MigrateFromHistory(); | 873 ts->MigrateFromHistory(); |
856 } | 874 } |
857 } | 875 } |
858 | 876 |
859 void HistoryService::OnTopSitesReady() { | 877 void HistoryService::OnTopSitesReady() { |
860 ScheduleAndForget(PRIORITY_NORMAL, | 878 ScheduleAndForget(PRIORITY_NORMAL, |
861 &HistoryBackend::MigrateThumbnailsDatabase); | 879 &HistoryBackend::MigrateThumbnailsDatabase); |
862 } | 880 } |
OLD | NEW |