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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "chrome/browser/profiles/profile.h" | 42 #include "chrome/browser/profiles/profile.h" |
43 #include "chrome/browser/ui/profile_error_dialog.h" | 43 #include "chrome/browser/ui/profile_error_dialog.h" |
44 #include "chrome/browser/visitedlink/visitedlink_master.h" | 44 #include "chrome/browser/visitedlink/visitedlink_master.h" |
45 #include "chrome/common/chrome_constants.h" | 45 #include "chrome/common/chrome_constants.h" |
46 #include "chrome/common/chrome_notification_types.h" | 46 #include "chrome/common/chrome_notification_types.h" |
47 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
48 #include "chrome/common/thumbnail_score.h" | 48 #include "chrome/common/thumbnail_score.h" |
49 #include "chrome/common/url_constants.h" | 49 #include "chrome/common/url_constants.h" |
50 #include "content/browser/browser_thread.h" | 50 #include "content/browser/browser_thread.h" |
51 #include "content/browser/download/download_persistent_store_info.h" | 51 #include "content/browser/download/download_persistent_store_info.h" |
52 #include "content/common/notification_service.h" | 52 #include "content/public/browser/notification_service.h" |
53 #include "grit/chromium_strings.h" | 53 #include "grit/chromium_strings.h" |
54 #include "grit/generated_resources.h" | 54 #include "grit/generated_resources.h" |
55 #include "third_party/skia/include/core/SkBitmap.h" | 55 #include "third_party/skia/include/core/SkBitmap.h" |
56 | 56 |
57 using base::Time; | 57 using base::Time; |
58 using history::HistoryBackend; | 58 using history::HistoryBackend; |
59 | 59 |
60 namespace { | 60 namespace { |
61 | 61 |
62 static const char* kHistoryThreadName = "Chrome_HistoryThread"; | 62 static const char* kHistoryThreadName = "Chrome_HistoryThread"; |
(...skipping 27 matching lines...) Expand all Loading... |
90 message_loop_->PostTask( | 90 message_loop_->PostTask( |
91 FROM_HERE, | 91 FROM_HERE, |
92 base::Bind(&HistoryService::SetInMemoryBackend, history_service_.get(), | 92 base::Bind(&HistoryService::SetInMemoryBackend, history_service_.get(), |
93 backend_id, backend)); | 93 backend_id, backend)); |
94 } | 94 } |
95 | 95 |
96 virtual void BroadcastNotifications( | 96 virtual void BroadcastNotifications( |
97 int type, | 97 int type, |
98 history::HistoryDetails* details) OVERRIDE { | 98 history::HistoryDetails* details) OVERRIDE { |
99 // Send the notification on the history thread. | 99 // Send the notification on the history thread. |
100 if (NotificationService::current()) { | 100 if (content::NotificationService::current()) { |
101 content::Details<history::HistoryDetails> det(details); | 101 content::Details<history::HistoryDetails> det(details); |
102 NotificationService::current()->Notify(type, | 102 content::NotificationService::current()->Notify( |
103 content::Source<Profile>(profile_), | 103 type, content::Source<Profile>(profile_), det); |
104 det); | |
105 } | 104 } |
106 // Send the notification to the history service on the main thread. | 105 // Send the notification to the history service on the main thread. |
107 message_loop_->PostTask( | 106 message_loop_->PostTask( |
108 FROM_HERE, | 107 FROM_HERE, |
109 base::Bind(&HistoryService::BroadcastNotifications, | 108 base::Bind(&HistoryService::BroadcastNotifications, |
110 history_service_.get(), type, details)); | 109 history_service_.get(), type, details)); |
111 } | 110 } |
112 | 111 |
113 virtual void DBLoaded(int backend_id) OVERRIDE { | 112 virtual void DBLoaded(int backend_id) OVERRIDE { |
114 message_loop_->PostTask( | 113 message_loop_->PostTask( |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 | 784 |
786 // The source of all of our notifications is the profile. Note that this | 785 // The source of all of our notifications is the profile. Note that this |
787 // pointer is NULL in unit tests. | 786 // pointer is NULL in unit tests. |
788 content::Source<Profile> source(profile_); | 787 content::Source<Profile> source(profile_); |
789 | 788 |
790 // The details object just contains the pointer to the object that the | 789 // The details object just contains the pointer to the object that the |
791 // backend has allocated for us. The receiver of the notification will cast | 790 // backend has allocated for us. The receiver of the notification will cast |
792 // this to the proper type. | 791 // this to the proper type. |
793 content::Details<history::HistoryDetails> det(details_deleted); | 792 content::Details<history::HistoryDetails> det(details_deleted); |
794 | 793 |
795 NotificationService::current()->Notify(type, source, det); | 794 content::NotificationService::current()->Notify(type, source, det); |
796 } | 795 } |
797 | 796 |
798 void HistoryService::LoadBackendIfNecessary() { | 797 void HistoryService::LoadBackendIfNecessary() { |
799 if (!thread_ || history_backend_) | 798 if (!thread_ || history_backend_) |
800 return; // Failed to init, or already started loading. | 799 return; // Failed to init, or already started loading. |
801 | 800 |
802 ++current_backend_id_; | 801 ++current_backend_id_; |
803 scoped_refptr<HistoryBackend> backend( | 802 scoped_refptr<HistoryBackend> backend( |
804 new HistoryBackend(history_dir_, | 803 new HistoryBackend(history_dir_, |
805 current_backend_id_, | 804 current_backend_id_, |
806 new BackendDelegate(this, profile_), | 805 new BackendDelegate(this, profile_), |
807 bookmark_service_)); | 806 bookmark_service_)); |
808 history_backend_.swap(backend); | 807 history_backend_.swap(backend); |
809 | 808 |
810 // There may not be a profile when unit testing. | 809 // There may not be a profile when unit testing. |
811 std::string languages; | 810 std::string languages; |
812 if (profile_) { | 811 if (profile_) { |
813 PrefService* prefs = profile_->GetPrefs(); | 812 PrefService* prefs = profile_->GetPrefs(); |
814 languages = prefs->GetString(prefs::kAcceptLanguages); | 813 languages = prefs->GetString(prefs::kAcceptLanguages); |
815 } | 814 } |
816 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, languages, no_db_); | 815 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, languages, no_db_); |
817 } | 816 } |
818 | 817 |
819 void HistoryService::OnDBLoaded(int backend_id) { | 818 void HistoryService::OnDBLoaded(int backend_id) { |
820 if (!history_backend_ || current_backend_id_ != backend_id) { | 819 if (!history_backend_ || current_backend_id_ != backend_id) { |
821 VLOG(1) << "Message from obsolete backend"; | 820 VLOG(1) << "Message from obsolete backend"; |
822 return; | 821 return; |
823 } | 822 } |
824 backend_loaded_ = true; | 823 backend_loaded_ = true; |
825 NotificationService::current()->Notify( | 824 content::NotificationService::current()->Notify( |
826 chrome::NOTIFICATION_HISTORY_LOADED, | 825 chrome::NOTIFICATION_HISTORY_LOADED, |
827 content::Source<Profile>(profile_), | 826 content::Source<Profile>(profile_), |
828 content::Details<HistoryService>(this)); | 827 content::Details<HistoryService>(this)); |
829 if (thread_ && profile_) { | 828 if (thread_ && profile_) { |
830 // We don't want to force creation of TopSites. | 829 // We don't want to force creation of TopSites. |
831 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 830 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
832 if (ts) | 831 if (ts) |
833 ts->HistoryLoaded(); | 832 ts->HistoryLoaded(); |
834 } | 833 } |
835 } | 834 } |
836 | 835 |
837 void HistoryService::StartTopSitesMigration(int backend_id) { | 836 void HistoryService::StartTopSitesMigration(int backend_id) { |
838 if (!history_backend_ || current_backend_id_ != backend_id) { | 837 if (!history_backend_ || current_backend_id_ != backend_id) { |
839 VLOG(1) << "Message from obsolete backend"; | 838 VLOG(1) << "Message from obsolete backend"; |
840 return; | 839 return; |
841 } | 840 } |
842 needs_top_sites_migration_ = true; | 841 needs_top_sites_migration_ = true; |
843 if (thread_ && profile_) { | 842 if (thread_ && profile_) { |
844 // We don't want to force creation of TopSites. | 843 // We don't want to force creation of TopSites. |
845 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 844 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
846 if (ts) | 845 if (ts) |
847 ts->MigrateFromHistory(); | 846 ts->MigrateFromHistory(); |
848 } | 847 } |
849 } | 848 } |
850 | 849 |
851 void HistoryService::OnTopSitesReady() { | 850 void HistoryService::OnTopSitesReady() { |
852 ScheduleAndForget(PRIORITY_NORMAL, | 851 ScheduleAndForget(PRIORITY_NORMAL, |
853 &HistoryBackend::MigrateThumbnailsDatabase); | 852 &HistoryBackend::MigrateThumbnailsDatabase); |
854 } | 853 } |
OLD | NEW |