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 17 matching lines...) Expand all Loading... |
28 #include "base/command_line.h" | 28 #include "base/command_line.h" |
29 #include "base/memory/ref_counted.h" | 29 #include "base/memory/ref_counted.h" |
30 #include "base/message_loop.h" | 30 #include "base/message_loop.h" |
31 #include "base/path_service.h" | 31 #include "base/path_service.h" |
32 #include "base/string_util.h" | 32 #include "base/string_util.h" |
33 #include "base/threading/thread.h" | 33 #include "base/threading/thread.h" |
34 #include "chrome/browser/autocomplete/history_url_provider.h" | 34 #include "chrome/browser/autocomplete/history_url_provider.h" |
35 #include "chrome/browser/bookmarks/bookmark_model.h" | 35 #include "chrome/browser/bookmarks/bookmark_model.h" |
36 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 36 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
37 #include "chrome/browser/browser_process.h" | 37 #include "chrome/browser/browser_process.h" |
| 38 #include "chrome/browser/history/download_persistent_store_info.h" |
38 #include "chrome/browser/history/history_backend.h" | 39 #include "chrome/browser/history/history_backend.h" |
39 #include "chrome/browser/history/history_notifications.h" | 40 #include "chrome/browser/history/history_notifications.h" |
40 #include "chrome/browser/history/history_types.h" | 41 #include "chrome/browser/history/history_types.h" |
41 #include "chrome/browser/history/in_memory_database.h" | 42 #include "chrome/browser/history/in_memory_database.h" |
42 #include "chrome/browser/history/in_memory_history_backend.h" | 43 #include "chrome/browser/history/in_memory_history_backend.h" |
43 #include "chrome/browser/history/in_memory_url_index.h" | 44 #include "chrome/browser/history/in_memory_url_index.h" |
44 #include "chrome/browser/history/top_sites.h" | 45 #include "chrome/browser/history/top_sites.h" |
45 #include "chrome/browser/history/visit_database.h" | 46 #include "chrome/browser/history/visit_database.h" |
46 #include "chrome/browser/history/visit_filter.h" | 47 #include "chrome/browser/history/visit_filter.h" |
47 #include "chrome/browser/prefs/pref_service.h" | 48 #include "chrome/browser/prefs/pref_service.h" |
48 #include "chrome/browser/profiles/profile.h" | 49 #include "chrome/browser/profiles/profile.h" |
49 #include "chrome/browser/ui/profile_error_dialog.h" | 50 #include "chrome/browser/ui/profile_error_dialog.h" |
50 #include "chrome/browser/visitedlink/visitedlink_master.h" | 51 #include "chrome/browser/visitedlink/visitedlink_master.h" |
51 #include "chrome/common/chrome_constants.h" | 52 #include "chrome/common/chrome_constants.h" |
52 #include "chrome/common/chrome_notification_types.h" | 53 #include "chrome/common/chrome_notification_types.h" |
53 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
54 #include "chrome/common/pref_names.h" | 55 #include "chrome/common/pref_names.h" |
55 #include "chrome/common/thumbnail_score.h" | 56 #include "chrome/common/thumbnail_score.h" |
56 #include "chrome/common/url_constants.h" | 57 #include "chrome/common/url_constants.h" |
57 #include "content/public/browser/browser_thread.h" | 58 #include "content/public/browser/browser_thread.h" |
58 #include "content/public/browser/download_persistent_store_info.h" | |
59 #include "content/public/browser/notification_service.h" | 59 #include "content/public/browser/notification_service.h" |
60 #include "grit/chromium_strings.h" | 60 #include "grit/chromium_strings.h" |
61 #include "grit/generated_resources.h" | 61 #include "grit/generated_resources.h" |
62 #include "third_party/skia/include/core/SkBitmap.h" | 62 #include "third_party/skia/include/core/SkBitmap.h" |
63 | 63 |
64 using base::Time; | 64 using base::Time; |
65 using history::HistoryBackend; | 65 using history::HistoryBackend; |
66 | 66 |
67 namespace { | 67 namespace { |
68 | 68 |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 CancelableRequestConsumerBase* consumer, | 583 CancelableRequestConsumerBase* consumer, |
584 const QueryURLCallback& callback) { | 584 const QueryURLCallback& callback) { |
585 return Schedule(PRIORITY_UI, &HistoryBackend::QueryURL, consumer, | 585 return Schedule(PRIORITY_UI, &HistoryBackend::QueryURL, consumer, |
586 new history::QueryURLRequest(callback), url, want_visits); | 586 new history::QueryURLRequest(callback), url, want_visits); |
587 } | 587 } |
588 | 588 |
589 // Downloads ------------------------------------------------------------------- | 589 // Downloads ------------------------------------------------------------------- |
590 | 590 |
591 // Handle creation of a download by creating an entry in the history service's | 591 // Handle creation of a download by creating an entry in the history service's |
592 // 'downloads' table. | 592 // 'downloads' table. |
593 HistoryService::Handle HistoryService::CreateDownload( | 593 void HistoryService::CreateDownload( |
594 int32 id, | 594 const DownloadPersistentStoreInfo& info, |
595 const content::DownloadPersistentStoreInfo& create_info, | |
596 CancelableRequestConsumerBase* consumer, | |
597 const HistoryService::DownloadCreateCallback& callback) { | 595 const HistoryService::DownloadCreateCallback& callback) { |
598 return Schedule(PRIORITY_NORMAL, &HistoryBackend::CreateDownload, consumer, | 596 LoadBackendIfNecessary(); |
599 new history::DownloadCreateRequest(callback), id, | 597 ScheduleTask(PRIORITY_NORMAL, base::Bind( |
600 create_info); | 598 &HistoryBackend::CreateDownload, history_backend_.get(), info, callback)); |
| 599 } |
| 600 |
| 601 void HistoryService::GetVisibleVisitCountToHostSimple( |
| 602 const GURL& url, |
| 603 const GetVisibleVisitCountToHostSimpleCallback& callback) { |
| 604 LoadBackendIfNecessary(); |
| 605 ScheduleTask(PRIORITY_NORMAL, base::Bind( |
| 606 &HistoryBackend::GetVisibleVisitCountToHostSimple, history_backend_.get(), |
| 607 url, callback)); |
601 } | 608 } |
602 | 609 |
603 HistoryService::Handle HistoryService::GetNextDownloadId( | 610 HistoryService::Handle HistoryService::GetNextDownloadId( |
604 CancelableRequestConsumerBase* consumer, | 611 CancelableRequestConsumerBase* consumer, |
605 const DownloadNextIdCallback& callback) { | 612 const DownloadNextIdCallback& callback) { |
606 return Schedule(PRIORITY_NORMAL, &HistoryBackend::GetNextDownloadId, consumer, | 613 return Schedule(PRIORITY_NORMAL, &HistoryBackend::GetNextDownloadId, consumer, |
607 new history::DownloadNextIdRequest(callback)); | 614 new history::DownloadNextIdRequest(callback)); |
608 } | 615 } |
609 | 616 |
610 // Handle queries for a list of all downloads in the history database's | 617 // Handle queries for a list of all downloads in the history database's |
611 // 'downloads' table. | 618 // 'downloads' table. |
612 HistoryService::Handle HistoryService::QueryDownloads( | 619 void HistoryService::QueryDownloads(const DownloadQueryCallback& callback) { |
613 CancelableRequestConsumerBase* consumer, | 620 LoadBackendIfNecessary(); |
614 const DownloadQueryCallback& callback) { | 621 ScheduleTask(PRIORITY_NORMAL, base::Bind( |
615 return Schedule(PRIORITY_NORMAL, &HistoryBackend::QueryDownloads, consumer, | 622 &HistoryBackend::QueryDownloads, history_backend_.get(), callback)); |
616 new history::DownloadQueryRequest(callback)); | |
617 } | 623 } |
618 | 624 |
619 // Changes all IN_PROGRESS in the database entries to CANCELED. | 625 // Changes all IN_PROGRESS in the database entries to CANCELED. |
620 // IN_PROGRESS entries are the corrupted entries, not updated by next function | 626 // IN_PROGRESS entries are the corrupted entries, not updated by next function |
621 // because of the crash or some other extremal exit. | 627 // because of the crash or some other extremal exit. |
622 void HistoryService::CleanUpInProgressEntries() { | 628 void HistoryService::CleanUpInProgressEntries() { |
623 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::CleanUpInProgressEntries); | 629 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::CleanUpInProgressEntries); |
624 } | 630 } |
625 | 631 |
626 // Handle updates for a particular download. This is a 'fire and forget' | 632 // Handle updates for a particular download. This is a 'fire and forget' |
627 // operation, so we don't need to be called back. | 633 // operation, so we don't need to be called back. |
628 void HistoryService::UpdateDownload( | 634 void HistoryService::UpdateDownload( |
629 const content::DownloadPersistentStoreInfo& data) { | 635 const DownloadPersistentStoreInfo& data) { |
630 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::UpdateDownload, data); | 636 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::UpdateDownload, data); |
631 } | 637 } |
632 | 638 |
633 void HistoryService::UpdateDownloadPath(const FilePath& path, | 639 void HistoryService::RemoveDownloads(const std::set<int64>& handles) { |
634 int64 db_handle) { | |
635 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::UpdateDownloadPath, | |
636 path, db_handle); | |
637 } | |
638 | |
639 void HistoryService::RemoveDownload(int64 db_handle) { | |
640 ScheduleAndForget(PRIORITY_NORMAL, | 640 ScheduleAndForget(PRIORITY_NORMAL, |
641 &HistoryBackend::RemoveDownload, db_handle); | 641 &HistoryBackend::RemoveDownloads, handles); |
642 } | |
643 | |
644 void HistoryService::RemoveDownloadsBetween(Time remove_begin, | |
645 Time remove_end) { | |
646 ScheduleAndForget(PRIORITY_NORMAL, | |
647 &HistoryBackend::RemoveDownloadsBetween, | |
648 remove_begin, | |
649 remove_end); | |
650 } | 642 } |
651 | 643 |
652 HistoryService::Handle HistoryService::QueryHistory( | 644 HistoryService::Handle HistoryService::QueryHistory( |
653 const string16& text_query, | 645 const string16& text_query, |
654 const history::QueryOptions& options, | 646 const history::QueryOptions& options, |
655 CancelableRequestConsumerBase* consumer, | 647 CancelableRequestConsumerBase* consumer, |
656 const QueryHistoryCallback& callback) { | 648 const QueryHistoryCallback& callback) { |
657 return Schedule(PRIORITY_UI, &HistoryBackend::QueryHistory, consumer, | 649 return Schedule(PRIORITY_UI, &HistoryBackend::QueryHistory, consumer, |
658 new history::QueryHistoryRequest(callback), | 650 new history::QueryHistoryRequest(callback), |
659 text_query, options); | 651 text_query, options); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 void HistoryService::RemoveVisitDatabaseObserver( | 952 void HistoryService::RemoveVisitDatabaseObserver( |
961 history::VisitDatabaseObserver* observer) { | 953 history::VisitDatabaseObserver* observer) { |
962 visit_database_observers_->RemoveObserver(observer); | 954 visit_database_observers_->RemoveObserver(observer); |
963 } | 955 } |
964 | 956 |
965 void HistoryService::NotifyVisitDBObserversOnAddVisit( | 957 void HistoryService::NotifyVisitDBObserversOnAddVisit( |
966 const history::BriefVisitInfo& info) { | 958 const history::BriefVisitInfo& info) { |
967 visit_database_observers_->Notify( | 959 visit_database_observers_->Notify( |
968 &history::VisitDatabaseObserver::OnAddVisit, info); | 960 &history::VisitDatabaseObserver::OnAddVisit, info); |
969 } | 961 } |
OLD | NEW |