history_service.h revision 116680a4aac90f2aa7413d9095a592090648e557
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/bind.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/logging.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/weak_ptr.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/observer_list.h"
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/task/cancelable_task_tracker.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/thread_checker.h"
23eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/common/cancelable_request.h"
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/history/delete_directive_handler.h"
26b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chrome/browser/history/typed_url_syncable_service.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/ref_counted_util.h"
28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/favicon_base/favicon_callback.h"
2946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "components/history/core/browser/history_client.h"
30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/history/core/browser/keyword_id.h"
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/core/keyed_service.h"
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "components/visitedlink/browser/visitedlink_delegate.h"
337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "content/public/browser/download_manager_delegate.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_transition_types.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sql/init_status.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sync/api/syncable_service.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_ANDROID)
41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class AndroidHistoryProviderService;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PageUsageData;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PageUsageRequest;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile;
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)struct ImportedFaviconUsage;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Thread;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace visitedlink {
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class VisitedLinkMaster;
5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace history {
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryBackend;
62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class HistoryClient;
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryDatabase;
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class HistoryDBTask;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryQueryTest;
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InMemoryHistoryBackend;
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InMemoryURLIndex;
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InMemoryURLIndexTest;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLDatabase;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VisitDatabaseObserver;
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class VisitFilter;
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct DownloadRow;
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct HistoryAddPageArgs;
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct HistoryDetails;
75116680a4aac90f2aa7413d9095a592090648e557Ben Murdochstruct KeywordSearchTermVisit;
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace history
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The history service records page titles, and visit times, as well as
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (eventually) information about autocomplete.
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This service is thread safe. Each request callback is invoked in the
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// thread that made the request.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryService : public CancelableRequestProvider,
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       public content::NotificationObserver,
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       public syncer::SyncableService,
87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                       public KeyedService,
8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                       public visitedlink::VisitedLinkDelegate {
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Miscellaneous commonly-used types.
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef std::vector<PageUsageData*> PageUsageDataList;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
93cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Must call Init after construction. The |history::HistoryClient| object
94cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // must be valid for the whole lifetime of |HistoryService|.
95cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  explicit HistoryService(history::HistoryClient* client, Profile* profile);
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The empty constructor is provided only for testing.
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HistoryService();
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~HistoryService();
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initializes the history service, returning true on success. On false, do
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not call any other functions. The given directory will be used for storing
10346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // the history files.
10446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  bool Init(const base::FilePath& history_dir) {
10546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return Init(history_dir, false);
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Triggers the backend to load if it hasn't already, and then returns whether
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it's finished loading.
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note: Virtual needed for mocking.
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool BackendLoaded();
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the backend has finished loading.
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool backend_loaded() const { return backend_loaded_; }
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called on shutdown, this will tell the history backend to complete and
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will release pointers to it. No other functions should be called once
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cleanup has happened that may dispatch to the history thread (because it
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be NULL).
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // In practice, this will be called by the service manager (BrowserProcess)
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // when it is being destroyed. Because that reference is being destroyed, it
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // should be impossible for anybody else to call the service, even if it is
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // still in memory (pending requests may be holding a reference to us).
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Cleanup();
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
127f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Context ids are used to scope page IDs (see AddPage). These contexts
128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // must tell us when they are being invalidated so that we can clear
129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // out any cached data associated with that context.
130f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void ClearCachedDataForContextID(history::ContextID context_id);
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Triggers the backend to load if it hasn't already, and then returns the
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in-memory URL database. The returned pointer MAY BE NULL if the in-memory
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // database has not been loaded yet. This pointer is owned by the history
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // system. Callers should not store or cache this value.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(brettw) this should return the InMemoryHistoryBackend.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  history::URLDatabase* InMemoryDatabase();
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Following functions get URL information from in-memory database.
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // They return false if database is not available (e.g. not loaded yet) or the
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL does not exist.
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads the number of times the user has typed the given URL.
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetTypedCountForURL(const GURL& url, int* typed_count);
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads the last visit time for the given URL.
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetLastVisitTimeForURL(const GURL& url, base::Time* last_visit);
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads the number of times this URL has been visited.
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetVisitCountForURL(const GURL& url, int* visit_count);
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
153b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Returns a pointer to the TypedUrlSyncableService owned by HistoryBackend.
154b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // This method should only be called from the history thread, because the
155b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // returned service is intended to be accessed only via the history thread.
156b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  history::TypedUrlSyncableService* GetTypedUrlSyncableService() const;
157b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return the quick history index.
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  history::InMemoryURLIndex* InMemoryIndex() const {
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return in_memory_url_index_.get();
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
163a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // KeyedService:
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Shutdown() OVERRIDE;
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Navigation ----------------------------------------------------------------
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds the given canonical URL to history with the given time as the visit
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // time. Referrer may be the empty string.
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
171f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // The supplied context id is used to scope the given page ID. Page IDs
172f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // are only unique inside a given context, so we need that to differentiate
173f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // them.
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
175f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // The context/page ids can be NULL if there is no meaningful tracking
176f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // information that can be performed on the given URL. The 'page_id' should
177f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // be the ID of the current session history entry in the given process.
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 'redirects' is an array of redirect URLs leading to this page, with the
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // page itself as the last item (so when there is no redirect, it will have
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // one entry). If there are no redirects, this array may also be empty for
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the convenience of callers.
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 'did_replace_entry' is true when the navigation entry for this page has
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // replaced the existing entry. A non-user initiated redirect causes such
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // replacement.
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All "Add Page" functions will update the visited link database.
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPage(const GURL& url,
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               base::Time time,
191f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)               history::ContextID context_id,
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               int32 page_id,
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               const GURL& referrer,
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               const history::RedirectList& redirects,
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               content::PageTransition transition,
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               history::VisitSource visit_source,
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               bool did_replace_entry);
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For adding pages to history where no tracking information can be done.
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPage(const GURL& url,
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               base::Time time,
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               history::VisitSource visit_source);
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All AddPage variants end up here.
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPage(const history::HistoryAddPageArgs& add_page_args);
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds an entry for the specified url without creating a visit. This should
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // only be used when bookmarking a page, otherwise the row leaks in the
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history db (it never gets cleaned).
210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void AddPageNoVisitForBookmark(const GURL& url, const base::string16& title);
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the title for the given page. The page should be in history. If it
213f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // is not, this operation is ignored.
214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void SetPageTitle(const GURL& url, const base::string16& title);
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Updates the history database with a page's ending time stamp information.
217f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // The page can be identified by the combination of the context id, the page
218f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // id and the url.
219f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void UpdateWithPageEndTime(history::ContextID context_id,
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             int32 page_id,
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const GURL& url,
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             base::Time end_ts);
22368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Querying ------------------------------------------------------------------
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the information about the requested URL. If the URL is found,
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // success will be true and the information will be in the URLRow parameter.
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // On success, the visits, if requested, will be sorted by date. If they have
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not been requested, the pointer will be valid, but the vector will be
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // empty.
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If success is false, neither the row nor the vector will be valid.
233f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  typedef base::Callback<
234f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      void(bool,  // Success flag, when false, nothing else is valid.
235f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)           const history::URLRow&,
236f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)           const history::VisitVector&)> QueryURLCallback;
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Queries the basic information about the URL in the history database. If
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the caller is interested in the visits (each time the URL is visited),
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // set |want_visits| to true. If these are not needed, the function will be
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // faster by setting this to false.
242f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  base::CancelableTaskTracker::TaskId QueryURL(
243f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const GURL& url,
244f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      bool want_visits,
245f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const QueryURLCallback& callback,
246f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Provides the result of a query. See QueryResults in history_types.h.
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The common use will be to use QueryResults.Swap to suck the contents of
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the results out of the passed in parameter and take ownership of them.
251116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  typedef base::Callback<void(history::QueryResults*)> QueryHistoryCallback;
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Queries all history with the given options (see QueryOptions in
254f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // history_types.h).  If empty, all results matching the given options
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be returned.
256116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryHistory(
257116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const base::string16& text_query,
258116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const history::QueryOptions& options,
259116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryHistoryCallback& callback,
260116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when the results of QueryRedirectsFrom are available.
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The given vector will contain a list of all redirects, not counting
264a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the original page. If A redirects to B which redirects to C, the vector
265a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // will contain [B, C], and A will be in 'from_url'.
266a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  //
267a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // For QueryRedirectsTo, the order is reversed. For A->B->C, the vector will
268a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // contain [B, A] and C will be in 'to_url'.
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If there is no such URL in the database or the most recent visit has no
271116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // redirect, the vector will be empty. If the given page has redirected to
272116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // multiple destinations, this will pick a random one.
273116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  typedef base::Callback<void(const history::RedirectList*)>
274116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      QueryRedirectsCallback;
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Schedules a query for the most recent redirect coming out of the given
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL. See the RedirectQuerySource above, which is guaranteed to be called
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if the request is not canceled.
279116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryRedirectsFrom(
280116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const GURL& from_url,
281116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryRedirectsCallback& callback,
282116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Schedules a query to get the most recent redirects ending at the given
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL.
286116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryRedirectsTo(
287116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const GURL& to_url,
288116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryRedirectsCallback& callback,
289116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Requests the number of user-visible visits (i.e. no redirects or subframes)
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to all urls on the same scheme/host/port as |url|.  This is only valid for
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HTTP and HTTPS URLs.
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<
295116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      void(bool,         // Were we able to determine the # of visits?
296116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch           int,          // Number of visits.
297116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch           base::Time)>  // Time of first visit. Only set if bool
298116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                         // is true and int is > 0.
299116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      GetVisibleVisitCountToHostCallback;
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
301116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId GetVisibleVisitCountToHost(
302116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const GURL& url,
303116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const GetVisibleVisitCountToHostCallback& callback,
304116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Request the |result_count| most visited URLs and the chain of
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // redirects leading to each of these URLs. |days_back| is the
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // number of days of history to use. Used by TopSites.
309116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  typedef base::Callback<void(const history::MostVisitedURLList*)>
310116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      QueryMostVisitedURLsCallback;
311116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
312116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryMostVisitedURLs(
313116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      int result_count,
314116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      int days_back,
315116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryMostVisitedURLsCallback& callback,
316116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Request the |result_count| URLs filtered and sorted based on the |filter|.
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |extended_info| is true, additional data will be provided in the
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // results. Computing this additional data is expensive, likely to become
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // more expensive as additional data points are added in future changes, and
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not useful in most cases. Set |extended_info| to true only if you
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // explicitly require the additional data.
324116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  typedef base::Callback<void(const history::FilteredURLList*)>
325116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      QueryFilteredURLsCallback;
326116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
327116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryFilteredURLs(
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int result_count,
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const history::VisitFilter& filter,
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bool extended_info,
331116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryFilteredURLsCallback& callback,
332116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Database management operations --------------------------------------------
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete all the information related to a single url.
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteURL(const GURL& url);
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete all the information related to a list of urls.  (Deleting
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URLs one by one is slow as it has to flush to disk each time.)
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteURLsForTest(const std::vector<GURL>& urls);
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
343f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Removes all visits in the selected time range (including the
344f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // start time), updating the URLs accordingly. This deletes any
345f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // associated data. This function also deletes the associated
346f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // favicons, if they are no longer referenced. |callback| runs when
347f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // the expiration is complete. You may use null Time values to do an
348f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // unbounded delete in either direction.
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |restrict_urls| is not empty, only visits to the URLs in this set are
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // removed.
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ExpireHistoryBetween(const std::set<GURL>& restrict_urls,
3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                            base::Time begin_time,
3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                            base::Time end_time,
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                            const base::Closure& callback,
3555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                            base::CancelableTaskTracker* tracker);
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Removes all visits to specified URLs in specific time ranges.
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This is the equivalent ExpireHistoryBetween() once for each element in the
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // vector. The fields of |ExpireHistoryArgs| map directly to the arguments of
3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // of ExpireHistoryBetween().
3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void ExpireHistory(const std::vector<history::ExpireHistoryArgs>& expire_list,
3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                     const base::Closure& callback,
3635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     base::CancelableTaskTracker* tracker);
3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Removes all visits to the given URLs in the specified time range. Calls
3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ExpireHistoryBetween() to delete local visits, and handles deletion of
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // synced visits if appropriate.
3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void ExpireLocalAndRemoteHistoryBetween(const std::set<GURL>& restrict_urls,
3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          base::Time begin_time,
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          base::Time end_time,
3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          const base::Closure& callback,
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          base::CancelableTaskTracker* tracker);
3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Processes the given |delete_directive| and sends it to the
3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // SyncChangeProcessor (if it exists).  Returns any error resulting
3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // from sending the delete directive to sync.
3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  syncer::SyncError ProcessLocalDeleteDirective(
3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive);
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
380116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Importer ------------------------------------------------------------------
381116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
382116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Used by the ProfileWriter for importing many favicons for many pages at
383116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // once. The pages must exist, any favicon sets for unknown pages will be
384116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // discarded. Existing favicons will not be overwritten.
385116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void SetImportedFavicons(
386116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const std::vector<ImportedFaviconUsage>& favicon_usage);
387116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Downloads -----------------------------------------------------------------
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Implemented by the caller of 'CreateDownload' below, and is called when the
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history service has created a new entry for a download in the history db.
3927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  typedef base::Callback<void(bool)> DownloadCreateCallback;
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Begins a history request to create a new row for a download. 'info'
3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // contains all the download's creation state, and 'callback' runs when the
3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // history service request is complete. The callback is called on the thread
3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // that calls CreateDownload().
3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void CreateDownload(
3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const history::DownloadRow& info,
4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const DownloadCreateCallback& callback);
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Responds on the calling thread with the maximum id of all downloads records
4037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // in the database plus 1.
4047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void GetNextDownloadId(const content::DownloadIdCallback& callback);
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Implemented by the caller of 'QueryDownloads' below, and is called when the
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history service has retrieved a list of all download state. The call
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(
4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      scoped_ptr<std::vector<history::DownloadRow> >)>
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          DownloadQueryCallback;
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Begins a history request to retrieve the state of all downloads in the
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history db. 'callback' runs when the history service request is complete,
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // at which point 'info' contains an array of history::DownloadRow, one per
4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // download. The callback is called on the thread that calls QueryDownloads().
4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void QueryDownloads(const DownloadQueryCallback& callback);
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to update the history service about the current state of a download.
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This is a 'fire and forget' query, so just pass the relevant state info to
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the database with no need for a callback.
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void UpdateDownload(const history::DownloadRow& data);
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Permanently remove some downloads from the history system. This is a 'fire
4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // and forget' operation.
4257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void RemoveDownloads(const std::set<uint32>& ids);
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Keyword search terms -----------------------------------------------------
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the search terms for the specified url and keyword. url_id gives the
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // id of the url, keyword_id the id of the keyword and term the search term.
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetKeywordSearchTermsForURL(const GURL& url,
432116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                   history::KeywordID keyword_id,
433a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                   const base::string16& term);
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deletes all search terms for the specified keyword.
436116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void DeleteAllSearchTermsForKeyword(history::KeywordID keyword_id);
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Deletes any search term corresponding to |url|.
4390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  void DeleteKeywordSearchTermForURL(const GURL& url);
4400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
4415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Deletes all URL and search term entries matching the given |term| and
4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |keyword_id|.
443116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void DeleteMatchingURLsForKeyword(history::KeywordID keyword_id,
4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                    const base::string16& term);
4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Bookmarks -----------------------------------------------------------------
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notification that a URL is no longer bookmarked.
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void URLsNoLongerBookmarked(const std::set<GURL>& urls);
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Generic Stuff -------------------------------------------------------------
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Schedules a HistoryDBTask for running on the history backend thread. See
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HistoryDBTask for details on what this does.
455116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void ScheduleDBTask(scoped_refptr<history::HistoryDBTask> task,
456116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                              base::CancelableTaskTracker* tracker);
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes observers for the VisitDatabase.
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddVisitDatabaseObserver(history::VisitDatabaseObserver* observer);
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RemoveVisitDatabaseObserver(history::VisitDatabaseObserver* observer);
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyVisitDBObserversOnAddVisit(const history::BriefVisitInfo& info);
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Testing -------------------------------------------------------------------
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Runs |flushed| after bouncing off the history thread.
4677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void FlushForTest(const base::Closure& flushed);
4687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Designed for unit tests, this passes the given task on to the history
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // backend to be called once the history backend has terminated. This allows
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // callers to know when the history thread is complete and the database files
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // can be deleted and the next test run. Otherwise, the history thread may
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // still be running, causing problems in subsequent tests.
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // There can be only one closing task, so this will override any previously
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // set task. We will take ownership of the pointer and delete it when done.
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The task will be run on the calling thread (this function is threadsafe).
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetOnBackendDestroyTask(const base::Closure& task);
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used for unit testing and potentially importing to get known information
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // into the database. This assumes the URL doesn't exist in the database
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Calling this function many times may be slow because each call will
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // dispatch to the history thread and will be a separate database
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // transaction. If this functionality is needed for importing many URLs,
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // callers should use AddPagesWithDetails() instead.
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note that this routine (and AddPageWithDetails()) always adds a single
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // visit using the |last_visit| timestamp, and a PageTransition type of LINK,
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if |visit_source| != SYNCED.
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPageWithDetails(const GURL& url,
492a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                          const base::string16& title,
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          int visit_count,
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          int typed_count,
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          base::Time last_visit,
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          bool hidden,
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          history::VisitSource visit_source);
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The same as AddPageWithDetails() but takes a vector.
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPagesWithDetails(const history::URLRows& info,
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           history::VisitSource visit_source);
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if this looks like the type of URL we want to add to the
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history. We filter out some URLs such as JavaScript.
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool CanAddURL(const GURL& url);
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
507cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns the HistoryClient.
508cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  history::HistoryClient* history_client() { return history_client_; }
509cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::WeakPtr<HistoryService> AsWeakPtr();
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // syncer::SyncableService implementation.
5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      syncer::ModelType type,
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const syncer::SyncDataList& initial_sync_data,
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual syncer::SyncDataList GetAllSyncData(
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      syncer::ModelType type) const OVERRIDE;
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual syncer::SyncError ProcessSyncChanges(
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const tracked_objects::Location& from_here,
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const syncer::SyncChangeList& change_list) OVERRIDE;
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // These are not currently used, hopefully we can do something in the future
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to ensure that the most important things happen first.
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum SchedulePriority {
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PRIORITY_UI,      // The highest priority (must respond to UI events).
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PRIORITY_NORMAL,  // Normal stuff like adding a page.
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PRIORITY_LOW,     // Low priority things like indexing or expiration.
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class BackendDelegate;
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_ANDROID)
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class AndroidHistoryProviderService;
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class base::RefCountedThreadSafe<HistoryService>;
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class BackendDelegate;
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class FaviconService;
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class history::HistoryBackend;
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class history::HistoryQueryTest;
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class HistoryOperation;
5457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  friend class HistoryQuickProviderTest;
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class HistoryURLProvider;
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class HistoryURLProviderTest;
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class history::InMemoryURLIndexTest;
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename Info, typename Callback> friend class DownloadRequest;
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class PageUsageRequest;
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class RedirectRequest;
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class TestingProfile;
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Implementation of content::NotificationObserver.
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Observe(int type,
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationSource& source,
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Implementation of visitedlink::VisitedLinkDelegate.
5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RebuildTable(
5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Low-level Init().  Same as the public version, but adds a |no_db| parameter
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that is only set by unittests which causes the backend to not init its DB.
56546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  bool Init(const base::FilePath& history_dir, bool no_db);
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the HistoryURLProvider class to schedule an autocomplete, it
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be called back on the internal history thread with the history
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // database so it can query. See history_autocomplete.cc for a diagram.
570116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void ScheduleAutocomplete(const base::Callback<
571116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      void(history::HistoryBackend*, history::URLDatabase*)>& callback);
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Broadcasts the given notification. This is called by the backend so that
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the notification will be broadcast on the main thread.
575a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void BroadcastNotificationsHelper(
576a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      int type,
577a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      scoped_ptr<history::HistoryDetails> details);
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notification from the backend that it has finished loading. Sends
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true.
581a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void OnDBLoaded();
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper function for getting URL information.
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads a URLRow from in-memory database. Returns false if database is not
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // available or the URL does not exist.
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetRowForURL(const GURL& url, history::URLRow* url_row);
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Favicon -------------------------------------------------------------------
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // These favicon methods are exposed to the FaviconService. Instead of calling
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // these methods directly you should call the respective method on the
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // FaviconService.
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by FaviconService to get the favicon bitmaps from the history backend
5956d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // whose edge sizes most closely match |desired_sizes| for |icon_types|. If
5966d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |desired_sizes| has a '0' entry, the largest favicon bitmap for
5976d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |icon_types| is returned. The returned FaviconBitmapResults will have at
5986d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // most one result for each entry in |desired_sizes|. If a favicon bitmap is
5996d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // determined to be the best candidate for multiple |desired_sizes| there will
6006d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // be fewer results.
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |icon_types| has several types, results for only a single type will be
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // FAVICON.
6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId GetFavicons(
6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const std::vector<GURL>& icon_urls,
6062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int icon_types,
6076d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      const std::vector<int>& desired_sizes,
608cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const favicon_base::FaviconResultsCallback& callback,
6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to get favicons mapped to |page_url| for
6126d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |icon_types| whose edge sizes most closely match |desired_sizes|. If
6136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |desired_sizes| has a '0' entry, the largest favicon bitmap for
6146d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |icon_types| is returned. The returned FaviconBitmapResults will have at
6156d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // most one result for each entry in |desired_sizes|. If a favicon bitmap is
6166d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // determined to be the best candidate for multiple |desired_sizes| there
6176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // will be fewer results. If |icon_types| has several types, results for only
6186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // a single type will be returned in the priority of TOUCH_PRECOMPOSED_ICON,
6196d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // TOUCH_ICON, and FAVICON.
6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId GetFaviconsForURL(
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& page_url,
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int icon_types,
6236d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      const std::vector<int>& desired_sizes,
624cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const favicon_base::FaviconResultsCallback& callback,
6255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Used by FaviconService to find the first favicon bitmap whose width and
6288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // height are greater than that of |minimum_size_in_pixels|. This searches
6298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // for icons by IconType. Each element of |icon_types| is a bitmask of
6308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // IconTypes indicating the types to search for.
6318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // If the largest icon of |icon_types[0]| is not larger than
6328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // |minimum_size_in_pixel|, the next icon types of
6338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // |icon_types| will be searched and so on.
6348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // If no icon is larger than |minimum_size_in_pixel|, the largest one of all
6358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // icon types in |icon_types| is returned.
636116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // This feature is especially useful when some types of icon is preferred as
6378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // long as its size is larger than a specific value.
6385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId GetLargestFaviconForURL(
6398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const GURL& page_url,
6408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const std::vector<int>& icon_types,
6418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      int minimum_size_in_pixels,
642f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const favicon_base::FaviconRawBitmapCallback& callback,
6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to get the favicon bitmap which most closely
6466d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // matches |desired_size| from the favicon with |favicon_id| from the history
6476d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // backend. If |desired_size| is 0, the largest favicon bitmap for
6486d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |favicon_id| is returned.
6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId GetFaviconForID(
6500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      favicon_base::FaviconID favicon_id,
6516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      int desired_size,
652cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const favicon_base::FaviconResultsCallback& callback,
6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to replace the favicon mappings to |page_url|
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for |icon_types| on the history backend.
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sample |icon_urls|:
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  { ICON_URL1 -> TOUCH_ICON, known to the database,
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    ICON_URL2 -> TOUCH_ICON, not known to the database,
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database }
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The new mappings are computed from |icon_urls| with these rules:
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 1) Any urls in |icon_urls| which are not already known to the database are
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    rejected.
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 }
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 2) If |icon_types| has multiple types, the mappings are only set for the
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    largest icon type.
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    Sample new mappings to |page_url|: { ICON_URL3 }
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |icon_types| can only have multiple IconTypes if
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON.
6706d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // The favicon bitmaps whose edge sizes most closely match |desired_sizes|
6716d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // from the favicons which were just mapped to |page_url| are returned. If
6726d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |desired_sizes| has a '0' entry, the largest favicon bitmap is returned.
6735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch(
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& page_url,
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::vector<GURL>& icon_urls,
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int icon_types,
6776d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      const std::vector<int>& desired_sizes,
678cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const favicon_base::FaviconResultsCallback& callback,
6795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Used by FaviconService to set a favicon for |page_url| and |icon_url| with
6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |pixel_size|.
6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Example:
6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //   |page_url|: www.google.com
6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // 2 favicons in history for |page_url|:
6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //   www.google.com/a.ico  16x16
6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //   www.google.com/b.ico  32x32
6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // MergeFavicon(|page_url|, www.google.com/a.ico, ..., ..., 16x16)
6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Merging occurs in the following manner:
6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // 1) |page_url| is set to map to only to |icon_url|. In order to not lose
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    data, favicon bitmaps mapped to |page_url| but not to |icon_url| are
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    copied to the favicon at |icon_url|.
6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    For the example above, |page_url| will only be mapped to a.ico.
6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    The 32x32 favicon bitmap at b.ico is copied to a.ico
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // 2) |bitmap_data| is added to the favicon at |icon_url|, overwriting any
6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    favicon bitmaps of |pixel_size|.
6982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    For the example above, |bitmap_data| overwrites the 16x16 favicon
6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    bitmap for a.ico.
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(pkotwicz): Remove once no longer required by sync.
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void MergeFavicon(const GURL& page_url,
7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                    const GURL& icon_url,
7030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                    favicon_base::IconType icon_type,
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    scoped_refptr<base::RefCountedMemory> bitmap_data,
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const gfx::Size& pixel_size);
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to set the favicons for a page on the history
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // backend.
7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |favicon_bitmap_data| replaces all the favicon bitmaps mapped to
7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |page_url|.
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |expired| and |icon_type| fields in FaviconBitmapData are ignored.
7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Use MergeFavicon() if |favicon_bitmap_data| is incomplete, and favicon
7132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // bitmaps in the database should be preserved if possible. For instance,
7142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // favicon bitmaps from sync are 1x only. MergeFavicon() is used to avoid
7152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // deleting the 2x favicon bitmap if it is present in the history backend.
7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // See HistoryBackend::ValidateSetFaviconsParams() for more details on the
7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // criteria for |favicon_bitmap_data| to be valid.
718f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SetFavicons(const GURL& page_url,
719f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                   favicon_base::IconType icon_type,
720f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                   const std::vector<favicon_base::FaviconRawBitmapData>&
721f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                       favicon_bitmap_data);
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to mark the favicon for the page as being out
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // of date.
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetFaviconsOutOfDateForPage(const GURL& page_url);
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to clone favicons from one page to another,
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // provided that other page does not already have favicons.
7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url);
7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the in-memory URL database. This is called by the backend once the
7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // database is loaded to make it available.
733eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void SetInMemoryBackend(
734eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<history::InMemoryHistoryBackend> mem_backend);
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by our BackendDelegate when there is a problem reading the database.
737a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void NotifyProfileError(sql::InitStatus init_status);
7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Call to schedule a given task for running on the history thread with the
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // specified priority. The task will have ownership taken.
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleTask(SchedulePriority priority, const base::Closure& task);
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Schedule ------------------------------------------------------------------
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Functions for scheduling operations on the history thread that have a
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // handle and may be cancelable. For fire-and-forget operations, see
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ScheduleAndForget below.
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc, class RequestType>
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Handle Schedule(SchedulePriority priority,
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  BackendFunc func,  // Function to call on the HistoryBackend.
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  CancelableRequestConsumerBase* consumer,
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  RequestType* request) {
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (consumer)
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      AddRequest(request, consumer);
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority,
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 base::Bind(func, history_backend_.get(),
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            scoped_refptr<RequestType>(request)));
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return request->handle();
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc, class RequestType, typename ArgA>
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Handle Schedule(SchedulePriority priority,
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  BackendFunc func,  // Function to call on the HistoryBackend.
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  CancelableRequestConsumerBase* consumer,
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  RequestType* request,
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgA& a) {
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (consumer)
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      AddRequest(request, consumer);
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority,
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 base::Bind(func, history_backend_.get(),
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            scoped_refptr<RequestType>(request), a));
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return request->handle();
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc,
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           class RequestType,  // Descendant of CancelableRequestBase.
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgA,
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgB>
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Handle Schedule(SchedulePriority priority,
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  BackendFunc func,  // Function to call on the HistoryBackend.
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  CancelableRequestConsumerBase* consumer,
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  RequestType* request,
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgA& a,
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgB& b) {
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (consumer)
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      AddRequest(request, consumer);
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority,
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 base::Bind(func, history_backend_.get(),
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            scoped_refptr<RequestType>(request), a, b));
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return request->handle();
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc,
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           class RequestType,  // Descendant of CancelableRequestBase.
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgA,
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgB,
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgC>
8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Handle Schedule(SchedulePriority priority,
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  BackendFunc func,  // Function to call on the HistoryBackend.
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  CancelableRequestConsumerBase* consumer,
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  RequestType* request,
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgA& a,
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgB& b,
8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgC& c) {
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (consumer)
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      AddRequest(request, consumer);
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority,
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 base::Bind(func, history_backend_.get(),
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            scoped_refptr<RequestType>(request), a, b, c));
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return request->handle();
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc,
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           class RequestType,  // Descendant of CancelableRequestBase.
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgA,
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgB,
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgC,
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgD>
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Handle Schedule(SchedulePriority priority,
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  BackendFunc func,  // Function to call on the HistoryBackend.
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  CancelableRequestConsumerBase* consumer,
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  RequestType* request,
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgA& a,
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgB& b,
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgC& c,
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  const ArgD& d) {
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (consumer)
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      AddRequest(request, consumer);
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority,
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 base::Bind(func, history_backend_.get(),
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            scoped_refptr<RequestType>(request), a, b, c, d));
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return request->handle();
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ScheduleAndForget ---------------------------------------------------------
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Functions for scheduling operations on the history thread that do not need
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // any callbacks and are not cancelable.
8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc>
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func) {  // Function to call on backend.
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get()));
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc, typename ArgA>
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a) {
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(), a));
8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc, typename ArgA, typename ArgB>
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a,
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgB& b) {
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(), a, b));
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc, typename ArgA, typename ArgB, typename ArgC>
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a,
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgB& b,
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgC& c) {
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(), a, b, c));
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc,
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgA,
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgB,
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgC,
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgD>
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a,
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgB& b,
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgC& c,
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgD& d) {
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(),
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      a, b, c, d));
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc,
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgA,
9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgB,
9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgC,
9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgD,
9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgE>
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a,
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgB& b,
9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgC& c,
9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgD& d,
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgE& e) {
9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(),
9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      a, b, c, d, e));
9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All vended weak pointers are invalidated in Cleanup().
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::WeakPtrFactory<HistoryService> weak_ptr_factory_;
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::ThreadChecker thread_checker_;
9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationRegistrar registrar_;
9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Some void primitives require some internal processing in the main thread
9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // when done. We use this internal consumer for this purpose.
9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CancelableRequestConsumer internal_consumer_;
9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The thread used by the history service to run complicated operations.
9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |thread_| is NULL once |Cleanup| is NULL.
9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Thread* thread_;
9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This class has most of the implementation and runs on the 'thread_'.
9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // You MUST communicate with this class ONLY through the thread_'s
9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // message_loop().
9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This pointer will be NULL once Cleanup() has been called, meaning no
9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // more calls should be made to the history thread.
9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<history::HistoryBackend> history_backend_;
9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A cache of the user-typed URLs kept in memory that is used by the
9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // autocomplete system. This will be NULL until the database has been created
9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // on the background thread.
9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321
9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_;
9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
954cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // The history client, may be null when testing. The object should otherwise
955cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // outlive |HistoryService|.
956cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  history::HistoryClient* history_client_;
957cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The profile, may be null when testing.
9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_;
9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Used for propagating link highlighting data across renderers. May be null
9622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // in tests.
96390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
9642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Has the backend finished loading? The backend is loaded once Init has
9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // completed.
9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool backend_loaded_;
9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cached values from Init(), used whenever we need to reload the backend.
9702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath history_dir_;
9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool no_db_;
9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The index used for quick history lookups.
9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(mrossetti): Move in_memory_url_index out of history_service.
9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // See http://crbug.com/138321
9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_;
9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ObserverList<history::VisitDatabaseObserver> visit_database_observers_;
9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  history::DeleteDirectiveHandler delete_directive_handler_;
9812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(HistoryService);
9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_
986