| 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_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_H_ |
| 6 #define CHROME_BROWSER_HISTORY_HISTORY_H_ | 6 #define CHROME_BROWSER_HISTORY_HISTORY_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
| 20 #include "base/string16.h" | 20 #include "base/string16.h" |
| 21 #include "base/time.h" | 21 #include "base/time.h" |
| 22 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
| 23 #include "chrome/browser/common/cancelable_request.h" | 23 #include "chrome/browser/common/cancelable_request.h" |
| 24 #include "chrome/browser/favicon/favicon_service.h" | 24 #include "chrome/browser/favicon/favicon_service.h" |
| 25 #include "chrome/browser/history/history_types.h" | 25 #include "chrome/browser/history/history_types.h" |
| 26 #include "chrome/browser/profiles/profile_keyed_service.h" | 26 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 27 #include "chrome/browser/search_engines/template_url_id.h" | 27 #include "chrome/browser/search_engines/template_url_id.h" |
| 28 #include "chrome/browser/visitedlink/visitedlink_delegate.h" | |
| 29 #include "chrome/common/cancelable_task_tracker.h" | 28 #include "chrome/common/cancelable_task_tracker.h" |
| 30 #include "chrome/common/ref_counted_util.h" | 29 #include "chrome/common/ref_counted_util.h" |
| 31 #include "content/public/browser/notification_observer.h" | 30 #include "content/public/browser/notification_observer.h" |
| 32 #include "content/public/browser/notification_registrar.h" | 31 #include "content/public/browser/notification_registrar.h" |
| 33 #include "content/public/common/page_transition_types.h" | 32 #include "content/public/common/page_transition_types.h" |
| 34 #include "sql/init_status.h" | 33 #include "sql/init_status.h" |
| 35 #include "sync/api/syncable_service.h" | 34 #include "sync/api/syncable_service.h" |
| 36 #include "ui/base/layout.h" | 35 #include "ui/base/layout.h" |
| 37 | 36 |
| 38 #if defined(OS_ANDROID) | 37 #if defined(OS_ANDROID) |
| 39 #include "chrome/browser/history/android/android_history_provider_service.h" | 38 #include "chrome/browser/history/android/android_history_provider_service.h" |
| 40 #endif | 39 #endif |
| 41 | 40 |
| 42 class BookmarkService; | 41 class BookmarkService; |
| 43 class FilePath; | 42 class FilePath; |
| 44 class GURL; | 43 class GURL; |
| 45 class HistoryURLProvider; | 44 class HistoryURLProvider; |
| 46 class PageUsageData; | 45 class PageUsageData; |
| 47 class PageUsageRequest; | 46 class PageUsageRequest; |
| 48 class Profile; | 47 class Profile; |
| 49 class VisitedLinkMaster; | |
| 50 struct HistoryURLProviderParams; | 48 struct HistoryURLProviderParams; |
| 51 | 49 |
| 52 namespace base { | 50 namespace base { |
| 53 class Thread; | 51 class Thread; |
| 54 } | 52 } |
| 55 | 53 |
| 56 | 54 |
| 57 namespace history { | 55 namespace history { |
| 58 | 56 |
| 59 class HistoryBackend; | 57 class HistoryBackend; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 }; | 100 }; |
| 103 | 101 |
| 104 // The history service records page titles, and visit times, as well as | 102 // The history service records page titles, and visit times, as well as |
| 105 // (eventually) information about autocomplete. | 103 // (eventually) information about autocomplete. |
| 106 // | 104 // |
| 107 // This service is thread safe. Each request callback is invoked in the | 105 // This service is thread safe. Each request callback is invoked in the |
| 108 // thread that made the request. | 106 // thread that made the request. |
| 109 class HistoryService : public CancelableRequestProvider, | 107 class HistoryService : public CancelableRequestProvider, |
| 110 public content::NotificationObserver, | 108 public content::NotificationObserver, |
| 111 public syncer::SyncableService, | 109 public syncer::SyncableService, |
| 112 public ProfileKeyedService, | 110 public ProfileKeyedService { |
| 113 public VisitedLinkDelegate { | |
| 114 public: | 111 public: |
| 115 // Miscellaneous commonly-used types. | 112 // Miscellaneous commonly-used types. |
| 116 typedef std::vector<PageUsageData*> PageUsageDataList; | 113 typedef std::vector<PageUsageData*> PageUsageDataList; |
| 117 | 114 |
| 118 // Must call Init after construction. | 115 // Must call Init after construction. |
| 119 explicit HistoryService(Profile* profile); | 116 explicit HistoryService(Profile* profile); |
| 120 // The empty constructor is provided only for testing. | 117 // The empty constructor is provided only for testing. |
| 121 HistoryService(); | 118 HistoryService(); |
| 122 | 119 |
| 123 virtual ~HistoryService(); | 120 virtual ~HistoryService(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 254 |
| 258 // Indexing ------------------------------------------------------------------ | 255 // Indexing ------------------------------------------------------------------ |
| 259 | 256 |
| 260 // Notifies history of the body text of the given recently-visited URL. | 257 // Notifies history of the body text of the given recently-visited URL. |
| 261 // If the URL was not visited "recently enough," the history system may | 258 // If the URL was not visited "recently enough," the history system may |
| 262 // discard it. | 259 // discard it. |
| 263 void SetPageContents(const GURL& url, const string16& contents); | 260 void SetPageContents(const GURL& url, const string16& contents); |
| 264 | 261 |
| 265 // Querying ------------------------------------------------------------------ | 262 // Querying ------------------------------------------------------------------ |
| 266 | 263 |
| 264 // Callback class that a client can implement to iterate over URLs. The |
| 265 // callbacks WILL BE CALLED ON THE BACKGROUND THREAD! Your implementation |
| 266 // should handle this appropriately. |
| 267 class URLEnumerator { |
| 268 public: |
| 269 // Indicates that a URL is available. There will be exactly one call for |
| 270 // every URL in history. |
| 271 virtual void OnURL(const history::URLRow& url_row) = 0; |
| 272 |
| 273 // Indicates we are done iterating over URLs. Once called, there will be no |
| 274 // more callbacks made. This call is guaranteed to occur, even if there are |
| 275 // no URLs. If all URLs were iterated, success will be true. |
| 276 virtual void OnComplete(bool success) = 0; |
| 277 |
| 278 protected: |
| 279 virtual ~URLEnumerator() {} |
| 280 }; |
| 281 |
| 282 // Enumerate all URLs in history. The given iterator will be owned by the |
| 283 // caller, so the caller should ensure it exists until OnComplete is called. |
| 284 // You should not generally use this since it will be slow to slurp all URLs |
| 285 // in from the database. It is designed for rebuilding the visited link |
| 286 // database from history. |
| 287 void IterateURLs(URLEnumerator* iterator); |
| 288 |
| 267 // Returns the information about the requested URL. If the URL is found, | 289 // Returns the information about the requested URL. If the URL is found, |
| 268 // success will be true and the information will be in the URLRow parameter. | 290 // success will be true and the information will be in the URLRow parameter. |
| 269 // On success, the visits, if requested, will be sorted by date. If they have | 291 // On success, the visits, if requested, will be sorted by date. If they have |
| 270 // not been requested, the pointer will be valid, but the vector will be | 292 // not been requested, the pointer will be valid, but the vector will be |
| 271 // empty. | 293 // empty. |
| 272 // | 294 // |
| 273 // If success is false, neither the row nor the vector will be valid. | 295 // If success is false, neither the row nor the vector will be valid. |
| 274 typedef base::Callback<void( | 296 typedef base::Callback<void( |
| 275 Handle, | 297 Handle, |
| 276 bool, // Success flag, when false, nothing else is valid. | 298 bool, // Success flag, when false, nothing else is valid. |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 template<typename Info, typename Callback> friend class DownloadRequest; | 672 template<typename Info, typename Callback> friend class DownloadRequest; |
| 651 friend class PageUsageRequest; | 673 friend class PageUsageRequest; |
| 652 friend class RedirectRequest; | 674 friend class RedirectRequest; |
| 653 friend class TestingProfile; | 675 friend class TestingProfile; |
| 654 | 676 |
| 655 // Implementation of content::NotificationObserver. | 677 // Implementation of content::NotificationObserver. |
| 656 virtual void Observe(int type, | 678 virtual void Observe(int type, |
| 657 const content::NotificationSource& source, | 679 const content::NotificationSource& source, |
| 658 const content::NotificationDetails& details) OVERRIDE; | 680 const content::NotificationDetails& details) OVERRIDE; |
| 659 | 681 |
| 660 // Implementation of VisitedLinkDelegate. | |
| 661 virtual bool AreEquivalentContexts( | |
| 662 content::BrowserContext* context1, | |
| 663 content::BrowserContext* context2) OVERRIDE; | |
| 664 virtual void RebuildTable(URLEnumerator* enumerator) OVERRIDE; | |
| 665 | |
| 666 // Low-level Init(). Same as the public version, but adds a |no_db| parameter | 682 // Low-level Init(). Same as the public version, but adds a |no_db| parameter |
| 667 // that is only set by unittests which causes the backend to not init its DB. | 683 // that is only set by unittests which causes the backend to not init its DB. |
| 668 bool Init(const FilePath& history_dir, | 684 bool Init(const FilePath& history_dir, |
| 669 BookmarkService* bookmark_service, | 685 BookmarkService* bookmark_service, |
| 670 bool no_db); | 686 bool no_db); |
| 671 | 687 |
| 672 // Called by the HistoryURLProvider class to schedule an autocomplete, it | 688 // Called by the HistoryURLProvider class to schedule an autocomplete, it |
| 673 // will be called back on the internal history thread with the history | 689 // will be called back on the internal history thread with the history |
| 674 // database so it can query. See history_autocomplete.cc for a diagram. | 690 // database so it can query. See history_autocomplete.cc for a diagram. |
| 675 void ScheduleAutocomplete(HistoryURLProvider* provider, | 691 void ScheduleAutocomplete(HistoryURLProvider* provider, |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 // on the background thread. | 1096 // on the background thread. |
| 1081 // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 | 1097 // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 |
| 1082 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; | 1098 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; |
| 1083 | 1099 |
| 1084 // Used to propagate local delete directives to sync. | 1100 // Used to propagate local delete directives to sync. |
| 1085 scoped_ptr<syncer::SyncChangeProcessor> sync_change_processor_; | 1101 scoped_ptr<syncer::SyncChangeProcessor> sync_change_processor_; |
| 1086 | 1102 |
| 1087 // The profile, may be null when testing. | 1103 // The profile, may be null when testing. |
| 1088 Profile* profile_; | 1104 Profile* profile_; |
| 1089 | 1105 |
| 1090 // Used for propagating link highlighting data across renderers. May be null | |
| 1091 // in tests. | |
| 1092 scoped_ptr<VisitedLinkMaster> visitedlink_master_; | |
| 1093 | |
| 1094 // Has the backend finished loading? The backend is loaded once Init has | 1106 // Has the backend finished loading? The backend is loaded once Init has |
| 1095 // completed. | 1107 // completed. |
| 1096 bool backend_loaded_; | 1108 bool backend_loaded_; |
| 1097 | 1109 |
| 1098 // The id of the current backend. This is only valid when history_backend_ | 1110 // The id of the current backend. This is only valid when history_backend_ |
| 1099 // is not NULL. | 1111 // is not NULL. |
| 1100 int current_backend_id_; | 1112 int current_backend_id_; |
| 1101 | 1113 |
| 1102 // Cached values from Init(), used whenever we need to reload the backend. | 1114 // Cached values from Init(), used whenever we need to reload the backend. |
| 1103 FilePath history_dir_; | 1115 FilePath history_dir_; |
| 1104 BookmarkService* bookmark_service_; | 1116 BookmarkService* bookmark_service_; |
| 1105 bool no_db_; | 1117 bool no_db_; |
| 1106 | 1118 |
| 1107 // True if needs top site migration. | 1119 // True if needs top site migration. |
| 1108 bool needs_top_sites_migration_; | 1120 bool needs_top_sites_migration_; |
| 1109 | 1121 |
| 1110 // The index used for quick history lookups. | 1122 // The index used for quick history lookups. |
| 1111 // TODO(mrossetti): Move in_memory_url_index out of history_service. | 1123 // TODO(mrossetti): Move in_memory_url_index out of history_service. |
| 1112 // See http://crbug.com/138321 | 1124 // See http://crbug.com/138321 |
| 1113 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 1125 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
| 1114 | 1126 |
| 1115 ObserverList<history::VisitDatabaseObserver> visit_database_observers_; | 1127 ObserverList<history::VisitDatabaseObserver> visit_database_observers_; |
| 1116 | 1128 |
| 1117 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 1129 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
| 1118 }; | 1130 }; |
| 1119 | 1131 |
| 1120 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ | 1132 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ |
| OLD | NEW |