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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // callers of this assume that if the backend isn't yet loaded it will be | 186 // callers of this assume that if the backend isn't yet loaded it will be |
187 // soon, so they will either listen for notifications or just retry this call | 187 // soon, so they will either listen for notifications or just retry this call |
188 // later. If we've purged the backend, we haven't necessarily restarted it | 188 // later. If we've purged the backend, we haven't necessarily restarted it |
189 // loading by now, so we need to trigger the load in order to maintain that | 189 // loading by now, so we need to trigger the load in order to maintain that |
190 // expectation. | 190 // expectation. |
191 LoadBackendIfNecessary(); | 191 LoadBackendIfNecessary(); |
192 return backend_loaded_; | 192 return backend_loaded_; |
193 } | 193 } |
194 | 194 |
195 void HistoryService::UnloadBackend() { | 195 void HistoryService::UnloadBackend() { |
196 if (!history_backend_) | 196 if (!history_backend_.get()) |
197 return; // Already unloaded. | 197 return; // Already unloaded. |
198 | 198 |
199 // Get rid of the in-memory backend. | 199 // Get rid of the in-memory backend. |
200 in_memory_backend_.reset(); | 200 in_memory_backend_.reset(); |
201 | 201 |
202 // Give the InMemoryURLIndex a chance to shutdown. | 202 // Give the InMemoryURLIndex a chance to shutdown. |
203 if (in_memory_url_index_.get()) | 203 if (in_memory_url_index_.get()) |
204 in_memory_url_index_->ShutDown(); | 204 in_memory_url_index_->ShutDown(); |
205 | 205 |
206 // The backend's destructor must run on the history thread since it is not | 206 // The backend's destructor must run on the history thread since it is not |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 // Allow all about: and chrome: URLs except about:blank, since the user may | 835 // Allow all about: and chrome: URLs except about:blank, since the user may |
836 // like to see "chrome://memory/", etc. in their history and autocomplete. | 836 // like to see "chrome://memory/", etc. in their history and autocomplete. |
837 if (url == GURL(chrome::kAboutBlankURL)) | 837 if (url == GURL(chrome::kAboutBlankURL)) |
838 return false; | 838 return false; |
839 | 839 |
840 return true; | 840 return true; |
841 } | 841 } |
842 | 842 |
843 void HistoryService::SetInMemoryBackend(int backend_id, | 843 void HistoryService::SetInMemoryBackend(int backend_id, |
844 history::InMemoryHistoryBackend* mem_backend) { | 844 history::InMemoryHistoryBackend* mem_backend) { |
845 if (!history_backend_ || current_backend_id_ != backend_id) { | 845 if (!history_backend_.get() || current_backend_id_ != backend_id) { |
846 VLOG(1) << "Message from obsolete backend"; | 846 VLOG(1) << "Message from obsolete backend"; |
847 // Cleaning up the memory backend. | 847 // Cleaning up the memory backend. |
848 delete mem_backend; | 848 delete mem_backend; |
849 return; | 849 return; |
850 } | 850 } |
851 DCHECK(!in_memory_backend_.get()) << "Setting mem DB twice"; | 851 DCHECK(!in_memory_backend_.get()) << "Setting mem DB twice"; |
852 in_memory_backend_.reset(mem_backend); | 852 in_memory_backend_.reset(mem_backend); |
853 | 853 |
854 // The database requires additional initialization once we own it. | 854 // The database requires additional initialization once we own it. |
855 in_memory_backend_->AttachToHistoryService(profile_); | 855 in_memory_backend_->AttachToHistoryService(profile_); |
856 } | 856 } |
857 | 857 |
858 void HistoryService::NotifyProfileError(int backend_id, | 858 void HistoryService::NotifyProfileError(int backend_id, |
859 sql::InitStatus init_status) { | 859 sql::InitStatus init_status) { |
860 if (!history_backend_ || current_backend_id_ != backend_id) { | 860 if (!history_backend_.get() || current_backend_id_ != backend_id) { |
861 VLOG(1) << "Message from obsolete backend"; | 861 VLOG(1) << "Message from obsolete backend"; |
862 return; | 862 return; |
863 } | 863 } |
864 ShowProfileErrorDialog( | 864 ShowProfileErrorDialog( |
865 (init_status == sql::INIT_FAILURE) ? | 865 (init_status == sql::INIT_FAILURE) ? |
866 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | 866 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); |
867 } | 867 } |
868 | 868 |
869 void HistoryService::DeleteURL(const GURL& url) { | 869 void HistoryService::DeleteURL(const GURL& url) { |
870 // We will update the visited links when we observe the delete notifications. | 870 // We will update the visited links when we observe the delete notifications. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 | 907 |
908 // The details object just contains the pointer to the object that the | 908 // The details object just contains the pointer to the object that the |
909 // backend has allocated for us. The receiver of the notification will cast | 909 // backend has allocated for us. The receiver of the notification will cast |
910 // this to the proper type. | 910 // this to the proper type. |
911 content::Details<history::HistoryDetails> det(details); | 911 content::Details<history::HistoryDetails> det(details); |
912 | 912 |
913 content::NotificationService::current()->Notify(type, source, det); | 913 content::NotificationService::current()->Notify(type, source, det); |
914 } | 914 } |
915 | 915 |
916 void HistoryService::LoadBackendIfNecessary() { | 916 void HistoryService::LoadBackendIfNecessary() { |
917 if (!thread_ || history_backend_) | 917 if (!thread_ || history_backend_.get()) |
918 return; // Failed to init, or already started loading. | 918 return; // Failed to init, or already started loading. |
919 | 919 |
920 ++current_backend_id_; | 920 ++current_backend_id_; |
921 scoped_refptr<HistoryBackend> backend( | 921 scoped_refptr<HistoryBackend> backend( |
922 new HistoryBackend(history_dir_, | 922 new HistoryBackend(history_dir_, |
923 current_backend_id_, | 923 current_backend_id_, |
924 new BackendDelegate(this, profile_), | 924 new BackendDelegate(this, profile_), |
925 bookmark_service_)); | 925 bookmark_service_)); |
926 history_backend_.swap(backend); | 926 history_backend_.swap(backend); |
927 | 927 |
928 // There may not be a profile when unit testing. | 928 // There may not be a profile when unit testing. |
929 std::string languages; | 929 std::string languages; |
930 if (profile_) { | 930 if (profile_) { |
931 PrefService* prefs = profile_->GetPrefs(); | 931 PrefService* prefs = profile_->GetPrefs(); |
932 languages = prefs->GetString(prefs::kAcceptLanguages); | 932 languages = prefs->GetString(prefs::kAcceptLanguages); |
933 } | 933 } |
934 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, languages, no_db_); | 934 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, languages, no_db_); |
935 } | 935 } |
936 | 936 |
937 void HistoryService::OnDBLoaded(int backend_id) { | 937 void HistoryService::OnDBLoaded(int backend_id) { |
938 if (!history_backend_ || current_backend_id_ != backend_id) { | 938 if (!history_backend_.get() || current_backend_id_ != backend_id) { |
939 VLOG(1) << "Message from obsolete backend"; | 939 VLOG(1) << "Message from obsolete backend"; |
940 return; | 940 return; |
941 } | 941 } |
942 backend_loaded_ = true; | 942 backend_loaded_ = true; |
943 content::NotificationService::current()->Notify( | 943 content::NotificationService::current()->Notify( |
944 chrome::NOTIFICATION_HISTORY_LOADED, | 944 chrome::NOTIFICATION_HISTORY_LOADED, |
945 content::Source<Profile>(profile_), | 945 content::Source<Profile>(profile_), |
946 content::Details<HistoryService>(this)); | 946 content::Details<HistoryService>(this)); |
947 if (thread_ && profile_) { | 947 if (thread_ && profile_) { |
948 // We don't want to force creation of TopSites. | 948 // We don't want to force creation of TopSites. |
949 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 949 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
950 if (ts) | 950 if (ts) |
951 ts->HistoryLoaded(); | 951 ts->HistoryLoaded(); |
952 } | 952 } |
953 } | 953 } |
954 | 954 |
955 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { | 955 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { |
956 history::URLDatabase* db = InMemoryDatabase(); | 956 history::URLDatabase* db = InMemoryDatabase(); |
957 return db && (db->GetRowForURL(url, url_row) != 0); | 957 return db && (db->GetRowForURL(url, url_row) != 0); |
958 } | 958 } |
959 | 959 |
960 void HistoryService::StartTopSitesMigration(int backend_id) { | 960 void HistoryService::StartTopSitesMigration(int backend_id) { |
961 if (!history_backend_ || current_backend_id_ != backend_id) { | 961 if (!history_backend_.get() || current_backend_id_ != backend_id) { |
962 VLOG(1) << "Message from obsolete backend"; | 962 VLOG(1) << "Message from obsolete backend"; |
963 return; | 963 return; |
964 } | 964 } |
965 needs_top_sites_migration_ = true; | 965 needs_top_sites_migration_ = true; |
966 if (thread_ && profile_) { | 966 if (thread_ && profile_) { |
967 // We don't want to force creation of TopSites. | 967 // We don't want to force creation of TopSites. |
968 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 968 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
969 if (ts) | 969 if (ts) |
970 ts->MigrateFromHistory(); | 970 ts->MigrateFromHistory(); |
971 } | 971 } |
(...skipping 12 matching lines...) Expand all Loading... |
984 void HistoryService::RemoveVisitDatabaseObserver( | 984 void HistoryService::RemoveVisitDatabaseObserver( |
985 history::VisitDatabaseObserver* observer) { | 985 history::VisitDatabaseObserver* observer) { |
986 visit_database_observers_->RemoveObserver(observer); | 986 visit_database_observers_->RemoveObserver(observer); |
987 } | 987 } |
988 | 988 |
989 void HistoryService::NotifyVisitDBObserversOnAddVisit( | 989 void HistoryService::NotifyVisitDBObserversOnAddVisit( |
990 const history::BriefVisitInfo& info) { | 990 const history::BriefVisitInfo& info) { |
991 visit_database_observers_->Notify( | 991 visit_database_observers_->Notify( |
992 &history::VisitDatabaseObserver::OnAddVisit, info); | 992 &history::VisitDatabaseObserver::OnAddVisit, info); |
993 } | 993 } |
OLD | NEW |