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 10 matching lines...) Expand all Loading... |
21 #include "base/task/cancelable_task_tracker.h" | 21 #include "base/task/cancelable_task_tracker.h" |
22 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
24 #include "chrome/browser/common/cancelable_request.h" | 24 #include "chrome/browser/common/cancelable_request.h" |
25 #include "chrome/browser/history/delete_directive_handler.h" | 25 #include "chrome/browser/history/delete_directive_handler.h" |
26 #include "chrome/browser/history/history_types.h" | 26 #include "chrome/browser/history/history_types.h" |
27 #include "chrome/browser/history/typed_url_syncable_service.h" | 27 #include "chrome/browser/history/typed_url_syncable_service.h" |
28 #include "chrome/browser/search_engines/template_url_id.h" | 28 #include "chrome/browser/search_engines/template_url_id.h" |
29 #include "chrome/common/ref_counted_util.h" | 29 #include "chrome/common/ref_counted_util.h" |
30 #include "components/favicon_base/favicon_callback.h" | 30 #include "components/favicon_base/favicon_callback.h" |
| 31 #include "components/history/core/browser/history_client.h" |
31 #include "components/keyed_service/core/keyed_service.h" | 32 #include "components/keyed_service/core/keyed_service.h" |
32 #include "components/visitedlink/browser/visitedlink_delegate.h" | 33 #include "components/visitedlink/browser/visitedlink_delegate.h" |
33 #include "content/public/browser/download_manager_delegate.h" | 34 #include "content/public/browser/download_manager_delegate.h" |
34 #include "content/public/browser/notification_observer.h" | 35 #include "content/public/browser/notification_observer.h" |
35 #include "content/public/browser/notification_registrar.h" | 36 #include "content/public/browser/notification_registrar.h" |
36 #include "content/public/common/page_transition_types.h" | 37 #include "content/public/common/page_transition_types.h" |
37 #include "sql/init_status.h" | 38 #include "sql/init_status.h" |
38 #include "sync/api/syncable_service.h" | 39 #include "sync/api/syncable_service.h" |
39 #include "ui/base/layout.h" | 40 #include "ui/base/layout.h" |
40 | 41 |
41 #if defined(OS_ANDROID) | 42 #if defined(OS_ANDROID) |
42 #include "chrome/browser/history/android/android_history_provider_service.h" | 43 #include "chrome/browser/history/android/android_history_provider_service.h" |
43 #endif | 44 #endif |
44 | 45 |
45 class BookmarkService; | |
46 class GURL; | 46 class GURL; |
47 class HistoryURLProvider; | 47 class HistoryURLProvider; |
48 class PageUsageData; | 48 class PageUsageData; |
49 class PageUsageRequest; | 49 class PageUsageRequest; |
50 class Profile; | 50 class Profile; |
51 struct HistoryURLProviderParams; | 51 struct HistoryURLProviderParams; |
52 struct ImportedFaviconUsage; | 52 struct ImportedFaviconUsage; |
53 | 53 |
54 namespace base { | 54 namespace base { |
55 class FilePath; | 55 class FilePath; |
(...skipping 23 matching lines...) Expand all Loading... |
79 } // namespace history | 79 } // namespace history |
80 | 80 |
81 // The history service records page titles, and visit times, as well as | 81 // The history service records page titles, and visit times, as well as |
82 // (eventually) information about autocomplete. | 82 // (eventually) information about autocomplete. |
83 // | 83 // |
84 // This service is thread safe. Each request callback is invoked in the | 84 // This service is thread safe. Each request callback is invoked in the |
85 // thread that made the request. | 85 // thread that made the request. |
86 class HistoryService : public CancelableRequestProvider, | 86 class HistoryService : public CancelableRequestProvider, |
87 public content::NotificationObserver, | 87 public content::NotificationObserver, |
88 public syncer::SyncableService, | 88 public syncer::SyncableService, |
89 public KeyedService, | |
90 public visitedlink::VisitedLinkDelegate { | 89 public visitedlink::VisitedLinkDelegate { |
91 public: | 90 public: |
92 // Miscellaneous commonly-used types. | 91 // Miscellaneous commonly-used types. |
93 typedef std::vector<PageUsageData*> PageUsageDataList; | 92 typedef std::vector<PageUsageData*> PageUsageDataList; |
94 | 93 |
95 // Must call Init after construction. | 94 // Must call Init after construction. |
96 explicit HistoryService(Profile* profile); | 95 explicit HistoryService(history::HistoryClient* client, Profile* profile); |
97 // The empty constructor is provided only for testing. | 96 // The empty constructor is provided only for testing. |
98 HistoryService(); | 97 HistoryService(); |
99 | 98 |
100 virtual ~HistoryService(); | 99 virtual ~HistoryService(); |
101 | 100 |
102 // Initializes the history service, returning true on success. On false, do | 101 // Initializes the history service, returning true on success. On false, do |
103 // not call any other functions. The given directory will be used for storing | 102 // not call any other functions. The given directory will be used for storing |
104 // the history files. The BookmarkService is used when deleting URLs to | 103 // the history files. |
105 // test if a URL is bookmarked; it may be NULL during testing. | 104 bool Init(const base::FilePath& history_dir) { |
106 bool Init(const base::FilePath& history_dir, BookmarkService* bookmark_service
) { | 105 return Init(history_dir, false); |
107 return Init(history_dir, bookmark_service, false); | |
108 } | 106 } |
109 | 107 |
110 // Triggers the backend to load if it hasn't already, and then returns whether | 108 // Triggers the backend to load if it hasn't already, and then returns whether |
111 // it's finished loading. | 109 // it's finished loading. |
112 // Note: Virtual needed for mocking. | 110 // Note: Virtual needed for mocking. |
113 virtual bool BackendLoaded(); | 111 virtual bool BackendLoaded(); |
114 | 112 |
115 // Returns true if the backend has finished loading. | 113 // Returns true if the backend has finished loading. |
116 bool backend_loaded() const { return backend_loaded_; } | 114 bool backend_loaded() const { return backend_loaded_; } |
117 | 115 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Returns a pointer to the TypedUrlSyncableService owned by HistoryBackend. | 156 // Returns a pointer to the TypedUrlSyncableService owned by HistoryBackend. |
159 // This method should only be called from the history thread, because the | 157 // This method should only be called from the history thread, because the |
160 // returned service is intended to be accessed only via the history thread. | 158 // returned service is intended to be accessed only via the history thread. |
161 history::TypedUrlSyncableService* GetTypedUrlSyncableService() const; | 159 history::TypedUrlSyncableService* GetTypedUrlSyncableService() const; |
162 | 160 |
163 // Return the quick history index. | 161 // Return the quick history index. |
164 history::InMemoryURLIndex* InMemoryIndex() const { | 162 history::InMemoryURLIndex* InMemoryIndex() const { |
165 return in_memory_url_index_.get(); | 163 return in_memory_url_index_.get(); |
166 } | 164 } |
167 | 165 |
168 // KeyedService: | |
169 virtual void Shutdown() OVERRIDE; | |
170 | |
171 // Navigation ---------------------------------------------------------------- | 166 // Navigation ---------------------------------------------------------------- |
172 | 167 |
173 // Adds the given canonical URL to history with the given time as the visit | 168 // Adds the given canonical URL to history with the given time as the visit |
174 // time. Referrer may be the empty string. | 169 // time. Referrer may be the empty string. |
175 // | 170 // |
176 // The supplied render process host is used to scope the given page ID. Page | 171 // The supplied render process host is used to scope the given page ID. Page |
177 // IDs are only unique inside a given render process, so we need that to | 172 // IDs are only unique inside a given render process, so we need that to |
178 // differentiate them. This pointer should not be dereferenced by the history | 173 // differentiate them. This pointer should not be dereferenced by the history |
179 // system. | 174 // system. |
180 // | 175 // |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 history::VisitSource visit_source); | 551 history::VisitSource visit_source); |
557 | 552 |
558 // The same as AddPageWithDetails() but takes a vector. | 553 // The same as AddPageWithDetails() but takes a vector. |
559 void AddPagesWithDetails(const history::URLRows& info, | 554 void AddPagesWithDetails(const history::URLRows& info, |
560 history::VisitSource visit_source); | 555 history::VisitSource visit_source); |
561 | 556 |
562 // Returns true if this looks like the type of URL we want to add to the | 557 // Returns true if this looks like the type of URL we want to add to the |
563 // history. We filter out some URLs such as JavaScript. | 558 // history. We filter out some URLs such as JavaScript. |
564 static bool CanAddURL(const GURL& url); | 559 static bool CanAddURL(const GURL& url); |
565 | 560 |
| 561 // Returns the HistoryClient. |
| 562 history::HistoryClient* history_client() const { return history_client_; } |
| 563 |
566 base::WeakPtr<HistoryService> AsWeakPtr(); | 564 base::WeakPtr<HistoryService> AsWeakPtr(); |
567 | 565 |
568 // syncer::SyncableService implementation. | 566 // syncer::SyncableService implementation. |
569 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 567 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
570 syncer::ModelType type, | 568 syncer::ModelType type, |
571 const syncer::SyncDataList& initial_sync_data, | 569 const syncer::SyncDataList& initial_sync_data, |
572 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 570 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
573 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; | 571 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
574 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 572 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
575 virtual syncer::SyncDataList GetAllSyncData( | 573 virtual syncer::SyncDataList GetAllSyncData( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 virtual void Observe(int type, | 609 virtual void Observe(int type, |
612 const content::NotificationSource& source, | 610 const content::NotificationSource& source, |
613 const content::NotificationDetails& details) OVERRIDE; | 611 const content::NotificationDetails& details) OVERRIDE; |
614 | 612 |
615 // Implementation of visitedlink::VisitedLinkDelegate. | 613 // Implementation of visitedlink::VisitedLinkDelegate. |
616 virtual void RebuildTable( | 614 virtual void RebuildTable( |
617 const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE; | 615 const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE; |
618 | 616 |
619 // Low-level Init(). Same as the public version, but adds a |no_db| parameter | 617 // Low-level Init(). Same as the public version, but adds a |no_db| parameter |
620 // that is only set by unittests which causes the backend to not init its DB. | 618 // that is only set by unittests which causes the backend to not init its DB. |
621 bool Init(const base::FilePath& history_dir, | 619 bool Init(const base::FilePath& history_dir, bool no_db); |
622 BookmarkService* bookmark_service, | |
623 bool no_db); | |
624 | 620 |
625 // Called by the HistoryURLProvider class to schedule an autocomplete, it | 621 // Called by the HistoryURLProvider class to schedule an autocomplete, it |
626 // will be called back on the internal history thread with the history | 622 // will be called back on the internal history thread with the history |
627 // database so it can query. See history_autocomplete.cc for a diagram. | 623 // database so it can query. See history_autocomplete.cc for a diagram. |
628 void ScheduleAutocomplete(HistoryURLProvider* provider, | 624 void ScheduleAutocomplete(HistoryURLProvider* provider, |
629 HistoryURLProviderParams* params); | 625 HistoryURLProviderParams* params); |
630 | 626 |
631 // Broadcasts the given notification. This is called by the backend so that | 627 // Broadcasts the given notification. This is called by the backend so that |
632 // the notification will be broadcast on the main thread. | 628 // the notification will be broadcast on the main thread. |
633 void BroadcastNotificationsHelper( | 629 void BroadcastNotificationsHelper( |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 // This pointer will be NULL once Cleanup() has been called, meaning no | 1009 // This pointer will be NULL once Cleanup() has been called, meaning no |
1014 // more calls should be made to the history thread. | 1010 // more calls should be made to the history thread. |
1015 scoped_refptr<history::HistoryBackend> history_backend_; | 1011 scoped_refptr<history::HistoryBackend> history_backend_; |
1016 | 1012 |
1017 // A cache of the user-typed URLs kept in memory that is used by the | 1013 // A cache of the user-typed URLs kept in memory that is used by the |
1018 // autocomplete system. This will be NULL until the database has been created | 1014 // autocomplete system. This will be NULL until the database has been created |
1019 // on the background thread. | 1015 // on the background thread. |
1020 // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 | 1016 // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 |
1021 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; | 1017 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; |
1022 | 1018 |
| 1019 // The HistoryClient; may be NULL in tests. |
| 1020 history::HistoryClient* history_client_; |
| 1021 |
1023 // The profile, may be null when testing. | 1022 // The profile, may be null when testing. |
1024 Profile* profile_; | 1023 Profile* profile_; |
1025 | 1024 |
1026 // Used for propagating link highlighting data across renderers. May be null | 1025 // Used for propagating link highlighting data across renderers. May be null |
1027 // in tests. | 1026 // in tests. |
1028 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_; | 1027 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_; |
1029 | 1028 |
1030 // Has the backend finished loading? The backend is loaded once Init has | 1029 // Has the backend finished loading? The backend is loaded once Init has |
1031 // completed. | 1030 // completed. |
1032 bool backend_loaded_; | 1031 bool backend_loaded_; |
1033 | 1032 |
1034 // Cached values from Init(), used whenever we need to reload the backend. | 1033 // Cached values from Init(), used whenever we need to reload the backend. |
1035 base::FilePath history_dir_; | 1034 base::FilePath history_dir_; |
1036 BookmarkService* bookmark_service_; | |
1037 bool no_db_; | 1035 bool no_db_; |
1038 | 1036 |
1039 // The index used for quick history lookups. | 1037 // The index used for quick history lookups. |
1040 // TODO(mrossetti): Move in_memory_url_index out of history_service. | 1038 // TODO(mrossetti): Move in_memory_url_index out of history_service. |
1041 // See http://crbug.com/138321 | 1039 // See http://crbug.com/138321 |
1042 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 1040 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
1043 | 1041 |
1044 ObserverList<history::VisitDatabaseObserver> visit_database_observers_; | 1042 ObserverList<history::VisitDatabaseObserver> visit_database_observers_; |
1045 | 1043 |
1046 history::DeleteDirectiveHandler delete_directive_handler_; | 1044 history::DeleteDirectiveHandler delete_directive_handler_; |
1047 | 1045 |
1048 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 1046 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
1049 }; | 1047 }; |
1050 | 1048 |
1051 #endif // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ | 1049 #endif // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ |
OLD | NEW |