| 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/task.h" | 32 #include "base/task.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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 return backend_loaded_; | 176 return backend_loaded_; |
| 176 } | 177 } |
| 177 | 178 |
| 178 void HistoryService::UnloadBackend() { | 179 void HistoryService::UnloadBackend() { |
| 179 if (!history_backend_) | 180 if (!history_backend_) |
| 180 return; // Already unloaded. | 181 return; // Already unloaded. |
| 181 | 182 |
| 182 // Get rid of the in-memory backend. | 183 // Get rid of the in-memory backend. |
| 183 in_memory_backend_.reset(); | 184 in_memory_backend_.reset(); |
| 184 | 185 |
| 186 // Give the InMemoryURLIndex a chance to shutdown. |
| 187 InMemoryIndex()->ShutDown(); |
| 188 |
| 185 // The backend's destructor must run on the history thread since it is not | 189 // The backend's destructor must run on the history thread since it is not |
| 186 // threadsafe. So this thread must not be the last thread holding a reference | 190 // threadsafe. So this thread must not be the last thread holding a reference |
| 187 // to the backend, or a crash could happen. | 191 // to the backend, or a crash could happen. |
| 188 // | 192 // |
| 189 // We have a reference to the history backend. There is also an extra | 193 // We have a reference to the history backend. There is also an extra |
| 190 // reference held by our delegate installed in the backend, which | 194 // reference held by our delegate installed in the backend, which |
| 191 // HistoryBackend::Closing will release. This means if we scheduled a call | 195 // HistoryBackend::Closing will release. This means if we scheduled a call |
| 192 // to HistoryBackend::Closing and *then* released our backend reference, there | 196 // to HistoryBackend::Closing and *then* released our backend reference, there |
| 193 // will be a race between us and the backend's Closing function to see who is | 197 // will be a race between us and the backend's Closing function to see who is |
| 194 // the last holder of a reference. If the backend thread's Closing manages to | 198 // 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... |
| 242 if (in_memory_backend_.get()) | 246 if (in_memory_backend_.get()) |
| 243 return in_memory_backend_->db(); | 247 return in_memory_backend_->db(); |
| 244 return NULL; | 248 return NULL; |
| 245 } | 249 } |
| 246 | 250 |
| 247 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { | 251 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { |
| 248 // NOTE: See comments in BackendLoaded() as to why we call | 252 // NOTE: See comments in BackendLoaded() as to why we call |
| 249 // LoadBackendIfNecessary() here even though it won't affect the return value | 253 // LoadBackendIfNecessary() here even though it won't affect the return value |
| 250 // for this call. | 254 // for this call. |
| 251 LoadBackendIfNecessary(); | 255 LoadBackendIfNecessary(); |
| 252 if (in_memory_backend_.get()) | 256 if (history_backend_.get()) |
| 253 return in_memory_backend_->InMemoryIndex(); | 257 return history_backend_->InMemoryIndex(); |
| 254 return NULL; | 258 return NULL; |
| 255 } | 259 } |
| 256 | 260 |
| 257 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { | 261 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { |
| 258 ScheduleAndForget(PRIORITY_UI, | 262 ScheduleAndForget(PRIORITY_UI, |
| 259 &HistoryBackend::SetSegmentPresentationIndex, | 263 &HistoryBackend::SetSegmentPresentationIndex, |
| 260 segment_id, index); | 264 segment_id, index); |
| 261 } | 265 } |
| 262 | 266 |
| 263 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, | 267 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 | 800 |
| 797 NotificationService::current()->Notify(type, source, det); | 801 NotificationService::current()->Notify(type, source, det); |
| 798 } | 802 } |
| 799 | 803 |
| 800 void HistoryService::LoadBackendIfNecessary() { | 804 void HistoryService::LoadBackendIfNecessary() { |
| 801 if (!thread_ || history_backend_) | 805 if (!thread_ || history_backend_) |
| 802 return; // Failed to init, or already started loading. | 806 return; // Failed to init, or already started loading. |
| 803 | 807 |
| 804 ++current_backend_id_; | 808 ++current_backend_id_; |
| 805 scoped_refptr<HistoryBackend> backend( | 809 scoped_refptr<HistoryBackend> backend( |
| 806 new HistoryBackend(history_dir_, | 810 new HistoryBackend(profile_, |
| 811 history_dir_, |
| 807 current_backend_id_, | 812 current_backend_id_, |
| 808 new BackendDelegate(this, profile_), | 813 new BackendDelegate(this, profile_), |
| 809 bookmark_service_)); | 814 bookmark_service_)); |
| 810 history_backend_.swap(backend); | 815 history_backend_.swap(backend); |
| 811 | 816 |
| 812 // There may not be a profile when unit testing. | 817 // There may not be a profile when unit testing. |
| 813 std::string languages; | 818 std::string languages; |
| 814 if (profile_) { | 819 if (profile_) { |
| 815 PrefService* prefs = profile_->GetPrefs(); | 820 PrefService* prefs = profile_->GetPrefs(); |
| 816 languages = prefs->GetString(prefs::kAcceptLanguages); | 821 languages = prefs->GetString(prefs::kAcceptLanguages); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 846 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 851 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
| 847 if (ts) | 852 if (ts) |
| 848 ts->MigrateFromHistory(); | 853 ts->MigrateFromHistory(); |
| 849 } | 854 } |
| 850 } | 855 } |
| 851 | 856 |
| 852 void HistoryService::OnTopSitesReady() { | 857 void HistoryService::OnTopSitesReady() { |
| 853 ScheduleAndForget(PRIORITY_NORMAL, | 858 ScheduleAndForget(PRIORITY_NORMAL, |
| 854 &HistoryBackend::MigrateThumbnailsDatabase); | 859 &HistoryBackend::MigrateThumbnailsDatabase); |
| 855 } | 860 } |
| OLD | NEW |