| 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 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // Must call Init after construction. | 104 // Must call Init after construction. |
| 105 explicit HistoryService(Profile* profile); | 105 explicit HistoryService(Profile* profile); |
| 106 // The empty constructor is provided only for testing. | 106 // The empty constructor is provided only for testing. |
| 107 HistoryService(); | 107 HistoryService(); |
| 108 | 108 |
| 109 // Initializes the history service, returning true on success. On false, do | 109 // Initializes the history service, returning true on success. On false, do |
| 110 // not call any other functions. The given directory will be used for storing | 110 // not call any other functions. The given directory will be used for storing |
| 111 // the history files. The BookmarkService is used when deleting URLs to | 111 // the history files. The BookmarkService is used when deleting URLs to |
| 112 // test if a URL is bookmarked; it may be NULL during testing. | 112 // test if a URL is bookmarked; it may be NULL during testing. |
| 113 bool Init(const FilePath& history_dir, BookmarkService* bookmark_service) { | 113 bool Init(const FilePath& history_dir, BookmarkService* bookmark_service) { |
| 114 return Init(history_dir, bookmark_service, false); | 114 return Init(history_dir, bookmark_service, false, false); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Triggers the backend to load if it hasn't already, and then returns whether | 117 // Triggers the backend to load if it hasn't already, and then returns whether |
| 118 // it's finished loading. | 118 // it's finished loading. |
| 119 // Note: Virtual needed for mocking. | 119 // Note: Virtual needed for mocking. |
| 120 virtual bool BackendLoaded(); | 120 virtual bool BackendLoaded(); |
| 121 | 121 |
| 122 // Returns true if the backend has finished loading. | 122 // Returns true if the backend has finished loading. |
| 123 bool backend_loaded() const { return backend_loaded_; } | 123 bool backend_loaded() const { return backend_loaded_; } |
| 124 | 124 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 247 |
| 248 // Querying ------------------------------------------------------------------ | 248 // Querying ------------------------------------------------------------------ |
| 249 | 249 |
| 250 // Callback class that a client can implement to iterate over URLs. The | 250 // Callback class that a client can implement to iterate over URLs. The |
| 251 // callbacks WILL BE CALLED ON THE BACKGROUND THREAD! Your implementation | 251 // callbacks WILL BE CALLED ON THE BACKGROUND THREAD! Your implementation |
| 252 // should handle this appropriately. | 252 // should handle this appropriately. |
| 253 class URLEnumerator { | 253 class URLEnumerator { |
| 254 public: | 254 public: |
| 255 // Indicates that a URL is available. There will be exactly one call for | 255 // Indicates that a URL is available. There will be exactly one call for |
| 256 // every URL in history. | 256 // every URL in history. |
| 257 virtual void OnURL(const GURL& url) = 0; | 257 virtual void OnURL(const history::URLRow& url_row) = 0; |
| 258 | 258 |
| 259 // Indicates we are done iterating over URLs. Once called, there will be no | 259 // Indicates we are done iterating over URLs. Once called, there will be no |
| 260 // more callbacks made. This call is guaranteed to occur, even if there are | 260 // more callbacks made. This call is guaranteed to occur, even if there are |
| 261 // no URLs. If all URLs were iterated, success will be true. | 261 // no URLs. If all URLs were iterated, success will be true. |
| 262 virtual void OnComplete(bool success) = 0; | 262 virtual void OnComplete(bool success) = 0; |
| 263 | 263 |
| 264 protected: | 264 protected: |
| 265 virtual ~URLEnumerator() {} | 265 virtual ~URLEnumerator() {} |
| 266 }; | 266 }; |
| 267 | 267 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 QueryFilteredURLsCallback; | 382 QueryFilteredURLsCallback; |
| 383 | 383 |
| 384 // Request the |result_count| most visited URLs and the chain of | 384 // Request the |result_count| most visited URLs and the chain of |
| 385 // redirects leading to each of these URLs. |days_back| is the | 385 // redirects leading to each of these URLs. |days_back| is the |
| 386 // number of days of history to use. Used by TopSites. | 386 // number of days of history to use. Used by TopSites. |
| 387 Handle QueryMostVisitedURLs(int result_count, int days_back, | 387 Handle QueryMostVisitedURLs(int result_count, int days_back, |
| 388 CancelableRequestConsumerBase* consumer, | 388 CancelableRequestConsumerBase* consumer, |
| 389 const QueryMostVisitedURLsCallback& callback); | 389 const QueryMostVisitedURLsCallback& callback); |
| 390 | 390 |
| 391 // Request the |result_count| URLs filtered and sorted based on the |filter|. | 391 // Request the |result_count| URLs filtered and sorted based on the |filter|. |
| 392 // If |extended_info| is enabled, additional data will be provided in the | 392 // If |extended_info| is true, additional data will be provided in the |
| 393 // results. | 393 // results. Computing this additional data is expensive, likely to become |
| 394 // more expensive as additional data points are added in future changes, and |
| 395 // not useful in most cases. Set |extended_info| to true only if you |
| 396 // explicitly require the additional data. |
| 394 Handle QueryFilteredURLs( | 397 Handle QueryFilteredURLs( |
| 395 int result_count, | 398 int result_count, |
| 396 const history::VisitFilter& filter, | 399 const history::VisitFilter& filter, |
| 397 bool extended_info, | 400 bool extended_info, |
| 398 CancelableRequestConsumerBase* consumer, | 401 CancelableRequestConsumerBase* consumer, |
| 399 const QueryFilteredURLsCallback& callback); | 402 const QueryFilteredURLsCallback& callback); |
| 400 | 403 |
| 401 // Thumbnails ---------------------------------------------------------------- | 404 // Thumbnails ---------------------------------------------------------------- |
| 402 | 405 |
| 403 // Implemented by consumers to get thumbnail data. Called when a request for | 406 // Implemented by consumers to get thumbnail data. Called when a request for |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 void StartTopSitesMigration(int backend_id); | 614 void StartTopSitesMigration(int backend_id); |
| 612 | 615 |
| 613 // Called by TopSites after the thumbnails were read and it is safe | 616 // Called by TopSites after the thumbnails were read and it is safe |
| 614 // to delete the thumbnails DB. | 617 // to delete the thumbnails DB. |
| 615 void OnTopSitesReady(); | 618 void OnTopSitesReady(); |
| 616 | 619 |
| 617 // Returns true if this looks like the type of URL we want to add to the | 620 // Returns true if this looks like the type of URL we want to add to the |
| 618 // history. We filter out some URLs such as JavaScript. | 621 // history. We filter out some URLs such as JavaScript. |
| 619 static bool CanAddURL(const GURL& url); | 622 static bool CanAddURL(const GURL& url); |
| 620 | 623 |
| 624 // Returns the history backend associated with this service. |
| 625 history::HistoryBackend* get_history_backend_for_testing() { |
| 626 return history_backend_.get(); |
| 627 } |
| 628 |
| 621 protected: | 629 protected: |
| 622 virtual ~HistoryService(); | 630 virtual ~HistoryService(); |
| 623 | 631 |
| 624 // These are not currently used, hopefully we can do something in the future | 632 // These are not currently used, hopefully we can do something in the future |
| 625 // to ensure that the most important things happen first. | 633 // to ensure that the most important things happen first. |
| 626 enum SchedulePriority { | 634 enum SchedulePriority { |
| 627 PRIORITY_UI, // The highest priority (must respond to UI events). | 635 PRIORITY_UI, // The highest priority (must respond to UI events). |
| 628 PRIORITY_NORMAL, // Normal stuff like adding a page. | 636 PRIORITY_NORMAL, // Normal stuff like adding a page. |
| 629 PRIORITY_LOW, // Low priority things like indexing or expiration. | 637 PRIORITY_LOW, // Low priority things like indexing or expiration. |
| 630 }; | 638 }; |
| 631 | 639 |
| 632 private: | 640 private: |
| 633 class BackendDelegate; | 641 class BackendDelegate; |
| 634 #if defined(OS_ANDROID) | 642 #if defined(OS_ANDROID) |
| 635 friend class AndroidHistoryProviderService; | 643 friend class AndroidHistoryProviderService; |
| 636 #endif | 644 #endif |
| 637 friend class base::RefCountedThreadSafe<HistoryService>; | 645 friend class base::RefCountedThreadSafe<HistoryService>; |
| 638 friend class BackendDelegate; | 646 friend class BackendDelegate; |
| 647 friend class CacheTestingProfile; |
| 639 friend class FaviconService; | 648 friend class FaviconService; |
| 640 friend class history::HistoryBackend; | 649 friend class history::HistoryBackend; |
| 641 friend class history::HistoryQueryTest; | 650 friend class history::HistoryQueryTest; |
| 642 friend class HistoryOperation; | 651 friend class HistoryOperation; |
| 643 friend class HistoryURLProvider; | 652 friend class HistoryURLProvider; |
| 644 friend class HistoryURLProviderTest; | 653 friend class HistoryURLProviderTest; |
| 645 friend class history::InMemoryURLIndexTest; | 654 friend class InMemoryURLIndexBaseTest; |
| 646 template<typename Info, typename Callback> friend class DownloadRequest; | 655 template<typename Info, typename Callback> friend class DownloadRequest; |
| 647 friend class PageUsageRequest; | 656 friend class PageUsageRequest; |
| 648 friend class RedirectRequest; | 657 friend class RedirectRequest; |
| 649 friend class TestingProfile; | 658 friend class TestingProfile; |
| 650 | 659 |
| 651 // Implementation of content::NotificationObserver. | 660 // Implementation of content::NotificationObserver. |
| 652 virtual void Observe(int type, | 661 virtual void Observe(int type, |
| 653 const content::NotificationSource& source, | 662 const content::NotificationSource& source, |
| 654 const content::NotificationDetails& details) OVERRIDE; | 663 const content::NotificationDetails& details) OVERRIDE; |
| 655 | 664 |
| 656 // Low-level Init(). Same as the public version, but adds a |no_db| parameter | 665 // Low-level Init(). Same as the public version, but adds the |no_db| and |
| 657 // that is only set by unittests which causes the backend to not init its DB. | 666 // |disable_index_cache| parameters that are only set by unittests. |no_db| |
| 667 // causes the backend to not init its DB. |disable_index_cache| causes the |
| 668 // InMemoryURLIndex to not create or use its cache database. |
| 658 bool Init(const FilePath& history_dir, | 669 bool Init(const FilePath& history_dir, |
| 659 BookmarkService* bookmark_service, | 670 BookmarkService* bookmark_service, |
| 660 bool no_db); | 671 bool no_db, |
| 672 bool disable_index_cache); |
| 661 | 673 |
| 662 // Called by the HistoryURLProvider class to schedule an autocomplete, it | 674 // Called by the HistoryURLProvider class to schedule an autocomplete, it |
| 663 // will be called back on the internal history thread with the history | 675 // will be called back on the internal history thread with the history |
| 664 // database so it can query. See history_autocomplete.cc for a diagram. | 676 // database so it can query. See history_autocomplete.cc for a diagram. |
| 665 void ScheduleAutocomplete(HistoryURLProvider* provider, | 677 void ScheduleAutocomplete(HistoryURLProvider* provider, |
| 666 HistoryURLProviderParams* params); | 678 HistoryURLProviderParams* params); |
| 667 | 679 |
| 668 // Broadcasts the given notification. This is called by the backend so that | 680 // Broadcasts the given notification. This is called by the backend so that |
| 669 // the notification will be broadcast on the main thread. | 681 // the notification will be broadcast on the main thread. |
| 670 // | 682 // |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 // You MUST communicate with this class ONLY through the thread_'s | 931 // You MUST communicate with this class ONLY through the thread_'s |
| 920 // message_loop(). | 932 // message_loop(). |
| 921 // | 933 // |
| 922 // This pointer will be NULL once Cleanup() has been called, meaning no | 934 // This pointer will be NULL once Cleanup() has been called, meaning no |
| 923 // more calls should be made to the history thread. | 935 // more calls should be made to the history thread. |
| 924 scoped_refptr<history::HistoryBackend> history_backend_; | 936 scoped_refptr<history::HistoryBackend> history_backend_; |
| 925 | 937 |
| 926 // A cache of the user-typed URLs kept in memory that is used by the | 938 // A cache of the user-typed URLs kept in memory that is used by the |
| 927 // autocomplete system. This will be NULL until the database has been created | 939 // autocomplete system. This will be NULL until the database has been created |
| 928 // on the background thread. | 940 // on the background thread. |
| 941 // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 |
| 929 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; | 942 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; |
| 930 | 943 |
| 931 // The profile, may be null when testing. | 944 // The profile, may be null when testing. |
| 932 Profile* profile_; | 945 Profile* profile_; |
| 933 | 946 |
| 934 // Has the backend finished loading? The backend is loaded once Init has | 947 // Has the backend finished loading? The backend is loaded once Init has |
| 935 // completed. | 948 // completed. |
| 936 bool backend_loaded_; | 949 bool backend_loaded_; |
| 937 | 950 |
| 938 // The id of the current backend. This is only valid when history_backend_ | 951 // The id of the current backend. This is only valid when history_backend_ |
| 939 // is not NULL. | 952 // is not NULL. |
| 940 int current_backend_id_; | 953 int current_backend_id_; |
| 941 | 954 |
| 942 // Cached values from Init(), used whenever we need to reload the backend. | 955 // Cached values from Init(), used whenever we need to reload the backend. |
| 943 FilePath history_dir_; | 956 FilePath history_dir_; |
| 944 BookmarkService* bookmark_service_; | 957 BookmarkService* bookmark_service_; |
| 945 bool no_db_; | 958 bool no_db_; |
| 946 | 959 |
| 947 // True if needs top site migration. | 960 // True if needs top site migration. |
| 948 bool needs_top_sites_migration_; | 961 bool needs_top_sites_migration_; |
| 949 | 962 |
| 950 // The index used for quick history lookups. | 963 // The index used for quick history lookups. |
| 964 // TODO(mrossetti): Move in_memory_url_index out of history_service. |
| 965 // See http://crbug.com/138321 |
| 951 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 966 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
| 952 | 967 |
| 953 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > | 968 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > |
| 954 visit_database_observers_; | 969 visit_database_observers_; |
| 955 | 970 |
| 956 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 971 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
| 957 }; | 972 }; |
| 958 | 973 |
| 959 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ | 974 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ |
| OLD | NEW |