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 #ifndef CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ |
6 #define CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ | 6 #define CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 class VisitedLinkMaster; | 57 class VisitedLinkMaster; |
58 } | 58 } |
59 | 59 |
60 namespace history { | 60 namespace history { |
61 | 61 |
62 class HistoryBackend; | 62 class HistoryBackend; |
63 class HistoryClient; | 63 class HistoryClient; |
64 class HistoryDatabase; | 64 class HistoryDatabase; |
65 class HistoryDBTask; | 65 class HistoryDBTask; |
66 class HistoryQueryTest; | 66 class HistoryQueryTest; |
67 class HistoryServiceObserver; | |
68 class HistoryTest; | 67 class HistoryTest; |
69 class InMemoryHistoryBackend; | 68 class InMemoryHistoryBackend; |
70 class InMemoryURLIndex; | 69 class InMemoryURLIndex; |
71 class InMemoryURLIndexTest; | 70 class InMemoryURLIndexTest; |
72 class URLDatabase; | 71 class URLDatabase; |
73 class VisitDatabaseObserver; | |
74 class VisitFilter; | 72 class VisitFilter; |
75 struct DownloadRow; | 73 struct DownloadRow; |
76 struct HistoryAddPageArgs; | 74 struct HistoryAddPageArgs; |
77 struct HistoryDetails; | 75 struct HistoryDetails; |
78 struct KeywordSearchTermVisit; | 76 struct KeywordSearchTermVisit; |
79 | 77 |
80 } // namespace history | 78 } // namespace history |
81 | 79 |
82 // The history service records page titles, and visit times, as well as | 80 // The history service records page titles, and visit times, as well as |
83 // (eventually) information about autocomplete. | 81 // (eventually) information about autocomplete. |
84 // | 82 // |
85 // This service is thread safe. Each request callback is invoked in the | 83 // This service is thread safe. Each request callback is invoked in the |
86 // thread that made the request. | 84 // thread that made the request. |
87 class HistoryService : public content::NotificationObserver, | 85 class HistoryService : public content::NotificationObserver, |
88 public syncer::SyncableService, | 86 public syncer::SyncableService, |
89 public KeyedService, | 87 public KeyedService, |
90 public visitedlink::VisitedLinkDelegate { | 88 public visitedlink::VisitedLinkDelegate { |
91 public: | 89 public: |
92 // Miscellaneous commonly-used types. | 90 // Miscellaneous commonly-used types. |
93 typedef std::vector<PageUsageData*> PageUsageDataList; | 91 typedef std::vector<PageUsageData*> PageUsageDataList; |
94 | 92 |
| 93 class Observer { |
| 94 public: |
| 95 Observer() {} |
| 96 virtual ~Observer() {} |
| 97 |
| 98 // Called when user visits an URL. |
| 99 // |
| 100 // The |row| ID will be set to the value that is currently in effect in the |
| 101 // main history database. |redirects| is the list of redirects leading up to |
| 102 // the URL. If we have a redirect chain A -> B -> C and user is visiting C, |
| 103 // then |redirects[0]=B| and |redirects[1]=A|. If there are no redirects, |
| 104 // |redirects| is an empty vector. |
| 105 virtual void OnURLVisited(ui::PageTransition transition, |
| 106 const history::URLRow& row, |
| 107 const history::RedirectList& redirects, |
| 108 base::Time visit_time) {} |
| 109 |
| 110 // Called on changes to the VisitDatabase. |
| 111 virtual void OnAddVisit(const history::BriefVisitInfo& info) {} |
| 112 }; |
| 113 |
95 // Must call Init after construction. The |history::HistoryClient| object | 114 // Must call Init after construction. The |history::HistoryClient| object |
96 // must be valid for the whole lifetime of |HistoryService|. | 115 // must be valid for the whole lifetime of |HistoryService|. |
97 explicit HistoryService(history::HistoryClient* client, Profile* profile); | 116 explicit HistoryService(history::HistoryClient* client, Profile* profile); |
98 // The empty constructor is provided only for testing. | 117 // The empty constructor is provided only for testing. |
99 HistoryService(); | 118 HistoryService(); |
100 | 119 |
101 virtual ~HistoryService(); | 120 virtual ~HistoryService(); |
102 | 121 |
103 // Initializes the history service, returning true on success. On false, do | 122 // Initializes the history service, returning true on success. On false, do |
104 // not call any other functions. The given directory will be used for storing | 123 // not call any other functions. The given directory will be used for storing |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // Deletes all URL and search term entries matching the given |term| and | 443 // Deletes all URL and search term entries matching the given |term| and |
425 // |keyword_id|. | 444 // |keyword_id|. |
426 void DeleteMatchingURLsForKeyword(history::KeywordID keyword_id, | 445 void DeleteMatchingURLsForKeyword(history::KeywordID keyword_id, |
427 const base::string16& term); | 446 const base::string16& term); |
428 | 447 |
429 // Bookmarks ----------------------------------------------------------------- | 448 // Bookmarks ----------------------------------------------------------------- |
430 | 449 |
431 // Notification that a URL is no longer bookmarked. | 450 // Notification that a URL is no longer bookmarked. |
432 void URLsNoLongerBookmarked(const std::set<GURL>& urls); | 451 void URLsNoLongerBookmarked(const std::set<GURL>& urls); |
433 | 452 |
434 // HistoryServiceObserver ---------------------------------------------------- | 453 // Observers ----------------------------------------------------------------- |
435 | 454 |
436 // Adds/Removes an HistoryServiceObserver. | 455 // Adds/Removes an Observer. |
437 void AddHistoryServiceObserver(history::HistoryServiceObserver* observer); | 456 void AddObserver(Observer* observer); |
438 void RemoveHistoryServiceObserver(history::HistoryServiceObserver* observer); | 457 void RemoveObserver(Observer* observer); |
439 | 458 |
440 // Generic Stuff ------------------------------------------------------------- | 459 // Generic Stuff ------------------------------------------------------------- |
441 | 460 |
442 // Schedules a HistoryDBTask for running on the history backend thread. See | 461 // Schedules a HistoryDBTask for running on the history backend thread. See |
443 // HistoryDBTask for details on what this does. Takes ownership of |task|. | 462 // HistoryDBTask for details on what this does. Takes ownership of |task|. |
444 virtual void ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, | 463 virtual void ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, |
445 base::CancelableTaskTracker* tracker); | 464 base::CancelableTaskTracker* tracker); |
446 | 465 |
447 // Adds or removes observers for the VisitDatabase. | |
448 void AddVisitDatabaseObserver(history::VisitDatabaseObserver* observer); | |
449 void RemoveVisitDatabaseObserver(history::VisitDatabaseObserver* observer); | |
450 | |
451 void NotifyVisitDBObserversOnAddVisit(const history::BriefVisitInfo& info); | |
452 | |
453 // This callback is invoked when favicon change for urls. | 466 // This callback is invoked when favicon change for urls. |
454 typedef base::Callback<void(const std::set<GURL>&)> OnFaviconChangedCallback; | 467 typedef base::Callback<void(const std::set<GURL>&)> OnFaviconChangedCallback; |
455 | 468 |
456 // Add a callback to the list. The callback will remain registered until the | 469 // Add a callback to the list. The callback will remain registered until the |
457 // returned Subscription is destroyed. This must occurs before HistoryService | 470 // returned Subscription is destroyed. This must occurs before HistoryService |
458 // is destroyed. | 471 // is destroyed. |
459 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription> | 472 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription> |
460 AddFaviconChangedCallback(const OnFaviconChangedCallback& callback) | 473 AddFaviconChangedCallback(const OnFaviconChangedCallback& callback) |
461 WARN_UNUSED_RESULT; | 474 WARN_UNUSED_RESULT; |
462 | 475 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 | 602 |
590 // Notification from the backend that it has finished loading. Sends | 603 // Notification from the backend that it has finished loading. Sends |
591 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. | 604 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. |
592 void OnDBLoaded(); | 605 void OnDBLoaded(); |
593 | 606 |
594 // Helper function for getting URL information. | 607 // Helper function for getting URL information. |
595 // Reads a URLRow from in-memory database. Returns false if database is not | 608 // Reads a URLRow from in-memory database. Returns false if database is not |
596 // available or the URL does not exist. | 609 // available or the URL does not exist. |
597 bool GetRowForURL(const GURL& url, history::URLRow* url_row); | 610 bool GetRowForURL(const GURL& url, history::URLRow* url_row); |
598 | 611 |
599 // HistoryServiceObserver ---------------------------------------------------- | 612 // Observers ----------------------------------------------------------------- |
600 | 613 |
601 // Notify all HistoryServiceObservers registered that user is visiting a URL. | 614 // Notify all Observers registered that user is visiting a URL. |
602 // The |row| ID will be set to the value that is currently in effect in the | 615 // The |row| ID will be set to the value that is currently in effect in the |
603 // main history database. |redirects| is the list of redirects leading up to | 616 // main history database. |redirects| is the list of redirects leading up to |
604 // the URL. If we have a redirect chain A -> B -> C and user is visiting C, | 617 // the URL. If we have a redirect chain A -> B -> C and user is visiting C, |
605 // then |redirects[0]=B| and |redirects[1]=A|. If there are no redirects, | 618 // then |redirects[0]=B| and |redirects[1]=A|. If there are no redirects, |
606 // |redirects| is an empty vector. | 619 // |redirects| is an empty vector. |
607 void NotifyURLVisited(ui::PageTransition transition, | 620 void NotifyURLVisited(ui::PageTransition transition, |
608 const history::URLRow& row, | 621 const history::URLRow& row, |
609 const history::RedirectList& redirects, | 622 const history::RedirectList& redirects, |
610 base::Time visit_time); | 623 base::Time visit_time); |
611 | 624 |
| 625 // Notify all Observers registered that the VisitDatabase was changed. |
| 626 void NotifyAddVisit(const history::BriefVisitInfo& info); |
| 627 |
612 // Favicon ------------------------------------------------------------------- | 628 // Favicon ------------------------------------------------------------------- |
613 | 629 |
614 // These favicon methods are exposed to the FaviconService. Instead of calling | 630 // These favicon methods are exposed to the FaviconService. Instead of calling |
615 // these methods directly you should call the respective method on the | 631 // these methods directly you should call the respective method on the |
616 // FaviconService. | 632 // FaviconService. |
617 | 633 |
618 // Used by FaviconService to get the favicon bitmaps from the history backend | 634 // Used by FaviconService to get the favicon bitmaps from the history backend |
619 // whose edge sizes most closely match |desired_sizes| for |icon_types|. If | 635 // whose edge sizes most closely match |desired_sizes| for |icon_types|. If |
620 // |desired_sizes| has a '0' entry, the largest favicon bitmap for | 636 // |desired_sizes| has a '0' entry, the largest favicon bitmap for |
621 // |icon_types| is returned. The returned FaviconBitmapResults will have at | 637 // |icon_types| is returned. The returned FaviconBitmapResults will have at |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 | 902 |
887 // Cached values from Init(), used whenever we need to reload the backend. | 903 // Cached values from Init(), used whenever we need to reload the backend. |
888 base::FilePath history_dir_; | 904 base::FilePath history_dir_; |
889 bool no_db_; | 905 bool no_db_; |
890 | 906 |
891 // The index used for quick history lookups. | 907 // The index used for quick history lookups. |
892 // TODO(mrossetti): Move in_memory_url_index out of history_service. | 908 // TODO(mrossetti): Move in_memory_url_index out of history_service. |
893 // See http://crbug.com/138321 | 909 // See http://crbug.com/138321 |
894 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 910 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
895 | 911 |
896 ObserverList<history::HistoryServiceObserver> history_service_observers_; | 912 ObserverList<Observer> observers_; |
897 ObserverList<history::VisitDatabaseObserver> visit_database_observers_; | |
898 | |
899 base::CallbackList<void(const std::set<GURL>&)> | 913 base::CallbackList<void(const std::set<GURL>&)> |
900 favicon_changed_callback_list_; | 914 favicon_changed_callback_list_; |
901 | 915 |
902 history::DeleteDirectiveHandler delete_directive_handler_; | 916 history::DeleteDirectiveHandler delete_directive_handler_; |
903 | 917 |
904 // All vended weak pointers are invalidated in Cleanup(). | 918 // All vended weak pointers are invalidated in Cleanup(). |
905 base::WeakPtrFactory<HistoryService> weak_ptr_factory_; | 919 base::WeakPtrFactory<HistoryService> weak_ptr_factory_; |
906 | 920 |
907 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 921 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
908 }; | 922 }; |
909 | 923 |
910 #endif // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ | 924 #endif // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ |
OLD | NEW |