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 26 matching lines...) Expand all Loading... |
37 #include "chrome/browser/history/history_notifications.h" | 37 #include "chrome/browser/history/history_notifications.h" |
38 #include "chrome/browser/history/history_types.h" | 38 #include "chrome/browser/history/history_types.h" |
39 #include "chrome/browser/history/in_memory_database.h" | 39 #include "chrome/browser/history/in_memory_database.h" |
40 #include "chrome/browser/history/in_memory_history_backend.h" | 40 #include "chrome/browser/history/in_memory_history_backend.h" |
41 #include "chrome/browser/history/top_sites.h" | 41 #include "chrome/browser/history/top_sites.h" |
42 #include "chrome/browser/prefs/pref_service.h" | 42 #include "chrome/browser/prefs/pref_service.h" |
43 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
44 #include "chrome/browser/ui/profile_error_dialog.h" | 44 #include "chrome/browser/ui/profile_error_dialog.h" |
45 #include "chrome/browser/visitedlink/visitedlink_master.h" | 45 #include "chrome/browser/visitedlink/visitedlink_master.h" |
46 #include "chrome/common/chrome_constants.h" | 46 #include "chrome/common/chrome_constants.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" |
50 #include "content/browser/browser_thread.h" | 51 #include "content/browser/browser_thread.h" |
51 #include "content/common/notification_service.h" | 52 #include "content/common/notification_service.h" |
52 #include "grit/chromium_strings.h" | 53 #include "grit/chromium_strings.h" |
53 #include "grit/generated_resources.h" | 54 #include "grit/generated_resources.h" |
54 #include "third_party/skia/include/core/SkBitmap.h" | 55 #include "third_party/skia/include/core/SkBitmap.h" |
55 | 56 |
56 using base::Time; | 57 using base::Time; |
(...skipping 23 matching lines...) Expand all Loading... |
80 } | 81 } |
81 | 82 |
82 virtual void SetInMemoryBackend( | 83 virtual void SetInMemoryBackend( |
83 history::InMemoryHistoryBackend* backend) OVERRIDE { | 84 history::InMemoryHistoryBackend* backend) OVERRIDE { |
84 // Send the backend to the history service on the main thread. | 85 // Send the backend to the history service on the main thread. |
85 message_loop_->PostTask(FROM_HERE, NewRunnableMethod(history_service_.get(), | 86 message_loop_->PostTask(FROM_HERE, NewRunnableMethod(history_service_.get(), |
86 &HistoryService::SetInMemoryBackend, backend)); | 87 &HistoryService::SetInMemoryBackend, backend)); |
87 } | 88 } |
88 | 89 |
89 virtual void BroadcastNotifications( | 90 virtual void BroadcastNotifications( |
90 NotificationType type, | 91 int type, |
91 history::HistoryDetails* details) OVERRIDE { | 92 history::HistoryDetails* details) OVERRIDE { |
92 // Send the notification on the history thread. | 93 // Send the notification on the history thread. |
93 if (NotificationService::current()) { | 94 if (NotificationService::current()) { |
94 Details<history::HistoryDetails> det(details); | 95 Details<history::HistoryDetails> det(details); |
95 NotificationService::current()->Notify(type, | 96 NotificationService::current()->Notify(type, |
96 NotificationService::AllSources(), | 97 NotificationService::AllSources(), |
97 det); | 98 det); |
98 } | 99 } |
99 // Send the notification to the history service on the main thread. | 100 // Send the notification to the history service on the main thread. |
100 message_loop_->PostTask(FROM_HERE, NewRunnableMethod(history_service_.get(), | 101 message_loop_->PostTask(FROM_HERE, NewRunnableMethod(history_service_.get(), |
(...skipping 28 matching lines...) Expand all Loading... |
129 } | 130 } |
130 | 131 |
131 HistoryService::HistoryService(Profile* profile) | 132 HistoryService::HistoryService(Profile* profile) |
132 : thread_(new base::Thread(kHistoryThreadName)), | 133 : thread_(new base::Thread(kHistoryThreadName)), |
133 profile_(profile), | 134 profile_(profile), |
134 backend_loaded_(false), | 135 backend_loaded_(false), |
135 bookmark_service_(NULL), | 136 bookmark_service_(NULL), |
136 no_db_(false), | 137 no_db_(false), |
137 needs_top_sites_migration_(false) { | 138 needs_top_sites_migration_(false) { |
138 DCHECK(profile_); | 139 DCHECK(profile_); |
139 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, | 140 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
140 Source<Profile>(profile_)); | 141 Source<Profile>(profile_)); |
141 registrar_.Add(this, NotificationType::TEMPLATE_URL_REMOVED, | 142 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_REMOVED, |
142 Source<Profile>(profile_)); | 143 Source<Profile>(profile_)); |
143 } | 144 } |
144 | 145 |
145 HistoryService::~HistoryService() { | 146 HistoryService::~HistoryService() { |
146 // Shutdown the backend. This does nothing if Cleanup was already invoked. | 147 // Shutdown the backend. This does nothing if Cleanup was already invoked. |
147 Cleanup(); | 148 Cleanup(); |
148 } | 149 } |
149 | 150 |
150 bool HistoryService::BackendLoaded() { | 151 bool HistoryService::BackendLoaded() { |
151 // NOTE: We start the backend loading even though it completes asynchronously | 152 // NOTE: We start the backend loading even though it completes asynchronously |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 int result_count, | 612 int result_count, |
612 int days_back, | 613 int days_back, |
613 CancelableRequestConsumerBase* consumer, | 614 CancelableRequestConsumerBase* consumer, |
614 QueryMostVisitedURLsCallback* callback) { | 615 QueryMostVisitedURLsCallback* callback) { |
615 return Schedule(PRIORITY_NORMAL, &HistoryBackend::QueryMostVisitedURLs, | 616 return Schedule(PRIORITY_NORMAL, &HistoryBackend::QueryMostVisitedURLs, |
616 consumer, | 617 consumer, |
617 new history::QueryMostVisitedURLsRequest(callback), | 618 new history::QueryMostVisitedURLsRequest(callback), |
618 result_count, days_back); | 619 result_count, days_back); |
619 } | 620 } |
620 | 621 |
621 void HistoryService::Observe(NotificationType type, | 622 void HistoryService::Observe(int type, |
622 const NotificationSource& source, | 623 const NotificationSource& source, |
623 const NotificationDetails& details) { | 624 const NotificationDetails& details) { |
624 if (!thread_) | 625 if (!thread_) |
625 return; | 626 return; |
626 | 627 |
627 switch (type.value) { | 628 switch (type) { |
628 case NotificationType::HISTORY_URLS_DELETED: { | 629 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: { |
629 // Update the visited link system for deleted URLs. We will update the | 630 // Update the visited link system for deleted URLs. We will update the |
630 // visited link system for added URLs as soon as we get the add | 631 // visited link system for added URLs as soon as we get the add |
631 // notification (we don't have to wait for the backend, which allows us to | 632 // notification (we don't have to wait for the backend, which allows us to |
632 // be faster to update the state). | 633 // be faster to update the state). |
633 // | 634 // |
634 // For deleted URLs, we don't typically know what will be deleted since | 635 // For deleted URLs, we don't typically know what will be deleted since |
635 // delete notifications are by time. We would also like to be more | 636 // delete notifications are by time. We would also like to be more |
636 // respectful of privacy and never tell the user something is gone when it | 637 // respectful of privacy and never tell the user something is gone when it |
637 // isn't. Therefore, we update the delete URLs after the fact. | 638 // isn't. Therefore, we update the delete URLs after the fact. |
638 if (!profile_) | 639 if (!profile_) |
639 return; // No profile, probably unit testing. | 640 return; // No profile, probably unit testing. |
640 Details<history::URLsDeletedDetails> deleted_details(details); | 641 Details<history::URLsDeletedDetails> deleted_details(details); |
641 VisitedLinkMaster* visited_links = profile_->GetVisitedLinkMaster(); | 642 VisitedLinkMaster* visited_links = profile_->GetVisitedLinkMaster(); |
642 if (!visited_links) | 643 if (!visited_links) |
643 return; // Nobody to update. | 644 return; // Nobody to update. |
644 if (deleted_details->all_history) | 645 if (deleted_details->all_history) |
645 visited_links->DeleteAllURLs(); | 646 visited_links->DeleteAllURLs(); |
646 else // Delete individual ones. | 647 else // Delete individual ones. |
647 visited_links->DeleteURLs(deleted_details->urls); | 648 visited_links->DeleteURLs(deleted_details->urls); |
648 break; | 649 break; |
649 } | 650 } |
650 | 651 |
651 case NotificationType::TEMPLATE_URL_REMOVED: | 652 case chrome::NOTIFICATION_TEMPLATE_URL_REMOVED: |
652 DeleteAllSearchTermsForKeyword(*(Details<TemplateURLID>(details).ptr())); | 653 DeleteAllSearchTermsForKeyword(*(Details<TemplateURLID>(details).ptr())); |
653 break; | 654 break; |
654 | 655 |
655 default: | 656 default: |
656 NOTREACHED(); | 657 NOTREACHED(); |
657 } | 658 } |
658 } | 659 } |
659 | 660 |
660 bool HistoryService::Init(const FilePath& history_dir, | 661 bool HistoryService::Init(const FilePath& history_dir, |
661 BookmarkService* bookmark_service, | 662 BookmarkService* bookmark_service, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 CancelableRequestConsumerBase* consumer, | 736 CancelableRequestConsumerBase* consumer, |
736 ExpireHistoryCallback* callback) { | 737 ExpireHistoryCallback* callback) { |
737 | 738 |
738 // We will update the visited links when we observe the delete notifications. | 739 // We will update the visited links when we observe the delete notifications. |
739 Schedule(PRIORITY_UI, &HistoryBackend::ExpireHistoryBetween, consumer, | 740 Schedule(PRIORITY_UI, &HistoryBackend::ExpireHistoryBetween, consumer, |
740 new history::ExpireHistoryRequest(callback), | 741 new history::ExpireHistoryRequest(callback), |
741 restrict_urls, begin_time, end_time); | 742 restrict_urls, begin_time, end_time); |
742 } | 743 } |
743 | 744 |
744 void HistoryService::BroadcastNotifications( | 745 void HistoryService::BroadcastNotifications( |
745 NotificationType type, | 746 int type, |
746 history::HistoryDetails* details_deleted) { | 747 history::HistoryDetails* details_deleted) { |
747 // We take ownership of the passed-in pointer and delete it. It was made for | 748 // We take ownership of the passed-in pointer and delete it. It was made for |
748 // us on another thread, so the caller doesn't know when we will handle it. | 749 // us on another thread, so the caller doesn't know when we will handle it. |
749 scoped_ptr<history::HistoryDetails> details(details_deleted); | 750 scoped_ptr<history::HistoryDetails> details(details_deleted); |
750 // TODO(evanm): this is currently necessitated by generate_profile, which | 751 // TODO(evanm): this is currently necessitated by generate_profile, which |
751 // runs without a browser process. generate_profile should really create | 752 // runs without a browser process. generate_profile should really create |
752 // a browser process, at which point this check can then be nuked. | 753 // a browser process, at which point this check can then be nuked. |
753 if (!g_browser_process) | 754 if (!g_browser_process) |
754 return; | 755 return; |
755 | 756 |
(...skipping 26 matching lines...) Expand all Loading... |
782 std::string languages; | 783 std::string languages; |
783 if (profile_) { | 784 if (profile_) { |
784 PrefService* prefs = profile_->GetPrefs(); | 785 PrefService* prefs = profile_->GetPrefs(); |
785 languages = prefs->GetString(prefs::kAcceptLanguages); | 786 languages = prefs->GetString(prefs::kAcceptLanguages); |
786 } | 787 } |
787 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, languages, no_db_); | 788 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, languages, no_db_); |
788 } | 789 } |
789 | 790 |
790 void HistoryService::OnDBLoaded() { | 791 void HistoryService::OnDBLoaded() { |
791 backend_loaded_ = true; | 792 backend_loaded_ = true; |
792 NotificationService::current()->Notify(NotificationType::HISTORY_LOADED, | 793 NotificationService::current()->Notify(chrome::NOTIFICATION_HISTORY_LOADED, |
793 Source<Profile>(profile_), | 794 Source<Profile>(profile_), |
794 Details<HistoryService>(this)); | 795 Details<HistoryService>(this)); |
795 if (thread_ && profile_) { | 796 if (thread_ && profile_) { |
796 // We don't want to force creation of TopSites. | 797 // We don't want to force creation of TopSites. |
797 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 798 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
798 if (ts) | 799 if (ts) |
799 ts->HistoryLoaded(); | 800 ts->HistoryLoaded(); |
800 } | 801 } |
801 } | 802 } |
802 | 803 |
803 void HistoryService::StartTopSitesMigration() { | 804 void HistoryService::StartTopSitesMigration() { |
804 needs_top_sites_migration_ = true; | 805 needs_top_sites_migration_ = true; |
805 if (thread_ && profile_) { | 806 if (thread_ && profile_) { |
806 // We don't want to force creation of TopSites. | 807 // We don't want to force creation of TopSites. |
807 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); | 808 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); |
808 if (ts) | 809 if (ts) |
809 ts->MigrateFromHistory(); | 810 ts->MigrateFromHistory(); |
810 } | 811 } |
811 } | 812 } |
812 | 813 |
813 void HistoryService::OnTopSitesReady() { | 814 void HistoryService::OnTopSitesReady() { |
814 ScheduleAndForget(PRIORITY_NORMAL, | 815 ScheduleAndForget(PRIORITY_NORMAL, |
815 &HistoryBackend::MigrateThumbnailsDatabase); | 816 &HistoryBackend::MigrateThumbnailsDatabase); |
816 } | 817 } |
OLD | NEW |