| 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 COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_SERVICE_H_ | 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_SERVICE_H_ |
| 6 #define COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_SERVICE_H_ | 6 #define COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/callback_list.h" | 18 #include "base/callback_list.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
| 23 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
| 24 #include "base/observer_list.h" | 24 #include "base/observer_list.h" |
| 25 #include "base/sequenced_task_runner.h" |
| 25 #include "base/strings/string16.h" | 26 #include "base/strings/string16.h" |
| 26 #include "base/task/cancelable_task_tracker.h" | 27 #include "base/task/cancelable_task_tracker.h" |
| 27 #include "base/threading/thread_checker.h" | 28 #include "base/threading/thread_checker.h" |
| 28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 29 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 30 #include "components/favicon_base/favicon_callback.h" | 31 #include "components/favicon_base/favicon_callback.h" |
| 31 #include "components/favicon_base/favicon_usage_data.h" | 32 #include "components/favicon_base/favicon_usage_data.h" |
| 32 #include "components/history/core/browser/delete_directive_handler.h" | 33 #include "components/history/core/browser/delete_directive_handler.h" |
| 33 #include "components/history/core/browser/history_types.h" | 34 #include "components/history/core/browser/history_types.h" |
| 34 #include "components/history/core/browser/keyword_id.h" | 35 #include "components/history/core/browser/keyword_id.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 87 |
| 87 // Must call Init after construction. The empty constructor provided only for | 88 // Must call Init after construction. The empty constructor provided only for |
| 88 // unit tests. When using the full constructor, |history_client| may only be | 89 // unit tests. When using the full constructor, |history_client| may only be |
| 89 // null during testing, while |visit_delegate| may be null if the embedder use | 90 // null during testing, while |visit_delegate| may be null if the embedder use |
| 90 // another way to track visited links. | 91 // another way to track visited links. |
| 91 HistoryService(); | 92 HistoryService(); |
| 92 HistoryService(std::unique_ptr<HistoryClient> history_client, | 93 HistoryService(std::unique_ptr<HistoryClient> history_client, |
| 93 std::unique_ptr<VisitDelegate> visit_delegate); | 94 std::unique_ptr<VisitDelegate> visit_delegate); |
| 94 ~HistoryService() override; | 95 ~HistoryService() override; |
| 95 | 96 |
| 97 // When this is called, all HistoryService instances in this process will run |
| 98 // their HistoryBackend tasks on a TaskScheduler sequence rather than on a |
| 99 // dedicated thread. This must be called before instantiating the first |
| 100 // HistoryService in the process. |
| 101 // TODO(fdoray): Remove once the HistoryService redirection experiment |
| 102 // concludes. https://crbug.com/661143 |
| 103 static void RedirectToTaskSchedulerForProcess(); |
| 104 |
| 96 // Initializes the history service, returning true on success. On false, do | 105 // Initializes the history service, returning true on success. On false, do |
| 97 // not call any other functions. The given directory will be used for storing | 106 // not call any other functions. The given directory will be used for storing |
| 98 // the history files. | 107 // the history files. |
| 99 bool Init(const HistoryDatabaseParams& history_database_params) { | 108 bool Init(const HistoryDatabaseParams& history_database_params) { |
| 100 return Init(false, history_database_params); | 109 return Init(false, history_database_params); |
| 101 } | 110 } |
| 102 | 111 |
| 103 // Triggers the backend to load if it hasn't already, and then returns whether | 112 // Triggers the backend to load if it hasn't already, and then returns whether |
| 104 // it's finished loading. | 113 // it's finished loading. |
| 105 // Note: Virtual needed for mocking. | 114 // Note: Virtual needed for mocking. |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 // Called when the favicons for the given page URLs (e.g. | 797 // Called when the favicons for the given page URLs (e.g. |
| 789 // http://www.google.com) and the given icon URL (e.g. | 798 // http://www.google.com) and the given icon URL (e.g. |
| 790 // http://www.google.com/favicon.ico) have changed. It is valid to call | 799 // http://www.google.com/favicon.ico) have changed. It is valid to call |
| 791 // NotifyFaviconsChanged() with non-empty |page_urls| and an empty |icon_url| | 800 // NotifyFaviconsChanged() with non-empty |page_urls| and an empty |icon_url| |
| 792 // and vice versa. | 801 // and vice versa. |
| 793 void NotifyFaviconsChanged(const std::set<GURL>& page_urls, | 802 void NotifyFaviconsChanged(const std::set<GURL>& page_urls, |
| 794 const GURL& icon_url); | 803 const GURL& icon_url); |
| 795 | 804 |
| 796 base::ThreadChecker thread_checker_; | 805 base::ThreadChecker thread_checker_; |
| 797 | 806 |
| 798 // The thread used by the history service to run complicated operations. | 807 // The thread used by the history service to run HistoryBackend operations. |
| 799 // |thread_| is null once Cleanup() is called. | 808 // Intentionally not a BrowserThread because the sync integration unit tests |
| 800 base::Thread* thread_; | 809 // need to create multiple HistoryServices which each have their own thread. |
| 810 // Nullptr if TaskScheduler is used for backend operations. |
| 811 std::unique_ptr<base::Thread> thread_; |
| 812 |
| 813 // The TaskRunner to which HistoryBackend tasks are posted. Nullptr once |
| 814 // Cleanup() is called. |
| 815 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; |
| 801 | 816 |
| 802 // This class has most of the implementation and runs on the 'thread_'. | 817 // This class has most of the implementation and runs on the 'thread_'. |
| 803 // You MUST communicate with this class ONLY through the thread_'s | 818 // You MUST communicate with this class ONLY through the thread_'s |
| 804 // message_loop(). | 819 // message_loop(). |
| 805 // | 820 // |
| 806 // This pointer will be null once Cleanup() has been called, meaning no | 821 // This pointer will be null once Cleanup() has been called, meaning no |
| 807 // more calls should be made to the history thread. | 822 // more calls should be made to the history thread. |
| 808 scoped_refptr<HistoryBackend> history_backend_; | 823 scoped_refptr<HistoryBackend> history_backend_; |
| 809 | 824 |
| 810 // A cache of the user-typed URLs kept in memory that is used by the | 825 // A cache of the user-typed URLs kept in memory that is used by the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 832 | 847 |
| 833 // All vended weak pointers are invalidated in Cleanup(). | 848 // All vended weak pointers are invalidated in Cleanup(). |
| 834 base::WeakPtrFactory<HistoryService> weak_ptr_factory_; | 849 base::WeakPtrFactory<HistoryService> weak_ptr_factory_; |
| 835 | 850 |
| 836 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 851 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
| 837 }; | 852 }; |
| 838 | 853 |
| 839 } // namespace history | 854 } // namespace history |
| 840 | 855 |
| 841 #endif // COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_SERVICE_H_ | 856 #endif // COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_SERVICE_H_ |
| OLD | NEW |