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 13 matching lines...) Expand all Loading... |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "chrome/browser/history/delete_directive_handler.h" | 25 #include "chrome/browser/history/delete_directive_handler.h" |
26 #include "chrome/browser/history/typed_url_syncable_service.h" | 26 #include "chrome/browser/history/typed_url_syncable_service.h" |
27 #include "chrome/common/ref_counted_util.h" | 27 #include "chrome/common/ref_counted_util.h" |
28 #include "components/favicon_base/favicon_callback.h" | 28 #include "components/favicon_base/favicon_callback.h" |
29 #include "components/history/core/browser/history_client.h" | 29 #include "components/history/core/browser/history_client.h" |
30 #include "components/history/core/browser/keyword_id.h" | 30 #include "components/history/core/browser/keyword_id.h" |
31 #include "components/keyed_service/core/keyed_service.h" | 31 #include "components/keyed_service/core/keyed_service.h" |
32 #include "components/visitedlink/browser/visitedlink_delegate.h" | 32 #include "components/visitedlink/browser/visitedlink_delegate.h" |
33 #include "content/public/browser/download_manager_delegate.h" | 33 #include "content/public/browser/download_manager_delegate.h" |
34 #include "content/public/browser/notification_observer.h" | |
35 #include "content/public/browser/notification_registrar.h" | |
36 #include "sql/init_status.h" | 34 #include "sql/init_status.h" |
37 #include "sync/api/syncable_service.h" | 35 #include "sync/api/syncable_service.h" |
38 #include "ui/base/page_transition_types.h" | 36 #include "ui/base/page_transition_types.h" |
39 | 37 |
40 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
41 class AndroidHistoryProviderService; | 39 class AndroidHistoryProviderService; |
42 #endif | 40 #endif |
43 | 41 |
44 class GURL; | 42 class GURL; |
45 class PageUsageData; | 43 class PageUsageData; |
(...skipping 21 matching lines...) Expand all Loading... |
67 class HistoryQueryTest; | 65 class HistoryQueryTest; |
68 class HistoryServiceObserver; | 66 class HistoryServiceObserver; |
69 class HistoryTest; | 67 class HistoryTest; |
70 class InMemoryHistoryBackend; | 68 class InMemoryHistoryBackend; |
71 class InMemoryURLIndex; | 69 class InMemoryURLIndex; |
72 class InMemoryURLIndexTest; | 70 class InMemoryURLIndexTest; |
73 class URLDatabase; | 71 class URLDatabase; |
74 class VisitFilter; | 72 class VisitFilter; |
75 struct DownloadRow; | 73 struct DownloadRow; |
76 struct HistoryAddPageArgs; | 74 struct HistoryAddPageArgs; |
77 struct HistoryDetails; | |
78 struct KeywordSearchTermVisit; | 75 struct KeywordSearchTermVisit; |
79 | 76 |
80 } // namespace history | 77 } // namespace history |
81 | 78 |
82 // The history service records page titles, and visit times, as well as | 79 // The history service records page titles, and visit times, as well as |
83 // (eventually) information about autocomplete. | 80 // (eventually) information about autocomplete. |
84 // | 81 // |
85 // This service is thread safe. Each request callback is invoked in the | 82 // This service is thread safe. Each request callback is invoked in the |
86 // thread that made the request. | 83 // thread that made the request. |
87 class HistoryService : public content::NotificationObserver, | 84 class HistoryService : public syncer::SyncableService, |
88 public syncer::SyncableService, | |
89 public KeyedService, | 85 public KeyedService, |
90 public visitedlink::VisitedLinkDelegate { | 86 public visitedlink::VisitedLinkDelegate { |
91 public: | 87 public: |
92 // Miscellaneous commonly-used types. | 88 // Miscellaneous commonly-used types. |
93 typedef std::vector<PageUsageData*> PageUsageDataList; | 89 typedef std::vector<PageUsageData*> PageUsageDataList; |
94 | 90 |
95 // Must call Init after construction. The |history::HistoryClient| object | 91 // Must call Init after construction. The |history::HistoryClient| object |
96 // must be valid for the whole lifetime of |HistoryService|. | 92 // must be valid for the whole lifetime of |HistoryService|. |
97 explicit HistoryService(history::HistoryClient* client, Profile* profile); | 93 explicit HistoryService(history::HistoryClient* client, Profile* profile); |
98 // The empty constructor is provided only for testing. | 94 // The empty constructor is provided only for testing. |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // will release pointers to it. No other functions should be called once | 546 // will release pointers to it. No other functions should be called once |
551 // cleanup has happened that may dispatch to the history thread (because it | 547 // cleanup has happened that may dispatch to the history thread (because it |
552 // will be NULL). | 548 // will be NULL). |
553 // | 549 // |
554 // In practice, this will be called by the service manager (BrowserProcess) | 550 // In practice, this will be called by the service manager (BrowserProcess) |
555 // when it is being destroyed. Because that reference is being destroyed, it | 551 // when it is being destroyed. Because that reference is being destroyed, it |
556 // should be impossible for anybody else to call the service, even if it is | 552 // should be impossible for anybody else to call the service, even if it is |
557 // still in memory (pending requests may be holding a reference to us). | 553 // still in memory (pending requests may be holding a reference to us). |
558 void Cleanup(); | 554 void Cleanup(); |
559 | 555 |
560 // Implementation of content::NotificationObserver. | |
561 void Observe(int type, | |
562 const content::NotificationSource& source, | |
563 const content::NotificationDetails& details) override; | |
564 | |
565 // Implementation of visitedlink::VisitedLinkDelegate. | 556 // Implementation of visitedlink::VisitedLinkDelegate. |
566 void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override; | 557 void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override; |
567 | 558 |
568 // Low-level Init(). Same as the public version, but adds a |no_db| parameter | 559 // Low-level Init(). Same as the public version, but adds a |no_db| parameter |
569 // that is only set by unittests which causes the backend to not init its DB. | 560 // that is only set by unittests which causes the backend to not init its DB. |
570 bool Init(bool no_db, | 561 bool Init(bool no_db, |
571 const history::HistoryDatabaseParams& history_database_params); | 562 const history::HistoryDatabaseParams& history_database_params); |
572 | 563 |
573 // Called by the HistoryURLProvider class to schedule an autocomplete, it | 564 // Called by the HistoryURLProvider class to schedule an autocomplete, it |
574 // will be called back on the internal history thread with the history | 565 // will be called back on the internal history thread with the history |
575 // database so it can query. See history_autocomplete.cc for a diagram. | 566 // database so it can query. See history_autocomplete.cc for a diagram. |
576 void ScheduleAutocomplete(const base::Callback< | 567 void ScheduleAutocomplete(const base::Callback< |
577 void(history::HistoryBackend*, history::URLDatabase*)>& callback); | 568 void(history::HistoryBackend*, history::URLDatabase*)>& callback); |
578 | 569 |
579 // Broadcasts the given notification. This is called by the backend so that | |
580 // the notification will be broadcast on the main thread. | |
581 void BroadcastNotificationsHelper( | |
582 int type, | |
583 scoped_ptr<history::HistoryDetails> details); | |
584 | |
585 // Notification from the backend that it has finished loading. Sends | 570 // Notification from the backend that it has finished loading. Sends |
586 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. | 571 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. |
587 void OnDBLoaded(); | 572 void OnDBLoaded(); |
588 | 573 |
589 // Helper function for getting URL information. | 574 // Helper function for getting URL information. |
590 // Reads a URLRow from in-memory database. Returns false if database is not | 575 // Reads a URLRow from in-memory database. Returns false if database is not |
591 // available or the URL does not exist. | 576 // available or the URL does not exist. |
592 bool GetRowForURL(const GURL& url, history::URLRow* url_row); | 577 bool GetRowForURL(const GURL& url, history::URLRow* url_row); |
593 | 578 |
594 // Observers ---------------------------------------------------------------- | 579 // Observers ---------------------------------------------------------------- |
595 | 580 |
596 // Notify all Observers registered that the VisitDatabase was changed. | 581 // Notify all Observers registered that the VisitDatabase was changed. |
597 void NotifyAddVisit(const history::BriefVisitInfo& info); | 582 void NotifyAddVisit(const history::BriefVisitInfo& info); |
598 | 583 |
599 // Notify all HistoryServiceObservers registered that user is visiting a URL. | 584 // Notify all HistoryServiceObservers registered that user is visiting a URL. |
600 // The |row| ID will be set to the value that is currently in effect in the | 585 // The |row| ID will be set to the value that is currently in effect in the |
601 // main history database. |redirects| is the list of redirects leading up to | 586 // main history database. |redirects| is the list of redirects leading up to |
602 // the URL. If we have a redirect chain A -> B -> C and user is visiting C, | 587 // the URL. If we have a redirect chain A -> B -> C and user is visiting C, |
603 // then |redirects[0]=B| and |redirects[1]=A|. If there are no redirects, | 588 // then |redirects[0]=B| and |redirects[1]=A|. If there are no redirects, |
604 // |redirects| is an empty vector. | 589 // |redirects| is an empty vector. |
605 void NotifyURLVisited(ui::PageTransition transition, | 590 void NotifyURLVisited(ui::PageTransition transition, |
606 const history::URLRow& row, | 591 const history::URLRow& row, |
607 const history::RedirectList& redirects, | 592 const history::RedirectList& redirects, |
608 base::Time visit_time); | 593 base::Time visit_time); |
609 | 594 |
610 // Notify all HistoryServiceObservers registered that URLs have been added or | 595 // Notify all HistoryServiceObservers registered that URLs have been added or |
611 // modified. |changed_urls| contains the list of affects URLs. | 596 // modified. |changed_urls| contains the list of affects URLs. |
612 void NotifyURLsModified(const history::URLRows& changed_urls); | 597 void NotifyURLsModified(const history::URLRows& changed_urls); |
613 | 598 |
| 599 // Notify all HistoryServiceObservers registered that URLs have been deleted. |
| 600 // |all_history| is set to true, if all the URLs are deleted. |
| 601 // When set to true, |deleted_rows| and |favicon_urls| are |
| 602 // undefined. |
| 603 // |expired| is set to true, if the URL deletion is due to expiration. |
| 604 // |deleted_rows| list of the deleted URLs. |
| 605 // |favicon_urls| list of favicon URLs that correspond to the deleted URLs. |
| 606 void NotifyURLsDeleted(bool all_history, |
| 607 bool expired, |
| 608 const history::URLRows& deleted_rows, |
| 609 const std::set<GURL>& favicon_urls); |
| 610 |
614 // Notify all HistoryServiceObservers registered that the | 611 // Notify all HistoryServiceObservers registered that the |
615 // HistoryService has finished loading. | 612 // HistoryService has finished loading. |
616 void NotifyHistoryServiceLoaded(); | 613 void NotifyHistoryServiceLoaded(); |
617 | 614 |
618 // HistoryService is being deleted. | 615 // Notify all HistoryServiceObservers registered that HistoryService is being |
| 616 // deleted. |
619 void NotifyHistoryServiceBeingDeleted(); | 617 void NotifyHistoryServiceBeingDeleted(); |
620 | 618 |
621 // Notify all HistoryServiceObservers registered that a keyword search term | 619 // Notify all HistoryServiceObservers registered that a keyword search term |
622 // has been updated. |row| contains the URL information for search |term|. | 620 // has been updated. |row| contains the URL information for search |term|. |
623 // |keyword_id| associated with a URL and search term. | 621 // |keyword_id| associated with a URL and search term. |
624 void NotifyKeywordSearchTermUpdated(const history::URLRow& row, | 622 void NotifyKeywordSearchTermUpdated(const history::URLRow& row, |
625 history::KeywordID keyword_id, | 623 history::KeywordID keyword_id, |
626 const base::string16& term); | 624 const base::string16& term); |
627 | 625 |
628 // Notify all HistoryServiceObservers registered that keyword search term is | 626 // Notify all HistoryServiceObservers registered that keyword search term is |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 const ArgD& d, | 860 const ArgD& d, |
863 const ArgE& e) { | 861 const ArgE& e) { |
864 DCHECK(thread_) << "History service being called after cleanup"; | 862 DCHECK(thread_) << "History service being called after cleanup"; |
865 DCHECK(thread_checker_.CalledOnValidThread()); | 863 DCHECK(thread_checker_.CalledOnValidThread()); |
866 ScheduleTask(priority, base::Bind(func, history_backend_.get(), | 864 ScheduleTask(priority, base::Bind(func, history_backend_.get(), |
867 a, b, c, d, e)); | 865 a, b, c, d, e)); |
868 } | 866 } |
869 | 867 |
870 base::ThreadChecker thread_checker_; | 868 base::ThreadChecker thread_checker_; |
871 | 869 |
872 content::NotificationRegistrar registrar_; | |
873 | |
874 // The thread used by the history service to run complicated operations. | 870 // The thread used by the history service to run complicated operations. |
875 // |thread_| is NULL once |Cleanup| is NULL. | 871 // |thread_| is NULL once |Cleanup| is NULL. |
876 base::Thread* thread_; | 872 base::Thread* thread_; |
877 | 873 |
878 // This class has most of the implementation and runs on the 'thread_'. | 874 // This class has most of the implementation and runs on the 'thread_'. |
879 // You MUST communicate with this class ONLY through the thread_'s | 875 // You MUST communicate with this class ONLY through the thread_'s |
880 // message_loop(). | 876 // message_loop(). |
881 // | 877 // |
882 // This pointer will be NULL once Cleanup() has been called, meaning no | 878 // This pointer will be NULL once Cleanup() has been called, meaning no |
883 // more calls should be made to the history thread. | 879 // more calls should be made to the history thread. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 | 915 |
920 history::DeleteDirectiveHandler delete_directive_handler_; | 916 history::DeleteDirectiveHandler delete_directive_handler_; |
921 | 917 |
922 // All vended weak pointers are invalidated in Cleanup(). | 918 // All vended weak pointers are invalidated in Cleanup(). |
923 base::WeakPtrFactory<HistoryService> weak_ptr_factory_; | 919 base::WeakPtrFactory<HistoryService> weak_ptr_factory_; |
924 | 920 |
925 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 921 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
926 }; | 922 }; |
927 | 923 |
928 #endif // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ | 924 #endif // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ |
OLD | NEW |