| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return backend_loaded_; | 166 return backend_loaded_; |
| 166 } | 167 } |
| 167 | 168 |
| 168 void HistoryService::UnloadBackend() { | 169 void HistoryService::UnloadBackend() { |
| 169 if (!history_backend_) | 170 if (!history_backend_) |
| 170 return; // Already unloaded. | 171 return; // Already unloaded. |
| 171 | 172 |
| 172 // Get rid of the in-memory backend. | 173 // Get rid of the in-memory backend. |
| 173 in_memory_backend_.reset(); | 174 in_memory_backend_.reset(); |
| 174 | 175 |
| 176 // Give the InMemoryURLIndex a chance to shutdown. |
| 177 InMemoryIndex()->ShutDown(); |
| 178 |
| 175 // The backend's destructor must run on the history thread since it is not | 179 // The backend's destructor must run on the history thread since it is not |
| 176 // threadsafe. So this thread must not be the last thread holding a reference | 180 // threadsafe. So this thread must not be the last thread holding a reference |
| 177 // to the backend, or a crash could happen. | 181 // to the backend, or a crash could happen. |
| 178 // | 182 // |
| 179 // We have a reference to the history backend. There is also an extra | 183 // We have a reference to the history backend. There is also an extra |
| 180 // reference held by our delegate installed in the backend, which | 184 // reference held by our delegate installed in the backend, which |
| 181 // HistoryBackend::Closing will release. This means if we scheduled a call | 185 // HistoryBackend::Closing will release. This means if we scheduled a call |
| 182 // to HistoryBackend::Closing and *then* released our backend reference, there | 186 // to HistoryBackend::Closing and *then* released our backend reference, there |
| 183 // will be a race between us and the backend's Closing function to see who is | 187 // will be a race between us and the backend's Closing function to see who is |
| 184 // the last holder of a reference. If the backend thread's Closing manages to | 188 // the last holder of a reference. If the backend thread's Closing manages to |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 if (in_memory_backend_.get()) | 229 if (in_memory_backend_.get()) |
| 226 return in_memory_backend_->db(); | 230 return in_memory_backend_->db(); |
| 227 return NULL; | 231 return NULL; |
| 228 } | 232 } |
| 229 | 233 |
| 230 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { | 234 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { |
| 231 // NOTE: See comments in BackendLoaded() as to why we call | 235 // NOTE: See comments in BackendLoaded() as to why we call |
| 232 // LoadBackendIfNecessary() here even though it won't affect the return value | 236 // LoadBackendIfNecessary() here even though it won't affect the return value |
| 233 // for this call. | 237 // for this call. |
| 234 LoadBackendIfNecessary(); | 238 LoadBackendIfNecessary(); |
| 235 if (in_memory_backend_.get()) | 239 if (history_backend_.get()) |
| 236 return in_memory_backend_->InMemoryIndex(); | 240 return history_backend_->InMemoryIndex(); |
| 237 return NULL; | 241 return NULL; |
| 238 } | 242 } |
| 239 | 243 |
| 240 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { | 244 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { |
| 241 ScheduleAndForget(PRIORITY_UI, | 245 ScheduleAndForget(PRIORITY_UI, |
| 242 &HistoryBackend::SetSegmentPresentationIndex, | 246 &HistoryBackend::SetSegmentPresentationIndex, |
| 243 segment_id, index); | 247 segment_id, index); |
| 244 } | 248 } |
| 245 | 249 |
| 246 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, | 250 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 785 |
| 782 NotificationService::current()->Notify(type, source, det); | 786 NotificationService::current()->Notify(type, source, det); |
| 783 } | 787 } |
| 784 | 788 |
| 785 void HistoryService::LoadBackendIfNecessary() { | 789 void HistoryService::LoadBackendIfNecessary() { |
| 786 if (!thread_ || history_backend_) | 790 if (!thread_ || history_backend_) |
| 787 return; // Failed to init, or already started loading. | 791 return; // Failed to init, or already started loading. |
| 788 | 792 |
| 789 ++current_backend_id_; | 793 ++current_backend_id_; |
| 790 scoped_refptr<HistoryBackend> backend( | 794 scoped_refptr<HistoryBackend> backend( |
| 791 new HistoryBackend(history_dir_, | 795 new HistoryBackend(profile_, |
| 796 history_dir_, |
| 792 current_backend_id_, | 797 current_backend_id_, |
| 793 new BackendDelegate(this, profile_), | 798 new BackendDelegate(this, profile_), |
| 794 bookmark_service_)); | 799 bookmark_service_)); |
| 795 history_backend_.swap(backend); | 800 history_backend_.swap(backend); |
| 796 | 801 |
| 797 // There may not be a profile when unit testing. | 802 // There may not be a profile when unit testing. |
| 798 std::string languages; | 803 std::string languages; |
| 799 if (profile_) { | 804 if (profile_) { |
| 800 PrefService* prefs = profile_->GetPrefs(); | 805 PrefService* prefs = profile_->GetPrefs(); |
| 801 languages = prefs->GetString(prefs::kAcceptLanguages); | 806 languages = prefs->GetString(prefs::kAcceptLanguages); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 831 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 836 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
| 832 if (ts) | 837 if (ts) |
| 833 ts->MigrateFromHistory(); | 838 ts->MigrateFromHistory(); |
| 834 } | 839 } |
| 835 } | 840 } |
| 836 | 841 |
| 837 void HistoryService::OnTopSitesReady() { | 842 void HistoryService::OnTopSitesReady() { |
| 838 ScheduleAndForget(PRIORITY_NORMAL, | 843 ScheduleAndForget(PRIORITY_NORMAL, |
| 839 &HistoryBackend::MigrateThumbnailsDatabase); | 844 &HistoryBackend::MigrateThumbnailsDatabase); |
| 840 } | 845 } |
| OLD | NEW |