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" | |
28 #include "chrome/common/cancelable_task_tracker.h" | 29 #include "chrome/common/cancelable_task_tracker.h" |
29 #include "chrome/common/ref_counted_util.h" | 30 #include "chrome/common/ref_counted_util.h" |
30 #include "content/public/browser/notification_observer.h" | 31 #include "content/public/browser/notification_observer.h" |
31 #include "content/public/browser/notification_registrar.h" | 32 #include "content/public/browser/notification_registrar.h" |
32 #include "content/public/common/page_transition_types.h" | 33 #include "content/public/common/page_transition_types.h" |
33 #include "sql/init_status.h" | 34 #include "sql/init_status.h" |
34 #include "sync/api/syncable_service.h" | 35 #include "sync/api/syncable_service.h" |
35 #include "ui/base/layout.h" | 36 #include "ui/base/layout.h" |
36 | 37 |
37 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
38 #include "chrome/browser/history/android/android_history_provider_service.h" | 39 #include "chrome/browser/history/android/android_history_provider_service.h" |
39 #endif | 40 #endif |
40 | 41 |
41 class BookmarkService; | 42 class BookmarkService; |
42 class FilePath; | 43 class FilePath; |
43 class GURL; | 44 class GURL; |
44 class HistoryURLProvider; | 45 class HistoryURLProvider; |
45 class PageUsageData; | 46 class PageUsageData; |
46 class PageUsageRequest; | 47 class PageUsageRequest; |
47 class Profile; | 48 class Profile; |
49 class VisitedLinkMaster; | |
48 struct HistoryURLProviderParams; | 50 struct HistoryURLProviderParams; |
49 | 51 |
50 namespace base { | 52 namespace base { |
51 class Thread; | 53 class Thread; |
52 } | 54 } |
53 | 55 |
54 | 56 |
55 namespace history { | 57 namespace history { |
56 | 58 |
57 class HistoryBackend; | 59 class HistoryBackend; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 }; | 102 }; |
101 | 103 |
102 // The history service records page titles, and visit times, as well as | 104 // The history service records page titles, and visit times, as well as |
103 // (eventually) information about autocomplete. | 105 // (eventually) information about autocomplete. |
104 // | 106 // |
105 // This service is thread safe. Each request callback is invoked in the | 107 // This service is thread safe. Each request callback is invoked in the |
106 // thread that made the request. | 108 // thread that made the request. |
107 class HistoryService : public CancelableRequestProvider, | 109 class HistoryService : public CancelableRequestProvider, |
108 public content::NotificationObserver, | 110 public content::NotificationObserver, |
109 public syncer::SyncableService, | 111 public syncer::SyncableService, |
110 public ProfileKeyedService { | 112 public ProfileKeyedService, |
113 public VisitedLinkDelegate { | |
111 public: | 114 public: |
112 // Miscellaneous commonly-used types. | 115 // Miscellaneous commonly-used types. |
113 typedef std::vector<PageUsageData*> PageUsageDataList; | 116 typedef std::vector<PageUsageData*> PageUsageDataList; |
114 | 117 |
115 // Must call Init after construction. | 118 // Must call Init after construction. |
116 explicit HistoryService(Profile* profile); | 119 explicit HistoryService(Profile* profile); |
117 // The empty constructor is provided only for testing. | 120 // The empty constructor is provided only for testing. |
118 HistoryService(); | 121 HistoryService(); |
119 | 122 |
120 virtual ~HistoryService(); | 123 virtual ~HistoryService(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 | 257 |
255 // Indexing ------------------------------------------------------------------ | 258 // Indexing ------------------------------------------------------------------ |
256 | 259 |
257 // Notifies history of the body text of the given recently-visited URL. | 260 // Notifies history of the body text of the given recently-visited URL. |
258 // If the URL was not visited "recently enough," the history system may | 261 // If the URL was not visited "recently enough," the history system may |
259 // discard it. | 262 // discard it. |
260 void SetPageContents(const GURL& url, const string16& contents); | 263 void SetPageContents(const GURL& url, const string16& contents); |
261 | 264 |
262 // Querying ------------------------------------------------------------------ | 265 // Querying ------------------------------------------------------------------ |
263 | 266 |
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 | |
289 // Returns the information about the requested URL. If the URL is found, | 267 // Returns the information about the requested URL. If the URL is found, |
290 // success will be true and the information will be in the URLRow parameter. | 268 // success will be true and the information will be in the URLRow parameter. |
291 // On success, the visits, if requested, will be sorted by date. If they have | 269 // On success, the visits, if requested, will be sorted by date. If they have |
292 // not been requested, the pointer will be valid, but the vector will be | 270 // not been requested, the pointer will be valid, but the vector will be |
293 // empty. | 271 // empty. |
294 // | 272 // |
295 // If success is false, neither the row nor the vector will be valid. | 273 // If success is false, neither the row nor the vector will be valid. |
296 typedef base::Callback<void( | 274 typedef base::Callback<void( |
297 Handle, | 275 Handle, |
298 bool, // Success flag, when false, nothing else is valid. | 276 bool, // Success flag, when false, nothing else is valid. |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 template<typename Info, typename Callback> friend class DownloadRequest; | 644 template<typename Info, typename Callback> friend class DownloadRequest; |
667 friend class PageUsageRequest; | 645 friend class PageUsageRequest; |
668 friend class RedirectRequest; | 646 friend class RedirectRequest; |
669 friend class TestingProfile; | 647 friend class TestingProfile; |
670 | 648 |
671 // Implementation of content::NotificationObserver. | 649 // Implementation of content::NotificationObserver. |
672 virtual void Observe(int type, | 650 virtual void Observe(int type, |
673 const content::NotificationSource& source, | 651 const content::NotificationSource& source, |
674 const content::NotificationDetails& details) OVERRIDE; | 652 const content::NotificationDetails& details) OVERRIDE; |
675 | 653 |
654 // Implementation of VisitedLinkDelegate. | |
655 virtual bool IsEquivalentContext(content::BrowserContext* context1, | |
Jói
2012/12/19 14:07:20
nit: I know I suggested this name, but now that I
boliu
2012/12/29 01:48:12
Done.
| |
656 content::BrowserContext* context2) OVERRIDE; | |
657 virtual void RebuildTable( | |
658 VisitedLinkDelegate::URLEnumerator* enumerator) OVERRIDE; | |
659 | |
676 // Low-level Init(). Same as the public version, but adds a |no_db| parameter | 660 // Low-level Init(). Same as the public version, but adds a |no_db| parameter |
677 // that is only set by unittests which causes the backend to not init its DB. | 661 // that is only set by unittests which causes the backend to not init its DB. |
678 bool Init(const FilePath& history_dir, | 662 bool Init(const FilePath& history_dir, |
679 BookmarkService* bookmark_service, | 663 BookmarkService* bookmark_service, |
680 bool no_db); | 664 bool no_db); |
681 | 665 |
682 // Called by the HistoryURLProvider class to schedule an autocomplete, it | 666 // Called by the HistoryURLProvider class to schedule an autocomplete, it |
683 // will be called back on the internal history thread with the history | 667 // will be called back on the internal history thread with the history |
684 // database so it can query. See history_autocomplete.cc for a diagram. | 668 // database so it can query. See history_autocomplete.cc for a diagram. |
685 void ScheduleAutocomplete(HistoryURLProvider* provider, | 669 void ScheduleAutocomplete(HistoryURLProvider* provider, |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 | 1071 |
1088 // A cache of the user-typed URLs kept in memory that is used by the | 1072 // A cache of the user-typed URLs kept in memory that is used by the |
1089 // autocomplete system. This will be NULL until the database has been created | 1073 // autocomplete system. This will be NULL until the database has been created |
1090 // on the background thread. | 1074 // on the background thread. |
1091 // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 | 1075 // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 |
1092 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; | 1076 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; |
1093 | 1077 |
1094 // The profile, may be null when testing. | 1078 // The profile, may be null when testing. |
1095 Profile* profile_; | 1079 Profile* profile_; |
1096 | 1080 |
1081 // This is null in tests. | |
1082 scoped_ptr<VisitedLinkMaster> visitedlink_master_; | |
1083 | |
1097 // Has the backend finished loading? The backend is loaded once Init has | 1084 // Has the backend finished loading? The backend is loaded once Init has |
1098 // completed. | 1085 // completed. |
1099 bool backend_loaded_; | 1086 bool backend_loaded_; |
1100 | 1087 |
1101 // The id of the current backend. This is only valid when history_backend_ | 1088 // The id of the current backend. This is only valid when history_backend_ |
1102 // is not NULL. | 1089 // is not NULL. |
1103 int current_backend_id_; | 1090 int current_backend_id_; |
1104 | 1091 |
1105 // Cached values from Init(), used whenever we need to reload the backend. | 1092 // Cached values from Init(), used whenever we need to reload the backend. |
1106 FilePath history_dir_; | 1093 FilePath history_dir_; |
1107 BookmarkService* bookmark_service_; | 1094 BookmarkService* bookmark_service_; |
1108 bool no_db_; | 1095 bool no_db_; |
1109 | 1096 |
1110 // True if needs top site migration. | 1097 // True if needs top site migration. |
1111 bool needs_top_sites_migration_; | 1098 bool needs_top_sites_migration_; |
1112 | 1099 |
1113 // The index used for quick history lookups. | 1100 // The index used for quick history lookups. |
1114 // TODO(mrossetti): Move in_memory_url_index out of history_service. | 1101 // TODO(mrossetti): Move in_memory_url_index out of history_service. |
1115 // See http://crbug.com/138321 | 1102 // See http://crbug.com/138321 |
1116 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 1103 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
1117 | 1104 |
1118 ObserverList<history::VisitDatabaseObserver> visit_database_observers_; | 1105 ObserverList<history::VisitDatabaseObserver> visit_database_observers_; |
1119 | 1106 |
1120 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 1107 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
1121 }; | 1108 }; |
1122 | 1109 |
1123 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ | 1110 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ |
OLD | NEW |