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 |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "base/path_service.h" | 30 #include "base/path_service.h" |
31 #include "base/string_util.h" | 31 #include "base/string_util.h" |
32 #include "base/threading/thread.h" | 32 #include "base/threading/thread.h" |
33 #include "chrome/browser/autocomplete/history_url_provider.h" | 33 #include "chrome/browser/autocomplete/history_url_provider.h" |
34 #include "chrome/browser/browser_process.h" | 34 #include "chrome/browser/browser_process.h" |
35 #include "chrome/browser/history/history_backend.h" | 35 #include "chrome/browser/history/history_backend.h" |
36 #include "chrome/browser/history/history_notifications.h" | 36 #include "chrome/browser/history/history_notifications.h" |
37 #include "chrome/browser/history/history_types.h" | 37 #include "chrome/browser/history/history_types.h" |
38 #include "chrome/browser/history/in_memory_database.h" | 38 #include "chrome/browser/history/in_memory_database.h" |
39 #include "chrome/browser/history/in_memory_history_backend.h" | 39 #include "chrome/browser/history/in_memory_history_backend.h" |
40 #include "chrome/browser/history/in_memory_url_index.h" | |
40 #include "chrome/browser/history/top_sites.h" | 41 #include "chrome/browser/history/top_sites.h" |
41 #include "chrome/browser/prefs/pref_service.h" | 42 #include "chrome/browser/prefs/pref_service.h" |
42 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
43 #include "chrome/browser/ui/profile_error_dialog.h" | 44 #include "chrome/browser/ui/profile_error_dialog.h" |
44 #include "chrome/browser/visitedlink/visitedlink_master.h" | 45 #include "chrome/browser/visitedlink/visitedlink_master.h" |
45 #include "chrome/common/chrome_constants.h" | 46 #include "chrome/common/chrome_constants.h" |
46 #include "chrome/common/chrome_notification_types.h" | 47 #include "chrome/common/chrome_notification_types.h" |
47 #include "chrome/common/pref_names.h" | 48 #include "chrome/common/pref_names.h" |
48 #include "chrome/common/thumbnail_score.h" | 49 #include "chrome/common/thumbnail_score.h" |
49 #include "chrome/common/url_constants.h" | 50 #include "chrome/common/url_constants.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 return backend_loaded_; | 175 return backend_loaded_; |
175 } | 176 } |
176 | 177 |
177 void HistoryService::UnloadBackend() { | 178 void HistoryService::UnloadBackend() { |
178 if (!history_backend_) | 179 if (!history_backend_) |
179 return; // Already unloaded. | 180 return; // Already unloaded. |
180 | 181 |
181 // Get rid of the in-memory backend. | 182 // Get rid of the in-memory backend. |
182 in_memory_backend_.reset(); | 183 in_memory_backend_.reset(); |
183 | 184 |
185 // Give the InMemoryURLIndex a chance to shutdown. | |
186 InMemoryIndex()->ShutDown(); | |
Peter Kasting
2012/01/14 00:12:49
Nit: Should this instead access |history_backend_|
mrossetti
2012/03/03 05:05:56
Done.
| |
187 | |
184 // The backend's destructor must run on the history thread since it is not | 188 // 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 | 189 // threadsafe. So this thread must not be the last thread holding a reference |
186 // to the backend, or a crash could happen. | 190 // to the backend, or a crash could happen. |
187 // | 191 // |
188 // We have a reference to the history backend. There is also an extra | 192 // We have a reference to the history backend. There is also an extra |
189 // reference held by our delegate installed in the backend, which | 193 // reference held by our delegate installed in the backend, which |
190 // HistoryBackend::Closing will release. This means if we scheduled a call | 194 // HistoryBackend::Closing will release. This means if we scheduled a call |
191 // to HistoryBackend::Closing and *then* released our backend reference, there | 195 // 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 | 196 // 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 | 197 // the last holder of a reference. If the backend thread's Closing manages to |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 if (in_memory_backend_.get()) | 245 if (in_memory_backend_.get()) |
242 return in_memory_backend_->db(); | 246 return in_memory_backend_->db(); |
243 return NULL; | 247 return NULL; |
244 } | 248 } |
245 | 249 |
246 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { | 250 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { |
247 // NOTE: See comments in BackendLoaded() as to why we call | 251 // NOTE: See comments in BackendLoaded() as to why we call |
248 // LoadBackendIfNecessary() here even though it won't affect the return value | 252 // LoadBackendIfNecessary() here even though it won't affect the return value |
249 // for this call. | 253 // for this call. |
250 LoadBackendIfNecessary(); | 254 LoadBackendIfNecessary(); |
251 if (in_memory_backend_.get()) | 255 if (history_backend_.get()) |
252 return in_memory_backend_->InMemoryIndex(); | 256 return history_backend_->InMemoryIndex(); |
253 return NULL; | 257 return NULL; |
254 } | 258 } |
255 | 259 |
256 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { | 260 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { |
257 ScheduleAndForget(PRIORITY_UI, | 261 ScheduleAndForget(PRIORITY_UI, |
258 &HistoryBackend::SetSegmentPresentationIndex, | 262 &HistoryBackend::SetSegmentPresentationIndex, |
259 segment_id, index); | 263 segment_id, index); |
260 } | 264 } |
261 | 265 |
262 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, | 266 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
802 | 806 |
803 content::NotificationService::current()->Notify(type, source, det); | 807 content::NotificationService::current()->Notify(type, source, det); |
804 } | 808 } |
805 | 809 |
806 void HistoryService::LoadBackendIfNecessary() { | 810 void HistoryService::LoadBackendIfNecessary() { |
807 if (!thread_ || history_backend_) | 811 if (!thread_ || history_backend_) |
808 return; // Failed to init, or already started loading. | 812 return; // Failed to init, or already started loading. |
809 | 813 |
810 ++current_backend_id_; | 814 ++current_backend_id_; |
811 scoped_refptr<HistoryBackend> backend( | 815 scoped_refptr<HistoryBackend> backend( |
812 new HistoryBackend(history_dir_, | 816 new HistoryBackend(profile_, |
817 history_dir_, | |
813 current_backend_id_, | 818 current_backend_id_, |
814 new BackendDelegate(this, profile_), | 819 new BackendDelegate(this, profile_), |
815 bookmark_service_)); | 820 bookmark_service_)); |
816 history_backend_.swap(backend); | 821 history_backend_.swap(backend); |
817 | 822 |
818 // There may not be a profile when unit testing. | 823 // There may not be a profile when unit testing. |
819 std::string languages; | 824 std::string languages; |
820 if (profile_) { | 825 if (profile_) { |
821 PrefService* prefs = profile_->GetPrefs(); | 826 PrefService* prefs = profile_->GetPrefs(); |
822 languages = prefs->GetString(prefs::kAcceptLanguages); | 827 languages = prefs->GetString(prefs::kAcceptLanguages); |
(...skipping 30 matching lines...) Expand all Loading... | |
853 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 858 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
854 if (ts) | 859 if (ts) |
855 ts->MigrateFromHistory(); | 860 ts->MigrateFromHistory(); |
856 } | 861 } |
857 } | 862 } |
858 | 863 |
859 void HistoryService::OnTopSitesReady() { | 864 void HistoryService::OnTopSitesReady() { |
860 ScheduleAndForget(PRIORITY_NORMAL, | 865 ScheduleAndForget(PRIORITY_NORMAL, |
861 &HistoryBackend::MigrateThumbnailsDatabase); | 866 &HistoryBackend::MigrateThumbnailsDatabase); |
862 } | 867 } |
OLD | NEW |