#include "base/gtest_prod_util.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
#include "base/single_thread_task_runner.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/history/expire_history_backend.h"
class CommitLaterTask;
struct DownloadRow;
+class HistoryBackendObserver;
class HistoryClient;
+struct HistoryDetails;
class HistoryDBTask;
class InMemoryHistoryBackend;
class TypedUrlSyncableService;
// functions in the history service. These functions are not documented
// here, see the history service for behavior.
class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
- public BroadcastNotificationDelegate {
+ public ExpireHistoryBackendDelegate {
public:
// Interface implemented by the owner of the HistoryBackend object. Normally,
// the history service implements this to send stuff back to the main thread.
virtual void SetInMemoryBackend(
scoped_ptr<InMemoryHistoryBackend> backend) = 0;
+ // Notify HistoryService that VisitDatabase was changed. The event will be
+ // forwarded to the history::HistoryServiceObservers in the UI thread.
+ virtual void NotifyAddVisit(const BriefVisitInfo& info) = 0;
+
// Notify HistoryService that some URLs favicon changed that will forward
// the events to the FaviconChangedObservers in the correct thread.
virtual void NotifyFaviconChanged(const std::set<GURL>& urls) = 0;
+ // Notify HistoryService that the user is visiting an URL. The event will
+ // be forwarded to the HistoryServiceObservers in the correct thread.
+ virtual void NotifyURLVisited(ui::PageTransition transition,
+ const URLRow& row,
+ const RedirectList& redirects,
+ base::Time visit_time) = 0;
+
// Broadcasts the specified notification to the notification service.
// This is implemented here because notifications must only be sent from
// the main thread. This is the only method that doesn't identify the
// Invoked when the backend has finished loading the db.
virtual void DBLoaded() = 0;
-
- virtual void NotifyVisitDBObserversOnAddVisit(
- const history::BriefVisitInfo& info) = 0;
};
// Init must be called to complete object creation. This object can be
void DeleteMatchingURLsForKeyword(KeywordID keyword_id,
const base::string16& term);
+ // Observers -----------------------------------------------------------------
+
+ void AddObserver(HistoryBackendObserver* observer);
+ void RemoveObserver(HistoryBackendObserver* observer);
+
#if defined(OS_ANDROID)
// Android Provider ---------------------------------------------------------
}
protected:
- virtual ~HistoryBackend();
+ ~HistoryBackend() override;
+
+ // Notify HistoryBackendObserver that |transition| to |row| occurred at
+ // |visit_time| following |redirects| (empty if there is no redirects).
+ void NotifyURLVisited(ui::PageTransition transition,
+ const URLRow& row,
+ const RedirectList& redirects,
+ base::Time visit_time);
private:
friend class base::RefCountedThreadSafe<HistoryBackend>;
// to be invoked again if there are more tasks that need to run.
void ProcessDBTaskImpl();
- virtual void BroadcastNotifications(
- int type,
- scoped_ptr<HistoryDetails> details) OVERRIDE;
- virtual void NotifySyncURLsModified(URLRows* rows) OVERRIDE;
- virtual void NotifySyncURLsDeleted(bool all_history,
- bool expired,
- URLRows* rows) OVERRIDE;
+ // Broadcasts the specified notification to the notification service on both
+ // the main thread and the history thread if a notification service is
+ // running.
+ void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details);
+
+ // ExpireHistoryBackendDelegate:
+ void NotifyURLsModified(const URLRows& rows) override;
+ void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const URLRows& rows,
+ const std::set<GURL>& favicon_urls) override;
// Deleting all history ------------------------------------------------------
// Used to manage syncing of the typed urls datatype. This will be NULL
// before Init is called.
+ // TODO(sdefresne): turn TypedUrlSyncableService into a HistoryBackendObserver
+ // and remove this field since it is only used for forwarding notifications
+ // about URL visited, modified, deleted.
scoped_ptr<TypedUrlSyncableService> typed_url_syncable_service_;
// Listens for the system being under memory pressure.
scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_;
+ // List of observers
+ ObserverList<HistoryBackendObserver> observers_;
+
DISALLOW_COPY_AND_ASSIGN(HistoryBackend);
};