1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_HISTORY_CHROME_HISTORY_CLIENT_H_
6 #define CHROME_BROWSER_HISTORY_CHROME_HISTORY_CLIENT_H_
8 #include "base/macros.h"
9 #include "components/history/core/browser/history_client.h"
10 #include "components/history/core/browser/history_service_observer.h"
11 #include "components/history/core/browser/top_sites_observer.h"
21 // This class implements history::HistoryClient to abstract operations that
22 // depend on Chrome environment.
23 class ChromeHistoryClient : public history::HistoryClient,
24 public history::HistoryServiceObserver,
25 public history::TopSitesObserver {
27 explicit ChromeHistoryClient(BookmarkModel* bookmark_model,
29 history::TopSites* top_sites);
30 ~ChromeHistoryClient() override;
32 // TODO(sdefresne): once NOTIFICATION_HISTORY_URL* notifications are no
33 // longer used, remove this reference to the HistoryService from the
34 // ChromeHistoryClient, http://crbug.com/373326
35 void SetHistoryService(HistoryService* history_service);
37 // history::HistoryClient:
38 void BlockUntilBookmarksLoaded() override;
39 bool IsBookmarked(const GURL& url) override;
40 void GetBookmarks(std::vector<history::URLAndTitle>* bookmarks) override;
41 void NotifyProfileError(sql::InitStatus init_status) override;
42 bool ShouldReportDatabaseError() override;
45 void Shutdown() override;
48 void TopSitesLoaded(history::TopSites* top_sites) override;
49 void TopSitesChanged(history::TopSites* top_sites) override;
52 // The BookmarkModel, this should outlive ChromeHistoryClient.
53 BookmarkModel* bookmark_model_;
55 HistoryService* history_service_;
56 // The TopSites object is owned by the Profile (see
57 // chrome/browser/profiles/profile_impl.h)
58 // and lazily constructed by the getter.
59 // ChromeHistoryClient is a KeyedService linked to the Profile lifetime by the
60 // ChromeHistoryClientFactory (which is a BrowserContextKeyedServiceFactory).
61 // Before the Profile is destroyed, all the KeyedService Shutdown methods are
62 // called, and the Profile is fully constructed before any of the KeyedService
63 // can be constructed. The TopSites does not use the HistoryService nor the
64 // HistoryClient during construction (it uses it later, but supports getting
66 history::TopSites* top_sites_;
68 DISALLOW_COPY_AND_ASSIGN(ChromeHistoryClient);
71 #endif // CHROME_BROWSER_HISTORY_CHROME_HISTORY_CLIENT_H_