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"
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/callback_list.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/logging.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/weak_ptr.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/observer_list.h"
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/task/cancelable_task_tracker.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/thread_checker.h"
24eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.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 "sql/init_status.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sync/api/syncable_service.h"
381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/base/page_transition_types.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;
491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass SkBitmap;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Thread;
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace visitedlink {
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class VisitedLinkMaster;
5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace history {
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryBackend;
63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class HistoryClient;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryDatabase;
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class HistoryDBTask;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryQueryTest;
671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass HistoryTest;
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InMemoryHistoryBackend;
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InMemoryURLIndex;
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InMemoryURLIndexTest;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLDatabase;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VisitDatabaseObserver;
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class VisitFilter;
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct DownloadRow;
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct HistoryAddPageArgs;
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct HistoryDetails;
77116680a4aac90f2aa7413d9095a592090648e557Ben Murdochstruct KeywordSearchTermVisit;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace history
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The history service records page titles, and visit times, as well as
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (eventually) information about autocomplete.
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This service is thread safe. Each request callback is invoked in the
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// thread that made the request.
865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class HistoryService : public content::NotificationObserver,
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       public syncer::SyncableService,
88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                       public KeyedService,
8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                       public visitedlink::VisitedLinkDelegate {
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Miscellaneous commonly-used types.
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef std::vector<PageUsageData*> PageUsageDataList;
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
94cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Must call Init after construction. The |history::HistoryClient| object
95cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // must be valid for the whole lifetime of |HistoryService|.
96cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  explicit HistoryService(history::HistoryClient* client, Profile* profile);
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The empty constructor is provided only for testing.
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HistoryService();
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~HistoryService();
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initializes the history service, returning true on success. On false, do
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not call any other functions. The given directory will be used for storing
10446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // the history files.
10546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  bool Init(const base::FilePath& history_dir) {
10646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return Init(history_dir, false);
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Triggers the backend to load if it hasn't already, and then returns whether
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it's finished loading.
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note: Virtual needed for mocking.
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool BackendLoaded();
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the backend has finished loading.
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool backend_loaded() const { return backend_loaded_; }
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Context ids are used to scope page IDs (see AddPage). These contexts
118f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // must tell us when they are being invalidated so that we can clear
119f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // out any cached data associated with that context.
120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void ClearCachedDataForContextID(history::ContextID context_id);
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Triggers the backend to load if it hasn't already, and then returns the
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in-memory URL database. The returned pointer MAY BE NULL if the in-memory
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // database has not been loaded yet. This pointer is owned by the history
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // system. Callers should not store or cache this value.
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(brettw) this should return the InMemoryHistoryBackend.
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  history::URLDatabase* InMemoryDatabase();
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Following functions get URL information from in-memory database.
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // They return false if database is not available (e.g. not loaded yet) or the
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL does not exist.
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads the number of times the user has typed the given URL.
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetTypedCountForURL(const GURL& url, int* typed_count);
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads the last visit time for the given URL.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetLastVisitTimeForURL(const GURL& url, base::Time* last_visit);
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads the number of times this URL has been visited.
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetVisitCountForURL(const GURL& url, int* visit_count);
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
143b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Returns a pointer to the TypedUrlSyncableService owned by HistoryBackend.
144b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // This method should only be called from the history thread, because the
145b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // returned service is intended to be accessed only via the history thread.
146b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  history::TypedUrlSyncableService* GetTypedUrlSyncableService() const;
147b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return the quick history index.
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  history::InMemoryURLIndex* InMemoryIndex() const {
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return in_memory_url_index_.get();
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
153a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // KeyedService:
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Shutdown() OVERRIDE;
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Navigation ----------------------------------------------------------------
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds the given canonical URL to history with the given time as the visit
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // time. Referrer may be the empty string.
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
161f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // The supplied context id is used to scope the given page ID. Page IDs
162f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // are only unique inside a given context, so we need that to differentiate
163f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // them.
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
165f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // The context/page ids can be NULL if there is no meaningful tracking
166f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // information that can be performed on the given URL. The 'page_id' should
167f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // be the ID of the current session history entry in the given process.
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 'redirects' is an array of redirect URLs leading to this page, with the
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // page itself as the last item (so when there is no redirect, it will have
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // one entry). If there are no redirects, this array may also be empty for
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the convenience of callers.
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 'did_replace_entry' is true when the navigation entry for this page has
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // replaced the existing entry. A non-user initiated redirect causes such
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // replacement.
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All "Add Page" functions will update the visited link database.
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPage(const GURL& url,
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               base::Time time,
181f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)               history::ContextID context_id,
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               int32 page_id,
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               const GURL& referrer,
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               const history::RedirectList& redirects,
1851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci               ui::PageTransition transition,
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               history::VisitSource visit_source,
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               bool did_replace_entry);
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For adding pages to history where no tracking information can be done.
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPage(const GURL& url,
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               base::Time time,
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               history::VisitSource visit_source);
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All AddPage variants end up here.
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPage(const history::HistoryAddPageArgs& add_page_args);
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds an entry for the specified url without creating a visit. This should
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // only be used when bookmarking a page, otherwise the row leaks in the
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history db (it never gets cleaned).
200a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void AddPageNoVisitForBookmark(const GURL& url, const base::string16& title);
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the title for the given page. The page should be in history. If it
203f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // is not, this operation is ignored.
204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void SetPageTitle(const GURL& url, const base::string16& title);
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Updates the history database with a page's ending time stamp information.
207f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // The page can be identified by the combination of the context id, the page
208f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // id and the url.
209f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void UpdateWithPageEndTime(history::ContextID context_id,
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             int32 page_id,
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const GURL& url,
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             base::Time end_ts);
21368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Querying ------------------------------------------------------------------
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the information about the requested URL. If the URL is found,
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // success will be true and the information will be in the URLRow parameter.
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // On success, the visits, if requested, will be sorted by date. If they have
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not been requested, the pointer will be valid, but the vector will be
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // empty.
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If success is false, neither the row nor the vector will be valid.
223f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  typedef base::Callback<
224f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      void(bool,  // Success flag, when false, nothing else is valid.
225f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)           const history::URLRow&,
226f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)           const history::VisitVector&)> QueryURLCallback;
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Queries the basic information about the URL in the history database. If
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the caller is interested in the visits (each time the URL is visited),
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // set |want_visits| to true. If these are not needed, the function will be
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // faster by setting this to false.
232f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  base::CancelableTaskTracker::TaskId QueryURL(
233f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const GURL& url,
234f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      bool want_visits,
235f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const QueryURLCallback& callback,
236f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Provides the result of a query. See QueryResults in history_types.h.
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The common use will be to use QueryResults.Swap to suck the contents of
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the results out of the passed in parameter and take ownership of them.
241116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  typedef base::Callback<void(history::QueryResults*)> QueryHistoryCallback;
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Queries all history with the given options (see QueryOptions in
244f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // history_types.h).  If empty, all results matching the given options
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be returned.
246116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryHistory(
247116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const base::string16& text_query,
248116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const history::QueryOptions& options,
249116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryHistoryCallback& callback,
250116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when the results of QueryRedirectsFrom are available.
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The given vector will contain a list of all redirects, not counting
254a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the original page. If A redirects to B which redirects to C, the vector
255a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // will contain [B, C], and A will be in 'from_url'.
256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  //
257a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // For QueryRedirectsTo, the order is reversed. For A->B->C, the vector will
258a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // contain [B, A] and C will be in 'to_url'.
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If there is no such URL in the database or the most recent visit has no
261116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // redirect, the vector will be empty. If the given page has redirected to
262116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // multiple destinations, this will pick a random one.
263116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  typedef base::Callback<void(const history::RedirectList*)>
264116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      QueryRedirectsCallback;
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Schedules a query for the most recent redirect coming out of the given
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL. See the RedirectQuerySource above, which is guaranteed to be called
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if the request is not canceled.
269116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryRedirectsFrom(
270116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const GURL& from_url,
271116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryRedirectsCallback& callback,
272116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Schedules a query to get the most recent redirects ending at the given
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL.
276116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryRedirectsTo(
277116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const GURL& to_url,
278116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryRedirectsCallback& callback,
279116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Requests the number of user-visible visits (i.e. no redirects or subframes)
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to all urls on the same scheme/host/port as |url|.  This is only valid for
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HTTP and HTTPS URLs.
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<
285116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      void(bool,         // Were we able to determine the # of visits?
286116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch           int,          // Number of visits.
287116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch           base::Time)>  // Time of first visit. Only set if bool
288116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                         // is true and int is > 0.
289116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      GetVisibleVisitCountToHostCallback;
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
291116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId GetVisibleVisitCountToHost(
292116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const GURL& url,
293116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const GetVisibleVisitCountToHostCallback& callback,
294116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Request the |result_count| most visited URLs and the chain of
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // redirects leading to each of these URLs. |days_back| is the
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // number of days of history to use. Used by TopSites.
299116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  typedef base::Callback<void(const history::MostVisitedURLList*)>
300116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      QueryMostVisitedURLsCallback;
301116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
302116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryMostVisitedURLs(
303116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      int result_count,
304116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      int days_back,
305116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryMostVisitedURLsCallback& callback,
306116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Request the |result_count| URLs filtered and sorted based on the |filter|.
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |extended_info| is true, additional data will be provided in the
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // results. Computing this additional data is expensive, likely to become
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // more expensive as additional data points are added in future changes, and
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not useful in most cases. Set |extended_info| to true only if you
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // explicitly require the additional data.
314116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  typedef base::Callback<void(const history::FilteredURLList*)>
315116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      QueryFilteredURLsCallback;
316116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
317116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::CancelableTaskTracker::TaskId QueryFilteredURLs(
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int result_count,
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const history::VisitFilter& filter,
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bool extended_info,
321116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const QueryFilteredURLsCallback& callback,
322116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      base::CancelableTaskTracker* tracker);
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Database management operations --------------------------------------------
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete all the information related to a single url.
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteURL(const GURL& url);
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete all the information related to a list of urls.  (Deleting
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URLs one by one is slow as it has to flush to disk each time.)
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteURLsForTest(const std::vector<GURL>& urls);
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
333f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Removes all visits in the selected time range (including the
334f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // start time), updating the URLs accordingly. This deletes any
335f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // associated data. This function also deletes the associated
336f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // favicons, if they are no longer referenced. |callback| runs when
337f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // the expiration is complete. You may use null Time values to do an
338f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // unbounded delete in either direction.
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |restrict_urls| is not empty, only visits to the URLs in this set are
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // removed.
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ExpireHistoryBetween(const std::set<GURL>& restrict_urls,
3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                            base::Time begin_time,
3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                            base::Time end_time,
3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                            const base::Closure& callback,
3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                            base::CancelableTaskTracker* tracker);
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Removes all visits to specified URLs in specific time ranges.
3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This is the equivalent ExpireHistoryBetween() once for each element in the
3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // vector. The fields of |ExpireHistoryArgs| map directly to the arguments of
3502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // of ExpireHistoryBetween().
3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void ExpireHistory(const std::vector<history::ExpireHistoryArgs>& expire_list,
3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                     const base::Closure& callback,
3535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     base::CancelableTaskTracker* tracker);
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Removes all visits to the given URLs in the specified time range. Calls
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ExpireHistoryBetween() to delete local visits, and handles deletion of
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // synced visits if appropriate.
3585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void ExpireLocalAndRemoteHistoryBetween(const std::set<GURL>& restrict_urls,
3595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          base::Time begin_time,
3605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          base::Time end_time,
3615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          const base::Closure& callback,
3625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          base::CancelableTaskTracker* tracker);
3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Processes the given |delete_directive| and sends it to the
3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // SyncChangeProcessor (if it exists).  Returns any error resulting
3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // from sending the delete directive to sync.
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  syncer::SyncError ProcessLocalDeleteDirective(
3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive);
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Downloads -----------------------------------------------------------------
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Implemented by the caller of 'CreateDownload' below, and is called when the
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history service has created a new entry for a download in the history db.
3747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  typedef base::Callback<void(bool)> DownloadCreateCallback;
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Begins a history request to create a new row for a download. 'info'
3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // contains all the download's creation state, and 'callback' runs when the
3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // history service request is complete. The callback is called on the thread
3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // that calls CreateDownload().
3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void CreateDownload(
3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const history::DownloadRow& info,
3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const DownloadCreateCallback& callback);
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Responds on the calling thread with the maximum id of all downloads records
3857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // in the database plus 1.
3867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void GetNextDownloadId(const content::DownloadIdCallback& callback);
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Implemented by the caller of 'QueryDownloads' below, and is called when the
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history service has retrieved a list of all download state. The call
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(
3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      scoped_ptr<std::vector<history::DownloadRow> >)>
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          DownloadQueryCallback;
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Begins a history request to retrieve the state of all downloads in the
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history db. 'callback' runs when the history service request is complete,
3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // at which point 'info' contains an array of history::DownloadRow, one per
3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // download. The callback is called on the thread that calls QueryDownloads().
3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void QueryDownloads(const DownloadQueryCallback& callback);
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to update the history service about the current state of a download.
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This is a 'fire and forget' query, so just pass the relevant state info to
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the database with no need for a callback.
4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void UpdateDownload(const history::DownloadRow& data);
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Permanently remove some downloads from the history system. This is a 'fire
4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // and forget' operation.
4077dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void RemoveDownloads(const std::set<uint32>& ids);
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Keyword search terms -----------------------------------------------------
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the search terms for the specified url and keyword. url_id gives the
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // id of the url, keyword_id the id of the keyword and term the search term.
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetKeywordSearchTermsForURL(const GURL& url,
414116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                   history::KeywordID keyword_id,
415a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                   const base::string16& term);
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deletes all search terms for the specified keyword.
418116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void DeleteAllSearchTermsForKeyword(history::KeywordID keyword_id);
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Deletes any search term corresponding to |url|.
4210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  void DeleteKeywordSearchTermForURL(const GURL& url);
4220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Deletes all URL and search term entries matching the given |term| and
4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |keyword_id|.
425116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void DeleteMatchingURLsForKeyword(history::KeywordID keyword_id,
4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                    const base::string16& term);
4275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Bookmarks -----------------------------------------------------------------
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notification that a URL is no longer bookmarked.
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void URLsNoLongerBookmarked(const std::set<GURL>& urls);
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Generic Stuff -------------------------------------------------------------
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Schedules a HistoryDBTask for running on the history backend thread. See
4365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // HistoryDBTask for details on what this does. Takes ownership of |task|.
4375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task,
438116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                              base::CancelableTaskTracker* tracker);
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes observers for the VisitDatabase.
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddVisitDatabaseObserver(history::VisitDatabaseObserver* observer);
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RemoveVisitDatabaseObserver(history::VisitDatabaseObserver* observer);
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyVisitDBObserversOnAddVisit(const history::BriefVisitInfo& info);
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // This callback is invoked when favicon change for urls.
4471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  typedef base::Callback<void(const std::set<GURL>&)> OnFaviconChangedCallback;
4481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Add a callback to the list. The callback will remain registered until the
4501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // returned Subscription is destroyed. This must occurs before HistoryService
4511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // is destroyed.
4521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription>
4531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      AddFaviconChangedCallback(const OnFaviconChangedCallback& callback)
4541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      WARN_UNUSED_RESULT;
4551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Testing -------------------------------------------------------------------
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Runs |flushed| after bouncing off the history thread.
4597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void FlushForTest(const base::Closure& flushed);
4607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Designed for unit tests, this passes the given task on to the history
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // backend to be called once the history backend has terminated. This allows
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // callers to know when the history thread is complete and the database files
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // can be deleted and the next test run. Otherwise, the history thread may
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // still be running, causing problems in subsequent tests.
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // There can be only one closing task, so this will override any previously
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // set task. We will take ownership of the pointer and delete it when done.
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The task will be run on the calling thread (this function is threadsafe).
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetOnBackendDestroyTask(const base::Closure& task);
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used for unit testing and potentially importing to get known information
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // into the database. This assumes the URL doesn't exist in the database
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Calling this function many times may be slow because each call will
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // dispatch to the history thread and will be a separate database
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // transaction. If this functionality is needed for importing many URLs,
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // callers should use AddPagesWithDetails() instead.
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note that this routine (and AddPageWithDetails()) always adds a single
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // visit using the |last_visit| timestamp, and a PageTransition type of LINK,
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if |visit_source| != SYNCED.
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPageWithDetails(const GURL& url,
484a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                          const base::string16& title,
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          int visit_count,
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          int typed_count,
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          base::Time last_visit,
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          bool hidden,
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          history::VisitSource visit_source);
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The same as AddPageWithDetails() but takes a vector.
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddPagesWithDetails(const history::URLRows& info,
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           history::VisitSource visit_source);
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if this looks like the type of URL we want to add to the
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history. We filter out some URLs such as JavaScript.
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool CanAddURL(const GURL& url);
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
499cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns the HistoryClient.
500cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  history::HistoryClient* history_client() { return history_client_; }
501cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::WeakPtr<HistoryService> AsWeakPtr();
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // syncer::SyncableService implementation.
5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      syncer::ModelType type,
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const syncer::SyncDataList& initial_sync_data,
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual syncer::SyncDataList GetAllSyncData(
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      syncer::ModelType type) const OVERRIDE;
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual syncer::SyncError ProcessSyncChanges(
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const tracked_objects::Location& from_here,
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const syncer::SyncChangeList& change_list) OVERRIDE;
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // These are not currently used, hopefully we can do something in the future
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to ensure that the most important things happen first.
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum SchedulePriority {
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PRIORITY_UI,      // The highest priority (must respond to UI events).
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PRIORITY_NORMAL,  // Normal stuff like adding a page.
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PRIORITY_LOW,     // Low priority things like indexing or expiration.
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class BackendDelegate;
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_ANDROID)
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class AndroidHistoryProviderService;
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class base::RefCountedThreadSafe<HistoryService>;
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class BackendDelegate;
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class FaviconService;
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class history::HistoryBackend;
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class history::HistoryQueryTest;
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class HistoryOperation;
5377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  friend class HistoryQuickProviderTest;
5381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  friend class history::HistoryTest;
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class HistoryURLProvider;
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class HistoryURLProviderTest;
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class history::InMemoryURLIndexTest;
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename Info, typename Callback> friend class DownloadRequest;
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class PageUsageRequest;
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class RedirectRequest;
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class TestingProfile;
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called on shutdown, this will tell the history backend to complete and
5481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // will release pointers to it. No other functions should be called once
5491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // cleanup has happened that may dispatch to the history thread (because it
5501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // will be NULL).
5511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  //
5521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // In practice, this will be called by the service manager (BrowserProcess)
5531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // when it is being destroyed. Because that reference is being destroyed, it
5541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // should be impossible for anybody else to call the service, even if it is
5551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // still in memory (pending requests may be holding a reference to us).
5561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void Cleanup();
5571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Implementation of content::NotificationObserver.
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Observe(int type,
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationSource& source,
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
56390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Implementation of visitedlink::VisitedLinkDelegate.
5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RebuildTable(
5652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Low-level Init().  Same as the public version, but adds a |no_db| parameter
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that is only set by unittests which causes the backend to not init its DB.
56946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  bool Init(const base::FilePath& history_dir, bool no_db);
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the HistoryURLProvider class to schedule an autocomplete, it
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be called back on the internal history thread with the history
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // database so it can query. See history_autocomplete.cc for a diagram.
574116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void ScheduleAutocomplete(const base::Callback<
575116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      void(history::HistoryBackend*, history::URLDatabase*)>& callback);
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Broadcasts the given notification. This is called by the backend so that
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the notification will be broadcast on the main thread.
579a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void BroadcastNotificationsHelper(
580a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      int type,
581a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      scoped_ptr<history::HistoryDetails> details);
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notification from the backend that it has finished loading. Sends
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true.
585a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void OnDBLoaded();
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper function for getting URL information.
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads a URLRow from in-memory database. Returns false if database is not
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // available or the URL does not exist.
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetRowForURL(const GURL& url, history::URLRow* url_row);
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Favicon -------------------------------------------------------------------
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // These favicon methods are exposed to the FaviconService. Instead of calling
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // these methods directly you should call the respective method on the
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // FaviconService.
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by FaviconService to get the favicon bitmaps from the history backend
5996d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // whose edge sizes most closely match |desired_sizes| for |icon_types|. If
6006d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |desired_sizes| has a '0' entry, the largest favicon bitmap for
6016d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |icon_types| is returned. The returned FaviconBitmapResults will have at
6026d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // most one result for each entry in |desired_sizes|. If a favicon bitmap is
6036d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // determined to be the best candidate for multiple |desired_sizes| there will
6046d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // be fewer results.
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |icon_types| has several types, results for only a single type will be
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // FAVICON.
6085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId GetFavicons(
6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const std::vector<GURL>& icon_urls,
6102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int icon_types,
6116d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      const std::vector<int>& desired_sizes,
612cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const favicon_base::FaviconResultsCallback& callback,
6135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to get favicons mapped to |page_url| for
6166d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |icon_types| whose edge sizes most closely match |desired_sizes|. If
6176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |desired_sizes| has a '0' entry, the largest favicon bitmap for
6186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |icon_types| is returned. The returned FaviconBitmapResults will have at
6196d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // most one result for each entry in |desired_sizes|. If a favicon bitmap is
6206d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // determined to be the best candidate for multiple |desired_sizes| there
6216d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // will be fewer results. If |icon_types| has several types, results for only
6226d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // a single type will be returned in the priority of TOUCH_PRECOMPOSED_ICON,
6236d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // TOUCH_ICON, and FAVICON.
6245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId GetFaviconsForURL(
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& page_url,
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int icon_types,
6276d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      const std::vector<int>& desired_sizes,
628cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const favicon_base::FaviconResultsCallback& callback,
6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Used by FaviconService to find the first favicon bitmap whose width and
6328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // height are greater than that of |minimum_size_in_pixels|. This searches
6338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // for icons by IconType. Each element of |icon_types| is a bitmask of
6348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // IconTypes indicating the types to search for.
6358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // If the largest icon of |icon_types[0]| is not larger than
6368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // |minimum_size_in_pixel|, the next icon types of
6378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // |icon_types| will be searched and so on.
6388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // If no icon is larger than |minimum_size_in_pixel|, the largest one of all
6398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // icon types in |icon_types| is returned.
640116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // This feature is especially useful when some types of icon is preferred as
6418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // long as its size is larger than a specific value.
6425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId GetLargestFaviconForURL(
6438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const GURL& page_url,
6448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const std::vector<int>& icon_types,
6458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      int minimum_size_in_pixels,
646f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const favicon_base::FaviconRawBitmapCallback& callback,
6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to get the favicon bitmap which most closely
6506d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // matches |desired_size| from the favicon with |favicon_id| from the history
6516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // backend. If |desired_size| is 0, the largest favicon bitmap for
6526d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |favicon_id| is returned.
6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId GetFaviconForID(
6540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      favicon_base::FaviconID favicon_id,
6556d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      int desired_size,
656cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const favicon_base::FaviconResultsCallback& callback,
6575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to replace the favicon mappings to |page_url|
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for |icon_types| on the history backend.
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sample |icon_urls|:
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  { ICON_URL1 -> TOUCH_ICON, known to the database,
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    ICON_URL2 -> TOUCH_ICON, not known to the database,
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database }
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The new mappings are computed from |icon_urls| with these rules:
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 1) Any urls in |icon_urls| which are not already known to the database are
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    rejected.
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 }
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 2) If |icon_types| has multiple types, the mappings are only set for the
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    largest icon type.
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    Sample new mappings to |page_url|: { ICON_URL3 }
6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |icon_types| can only have multiple IconTypes if
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON.
6746d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // The favicon bitmaps whose edge sizes most closely match |desired_sizes|
6756d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // from the favicons which were just mapped to |page_url| are returned. If
6766d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // |desired_sizes| has a '0' entry, the largest favicon bitmap is returned.
6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch(
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& page_url,
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::vector<GURL>& icon_urls,
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int icon_types,
6816d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      const std::vector<int>& desired_sizes,
682cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const favicon_base::FaviconResultsCallback& callback,
6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::CancelableTaskTracker* tracker);
6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Used by FaviconService to set a favicon for |page_url| and |icon_url| with
6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |pixel_size|.
6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Example:
6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //   |page_url|: www.google.com
6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // 2 favicons in history for |page_url|:
6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //   www.google.com/a.ico  16x16
6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //   www.google.com/b.ico  32x32
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // MergeFavicon(|page_url|, www.google.com/a.ico, ..., ..., 16x16)
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Merging occurs in the following manner:
6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // 1) |page_url| is set to map to only to |icon_url|. In order to not lose
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    data, favicon bitmaps mapped to |page_url| but not to |icon_url| are
6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    copied to the favicon at |icon_url|.
6982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    For the example above, |page_url| will only be mapped to a.ico.
6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    The 32x32 favicon bitmap at b.ico is copied to a.ico
7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // 2) |bitmap_data| is added to the favicon at |icon_url|, overwriting any
7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    favicon bitmaps of |pixel_size|.
7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    For the example above, |bitmap_data| overwrites the 16x16 favicon
7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //    bitmap for a.ico.
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(pkotwicz): Remove once no longer required by sync.
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void MergeFavicon(const GURL& page_url,
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                    const GURL& icon_url,
7070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                    favicon_base::IconType icon_type,
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    scoped_refptr<base::RefCountedMemory> bitmap_data,
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const gfx::Size& pixel_size);
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Used by the FaviconService to replace all of the favicon bitmaps mapped to
7121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // |page_url| for |icon_type|.
7131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Use MergeFavicon() if |bitmaps| is incomplete, and favicon bitmaps in the
7141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // database should be preserved if possible. For instance, favicon bitmaps
7151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // from sync are 1x only. MergeFavicon() is used to avoid deleting the 2x
7161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // favicon bitmap if it is present in the history backend.
717f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SetFavicons(const GURL& page_url,
718f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                   favicon_base::IconType icon_type,
7191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                   const GURL& icon_url,
7201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                   const std::vector<SkBitmap>& bitmaps);
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to mark the favicon for the page as being out
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // of date.
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetFaviconsOutOfDateForPage(const GURL& page_url);
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by the FaviconService to clone favicons from one page to another,
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // provided that other page does not already have favicons.
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url);
7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Used by the FaviconService for importing many favicons for many pages at
7315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // once. The pages must exist, any favicon sets for unknown pages will be
7325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // discarded. Existing favicons will not be overwritten.
7335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  void SetImportedFavicons(
7345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const std::vector<ImportedFaviconUsage>& favicon_usage);
7355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the in-memory URL database. This is called by the backend once the
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // database is loaded to make it available.
738eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void SetInMemoryBackend(
739eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      scoped_ptr<history::InMemoryHistoryBackend> mem_backend);
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by our BackendDelegate when there is a problem reading the database.
742a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void NotifyProfileError(sql::InitStatus init_status);
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Call to schedule a given task for running on the history thread with the
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // specified priority. The task will have ownership taken.
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleTask(SchedulePriority priority, const base::Closure& task);
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Invokes all callback registered by AddFaviconChangedCallback.
7491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void NotifyFaviconChanged(const std::set<GURL>& changed_favicons);
7501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ScheduleAndForget ---------------------------------------------------------
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Functions for scheduling operations on the history thread that do not need
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // any callbacks and are not cancelable.
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc>
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func) {  // Function to call on backend.
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get()));
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc, typename ArgA>
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a) {
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(), a));
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc, typename ArgA, typename ArgB>
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a,
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgB& b) {
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(), a, b));
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc, typename ArgA, typename ArgB, typename ArgC>
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a,
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgB& b,
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgC& c) {
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(), a, b, c));
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc,
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgA,
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgB,
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgC,
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgD>
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a,
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgB& b,
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgC& c,
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgD& d) {
8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(),
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      a, b, c, d));
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename BackendFunc,
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgA,
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgB,
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgC,
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgD,
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           typename ArgE>
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleAndForget(SchedulePriority priority,
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         BackendFunc func,  // Function to call on backend.
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgA& a,
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgB& b,
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgC& c,
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgD& d,
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const ArgE& e) {
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_) << "History service being called after cleanup";
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(thread_checker_.CalledOnValidThread());
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScheduleTask(priority, base::Bind(func, history_backend_.get(),
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      a, b, c, d, e));
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::ThreadChecker thread_checker_;
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationRegistrar registrar_;
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The thread used by the history service to run complicated operations.
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |thread_| is NULL once |Cleanup| is NULL.
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Thread* thread_;
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This class has most of the implementation and runs on the 'thread_'.
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // You MUST communicate with this class ONLY through the thread_'s
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // message_loop().
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This pointer will be NULL once Cleanup() has been called, meaning no
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // more calls should be made to the history thread.
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<history::HistoryBackend> history_backend_;
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A cache of the user-typed URLs kept in memory that is used by the
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // autocomplete system. This will be NULL until the database has been created
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // on the background thread.
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321
8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_;
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
852cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // The history client, may be null when testing. The object should otherwise
853cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // outlive |HistoryService|.
854cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  history::HistoryClient* history_client_;
855cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The profile, may be null when testing.
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_;
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Used for propagating link highlighting data across renderers. May be null
8602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // in tests.
86190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
8622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Has the backend finished loading? The backend is loaded once Init has
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // completed.
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool backend_loaded_;
8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cached values from Init(), used whenever we need to reload the backend.
8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath history_dir_;
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool no_db_;
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The index used for quick history lookups.
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(mrossetti): Move in_memory_url_index out of history_service.
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // See http://crbug.com/138321
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_;
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ObserverList<history::VisitDatabaseObserver> visit_database_observers_;
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::CallbackList<void(const std::set<GURL>&)>
8791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      favicon_changed_callback_list_;
8801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  history::DeleteDirectiveHandler delete_directive_handler_;
8822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // All vended weak pointers are invalidated in Cleanup().
8841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::WeakPtrFactory<HistoryService> weak_ptr_factory_;
8851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(HistoryService);
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_
890