Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: chrome/browser/history/history_service.h

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

Powered by Google App Engine
This is Rietveld 408576698