history_service.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/bind.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/logging.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/weak_ptr.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/observer_list.h" 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/task/cancelable_task_tracker.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/thread_checker.h" 23eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/common/cancelable_request.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/history/delete_directive_handler.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/history/history_types.h" 27b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chrome/browser/history/typed_url_syncable_service.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/search_engines/template_url_id.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/ref_counted_util.h" 30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/favicon_base/favicon_callback.h" 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/core/keyed_service.h" 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "components/visitedlink/browser/visitedlink_delegate.h" 337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "content/public/browser/download_manager_delegate.h" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_transition_types.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sql/init_status.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sync/api/syncable_service.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/layout.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_ANDROID) 42cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class AndroidHistoryProviderService; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BookmarkService; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryURLProvider; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PageUsageData; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PageUsageRequest; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile; 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct HistoryURLProviderParams; 52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)struct ImportedFaviconUsage; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Thread; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace visitedlink { 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class VisitedLinkMaster; 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace history { 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryBackend; 66cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class HistoryClient; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryDatabase; 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class HistoryDBTask; 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryQueryTest; 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InMemoryHistoryBackend; 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InMemoryURLIndex; 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InMemoryURLIndexTest; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLDatabase; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VisitDatabaseObserver; 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class VisitFilter; 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct DownloadRow; 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct HistoryAddPageArgs; 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct HistoryDetails; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace history 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The history service records page titles, and visit times, as well as 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (eventually) information about autocomplete. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This service is thread safe. Each request callback is invoked in the 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// thread that made the request. 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryService : public CancelableRequestProvider, 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public content::NotificationObserver, 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public syncer::SyncableService, 90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public KeyedService, 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public visitedlink::VisitedLinkDelegate { 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Miscellaneous commonly-used types. 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::vector<PageUsageData*> PageUsageDataList; 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 96cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Must call Init after construction. The |history::HistoryClient| object 97cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // must be valid for the whole lifetime of |HistoryService|. 98cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) explicit HistoryService(history::HistoryClient* client, Profile* profile); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The empty constructor is provided only for testing. 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HistoryService(); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~HistoryService(); 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes the history service, returning true on success. On false, do 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not call any other functions. The given directory will be used for storing 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the history files. The BookmarkService is used when deleting URLs to 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // test if a URL is bookmarked; it may be NULL during testing. 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool Init(const base::FilePath& history_dir, BookmarkService* bookmark_service) { 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Init(history_dir, bookmark_service, false); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Triggers the backend to load if it hasn't already, and then returns whether 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it's finished loading. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note: Virtual needed for mocking. 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool BackendLoaded(); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the backend has finished loading. 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool backend_loaded() const { return backend_loaded_; } 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called on shutdown, this will tell the history backend to complete and 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will release pointers to it. No other functions should be called once 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cleanup has happened that may dispatch to the history thread (because it 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be NULL). 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // In practice, this will be called by the service manager (BrowserProcess) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when it is being destroyed. Because that reference is being destroyed, it 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // should be impossible for anybody else to call the service, even if it is 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // still in memory (pending requests may be holding a reference to us). 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Cleanup(); 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // RenderProcessHost pointers are used to scope page IDs (see AddPage). These 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // objects must tell us when they are being destroyed so that we can clear 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // out any cached data associated with that scope. 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The given pointer will not be dereferenced, it is only used for 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // identification purposes, hence it is a void*. 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyRenderProcessHostDestruction(const void* host); 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Triggers the backend to load if it hasn't already, and then returns the 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in-memory URL database. The returned pointer MAY BE NULL if the in-memory 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // database has not been loaded yet. This pointer is owned by the history 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // system. Callers should not store or cache this value. 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(brettw) this should return the InMemoryHistoryBackend. 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) history::URLDatabase* InMemoryDatabase(); 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Following functions get URL information from in-memory database. 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // They return false if database is not available (e.g. not loaded yet) or the 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL does not exist. 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reads the number of times the user has typed the given URL. 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetTypedCountForURL(const GURL& url, int* typed_count); 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reads the last visit time for the given URL. 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetLastVisitTimeForURL(const GURL& url, base::Time* last_visit); 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reads the number of times this URL has been visited. 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetVisitCountForURL(const GURL& url, int* visit_count); 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 160b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Returns a pointer to the TypedUrlSyncableService owned by HistoryBackend. 161b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // This method should only be called from the history thread, because the 162b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // returned service is intended to be accessed only via the history thread. 163b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) history::TypedUrlSyncableService* GetTypedUrlSyncableService() const; 164b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return the quick history index. 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) history::InMemoryURLIndex* InMemoryIndex() const { 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return in_memory_url_index_.get(); 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 170a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // KeyedService: 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Shutdown() OVERRIDE; 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Navigation ---------------------------------------------------------------- 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds the given canonical URL to history with the given time as the visit 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // time. Referrer may be the empty string. 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The supplied render process host is used to scope the given page ID. Page 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IDs are only unique inside a given render process, so we need that to 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // differentiate them. This pointer should not be dereferenced by the history 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // system. 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The scope/ids can be NULL if there is no meaningful tracking information 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that can be performed on the given URL. The 'page_id' should be the ID of 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the current session history entry in the given process. 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 'redirects' is an array of redirect URLs leading to this page, with the 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // page itself as the last item (so when there is no redirect, it will have 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // one entry). If there are no redirects, this array may also be empty for 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the convenience of callers. 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 'did_replace_entry' is true when the navigation entry for this page has 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // replaced the existing entry. A non-user initiated redirect causes such 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // replacement. 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // All "Add Page" functions will update the visited link database. 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddPage(const GURL& url, 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time time, 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void* id_scope, 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32 page_id, 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& referrer, 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const history::RedirectList& redirects, 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PageTransition transition, 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) history::VisitSource visit_source, 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool did_replace_entry); 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For adding pages to history where no tracking information can be done. 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddPage(const GURL& url, 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time time, 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) history::VisitSource visit_source); 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // All AddPage variants end up here. 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddPage(const history::HistoryAddPageArgs& add_page_args); 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds an entry for the specified url without creating a visit. This should 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // only be used when bookmarking a page, otherwise the row leaks in the 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // history db (it never gets cleaned). 218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void AddPageNoVisitForBookmark(const GURL& url, const base::string16& title); 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the title for the given page. The page should be in history. If it 221f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // is not, this operation is ignored. 222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void SetPageTitle(const GURL& url, const base::string16& title); 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the history database with a page's ending time stamp information. 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The page can be identified by the combination of the pointer to 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a RenderProcessHost, the page id and the url. 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The given pointer will not be dereferenced, it is only used for 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // identification purposes, hence it is a void*. 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateWithPageEndTime(const void* host, 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32 page_id, 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time end_ts); 23468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Querying ------------------------------------------------------------------ 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the information about the requested URL. If the URL is found, 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // success will be true and the information will be in the URLRow parameter. 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // On success, the visits, if requested, will be sorted by date. If they have 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not been requested, the pointer will be valid, but the vector will be 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // empty. 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If success is false, neither the row nor the vector will be valid. 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void( 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle, 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool, // Success flag, when false, nothing else is valid. 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const history::URLRow*, 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) history::VisitVector*)> QueryURLCallback; 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Queries the basic information about the URL in the history database. If 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the caller is interested in the visits (each time the URL is visited), 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // set |want_visits| to true. If these are not needed, the function will be 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // faster by setting this to false. 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle QueryURL(const GURL& url, 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool want_visits, 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const QueryURLCallback& callback); 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Provides the result of a query. See QueryResults in history_types.h. 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The common use will be to use QueryResults.Swap to suck the contents of 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the results out of the passed in parameter and take ownership of them. 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void(Handle, history::QueryResults*)> 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QueryHistoryCallback; 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Queries all history with the given options (see QueryOptions in 266f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // history_types.h). If empty, all results matching the given options 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be returned. 268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) Handle QueryHistory(const base::string16& text_query, 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const history::QueryOptions& options, 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const QueryHistoryCallback& callback); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the results of QueryRedirectsFrom are available. 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The given vector will contain a list of all redirects, not counting 275a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // the original page. If A redirects to B which redirects to C, the vector 276a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // will contain [B, C], and A will be in 'from_url'. 277a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // For QueryRedirectsTo, the order is reversed. For A->B->C, the vector will 279a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // contain [B, A] and C will be in 'to_url'. 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If there is no such URL in the database or the most recent visit has no 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // redirect, the vector will be empty. If the history system failed for 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // some reason, success will additionally be false. If the given page 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // has redirected to multiple destinations, this will pick a random one. 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void(Handle, 286a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GURL, // from_url / to_url 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool, // success 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) history::RedirectList*)> QueryRedirectsCallback; 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Schedules a query for the most recent redirect coming out of the given 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL. See the RedirectQuerySource above, which is guaranteed to be called 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if the request is not canceled. 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle QueryRedirectsFrom(const GURL& from_url, 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const QueryRedirectsCallback& callback); 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Schedules a query to get the most recent redirects ending at the given 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL. 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle QueryRedirectsTo(const GURL& to_url, 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const QueryRedirectsCallback& callback); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback< 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(Handle, 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool, // Were we able to determine the # of visits? 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int, // Number of visits. 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time)> // Time of first visit. Only set if bool 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is true and int is > 0. 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetVisibleVisitCountToHostCallback; 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Requests the number of user-visible visits (i.e. no redirects or subframes) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to all urls on the same scheme/host/port as |url|. This is only valid for 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // HTTP and HTTPS URLs. 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle GetVisibleVisitCountToHost( 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GetVisibleVisitCountToHostCallback& callback); 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when QueryTopURLsAndRedirects completes. The vector contains a list 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of the top |result_count| URLs. For each of these URLs, there is an entry 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in the map containing redirects from the URL. For example, if we have the 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // redirect chain A -> B -> C and A is a top visited URL, then A will be in 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the vector and "A => {B -> C}" will be in the map. 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback< 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(Handle, 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool, // Did we get the top urls and redirects? 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<GURL>*, // List of top URLs. 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) history::RedirectMap*)> // Redirects for top URLs. 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QueryTopURLsAndRedirectsCallback; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request the top |result_count| most visited URLs and the chain of redirects 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // leading to each of these URLs. 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(Nik): remove this. Use QueryMostVisitedURLs instead. 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle QueryTopURLsAndRedirects( 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int result_count, 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const QueryTopURLsAndRedirectsCallback& callback); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void(Handle, history::MostVisitedURLList)> 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QueryMostVisitedURLsCallback; 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void(Handle, const history::FilteredURLList&)> 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QueryFilteredURLsCallback; 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request the |result_count| most visited URLs and the chain of 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // redirects leading to each of these URLs. |days_back| is the 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // number of days of history to use. Used by TopSites. 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle QueryMostVisitedURLs(int result_count, int days_back, 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const QueryMostVisitedURLsCallback& callback); 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request the |result_count| URLs filtered and sorted based on the |filter|. 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |extended_info| is true, additional data will be provided in the 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // results. Computing this additional data is expensive, likely to become 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // more expensive as additional data points are added in future changes, and 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not useful in most cases. Set |extended_info| to true only if you 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // explicitly require the additional data. 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle QueryFilteredURLs( 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int result_count, 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const history::VisitFilter& filter, 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool extended_info, 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const QueryFilteredURLsCallback& callback); 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Database management operations -------------------------------------------- 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Delete all the information related to a single url. 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DeleteURL(const GURL& url); 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Delete all the information related to a list of urls. (Deleting 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URLs one by one is slow as it has to flush to disk each time.) 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DeleteURLsForTest(const std::vector<GURL>& urls); 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 374f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Removes all visits in the selected time range (including the 375f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // start time), updating the URLs accordingly. This deletes any 376f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // associated data. This function also deletes the associated 377f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // favicons, if they are no longer referenced. |callback| runs when 378f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // the expiration is complete. You may use null Time values to do an 379f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // unbounded delete in either direction. 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |restrict_urls| is not empty, only visits to the URLs in this set are 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // removed. 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ExpireHistoryBetween(const std::set<GURL>& restrict_urls, 3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Time begin_time, 3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Time end_time, 3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::Closure& callback, 3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker* tracker); 3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Removes all visits to specified URLs in specific time ranges. 3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This is the equivalent ExpireHistoryBetween() once for each element in the 3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // vector. The fields of |ExpireHistoryArgs| map directly to the arguments of 3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // of ExpireHistoryBetween(). 3922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void ExpireHistory(const std::vector<history::ExpireHistoryArgs>& expire_list, 3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::Closure& callback, 3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker* tracker); 3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Removes all visits to the given URLs in the specified time range. Calls 3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ExpireHistoryBetween() to delete local visits, and handles deletion of 3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // synced visits if appropriate. 3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void ExpireLocalAndRemoteHistoryBetween(const std::set<GURL>& restrict_urls, 4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Time begin_time, 4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Time end_time, 4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker* tracker); 4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Processes the given |delete_directive| and sends it to the 4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // SyncChangeProcessor (if it exists). Returns any error resulting 4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // from sending the delete directive to sync. 4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) syncer::SyncError ProcessLocalDeleteDirective( 4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive); 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Downloads ----------------------------------------------------------------- 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implemented by the caller of 'CreateDownload' below, and is called when the 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // history service has created a new entry for a download in the history db. 4157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch typedef base::Callback<void(bool)> DownloadCreateCallback; 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Begins a history request to create a new row for a download. 'info' 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // contains all the download's creation state, and 'callback' runs when the 4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // history service request is complete. The callback is called on the thread 4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // that calls CreateDownload(). 4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void CreateDownload( 4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const history::DownloadRow& info, 4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const DownloadCreateCallback& callback); 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Responds on the calling thread with the maximum id of all downloads records 4267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // in the database plus 1. 4277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void GetNextDownloadId(const content::DownloadIdCallback& callback); 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implemented by the caller of 'QueryDownloads' below, and is called when the 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // history service has retrieved a list of all download state. The call 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void( 4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<std::vector<history::DownloadRow> >)> 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DownloadQueryCallback; 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Begins a history request to retrieve the state of all downloads in the 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // history db. 'callback' runs when the history service request is complete, 4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // at which point 'info' contains an array of history::DownloadRow, one per 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // download. The callback is called on the thread that calls QueryDownloads(). 4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void QueryDownloads(const DownloadQueryCallback& callback); 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called to update the history service about the current state of a download. 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is a 'fire and forget' query, so just pass the relevant state info to 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the database with no need for a callback. 4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void UpdateDownload(const history::DownloadRow& data); 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Permanently remove some downloads from the history system. This is a 'fire 4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and forget' operation. 4487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void RemoveDownloads(const std::set<uint32>& ids); 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Visit Segments ------------------------------------------------------------ 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void(Handle, std::vector<PageUsageData*>*)> 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SegmentQueryCallback; 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Query usage data for all visit segments since the provided time. 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request is performed asynchronously and can be cancelled by using the 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returned handle. 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The vector provided to the callback and its contents is owned by the 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // history system. It will be deeply deleted after the callback is invoked. 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If you want to preserve any PageUsageData instance, simply remove them 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // from the vector. 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The vector contains a list of PageUsageData. Each PageUsageData ID is set 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to the segment ID. The URL and all the other information is set to the page 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // representing the segment. 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle QuerySegmentUsageSince(CancelableRequestConsumerBase* consumer, 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Time from_time, 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int max_result_count, 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SegmentQueryCallback& callback); 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Keyword search terms ----------------------------------------------------- 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the search terms for the specified url and keyword. url_id gives the 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // id of the url, keyword_id the id of the keyword and term the search term. 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetKeywordSearchTermsForURL(const GURL& url, 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TemplateURLID keyword_id, 479a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& term); 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Deletes all search terms for the specified keyword. 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DeleteAllSearchTermsForKeyword(TemplateURLID keyword_id); 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback< 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(Handle, std::vector<history::KeywordSearchTermVisit>*)> 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetMostRecentKeywordSearchTermsCallback; 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns up to max_count of the most recent search terms starting with the 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // specified text. The matching is case insensitive. The results are ordered 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in descending order up to |max_count| with the most recent search term 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // first. 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle GetMostRecentKeywordSearchTerms( 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TemplateURLID keyword_id, 494a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& prefix, 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int max_count, 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GetMostRecentKeywordSearchTermsCallback& callback); 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Deletes any search term corresponding to |url|. 5000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) void DeleteKeywordSearchTermForURL(const GURL& url); 5010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 5025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Deletes all URL and search term entries matching the given |term| and 5035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |keyword_id|. 5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void DeleteMatchingURLsForKeyword(TemplateURLID keyword_id, 5055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& term); 5065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Bookmarks ----------------------------------------------------------------- 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notification that a URL is no longer bookmarked. 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void URLsNoLongerBookmarked(const std::set<GURL>& urls); 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Generic Stuff ------------------------------------------------------------- 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Schedules a HistoryDBTask for running on the history backend thread. See 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // HistoryDBTask for details on what this does. 5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void ScheduleDBTask(history::HistoryDBTask* task, 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer); 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds or removes observers for the VisitDatabase. 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddVisitDatabaseObserver(history::VisitDatabaseObserver* observer); 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveVisitDatabaseObserver(history::VisitDatabaseObserver* observer); 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyVisitDBObserversOnAddVisit(const history::BriefVisitInfo& info); 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Testing ------------------------------------------------------------------- 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Runs |flushed| after bouncing off the history thread. 5287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void FlushForTest(const base::Closure& flushed); 5297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Designed for unit tests, this passes the given task on to the history 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // backend to be called once the history backend has terminated. This allows 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // callers to know when the history thread is complete and the database files 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // can be deleted and the next test run. Otherwise, the history thread may 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // still be running, causing problems in subsequent tests. 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There can be only one closing task, so this will override any previously 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // set task. We will take ownership of the pointer and delete it when done. 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The task will be run on the calling thread (this function is threadsafe). 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetOnBackendDestroyTask(const base::Closure& task); 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used for unit testing and potentially importing to get known information 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // into the database. This assumes the URL doesn't exist in the database 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Calling this function many times may be slow because each call will 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // dispatch to the history thread and will be a separate database 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // transaction. If this functionality is needed for importing many URLs, 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // callers should use AddPagesWithDetails() instead. 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note that this routine (and AddPageWithDetails()) always adds a single 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // visit using the |last_visit| timestamp, and a PageTransition type of LINK, 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if |visit_source| != SYNCED. 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddPageWithDetails(const GURL& url, 553a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& title, 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int visit_count, 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int typed_count, 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time last_visit, 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool hidden, 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) history::VisitSource visit_source); 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The same as AddPageWithDetails() but takes a vector. 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddPagesWithDetails(const history::URLRows& info, 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) history::VisitSource visit_source); 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if this looks like the type of URL we want to add to the 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // history. We filter out some URLs such as JavaScript. 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool CanAddURL(const GURL& url); 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 568cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Returns the HistoryClient. 569cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) history::HistoryClient* history_client() { return history_client_; } 570cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::WeakPtr<HistoryService> AsWeakPtr(); 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // syncer::SyncableService implementation. 5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual syncer::SyncMergeResult MergeDataAndStartSyncing( 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::ModelType type, 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const syncer::SyncDataList& initial_sync_data, 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void StopSyncing(syncer::ModelType type) OVERRIDE; 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual syncer::SyncDataList GetAllSyncData( 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::ModelType type) const OVERRIDE; 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual syncer::SyncError ProcessSyncChanges( 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const tracked_objects::Location& from_here, 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const syncer::SyncChangeList& change_list) OVERRIDE; 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These are not currently used, hopefully we can do something in the future 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to ensure that the most important things happen first. 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum SchedulePriority { 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRIORITY_UI, // The highest priority (must respond to UI events). 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRIORITY_NORMAL, // Normal stuff like adding a page. 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRIORITY_LOW, // Low priority things like indexing or expiration. 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class BackendDelegate; 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_ANDROID) 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class AndroidHistoryProviderService; 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class base::RefCountedThreadSafe<HistoryService>; 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class BackendDelegate; 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class FaviconService; 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class history::HistoryBackend; 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class history::HistoryQueryTest; 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class HistoryOperation; 6067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) friend class HistoryQuickProviderTest; 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class HistoryURLProvider; 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class HistoryURLProviderTest; 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class history::InMemoryURLIndexTest; 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename Info, typename Callback> friend class DownloadRequest; 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class PageUsageRequest; 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class RedirectRequest; 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class TestingProfile; 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implementation of content::NotificationObserver. 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Observe(int type, 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 62090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Implementation of visitedlink::VisitedLinkDelegate. 6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void RebuildTable( 6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE; 6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Low-level Init(). Same as the public version, but adds a |no_db| parameter 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that is only set by unittests which causes the backend to not init its DB. 6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool Init(const base::FilePath& history_dir, 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BookmarkService* bookmark_service, 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool no_db); 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called by the HistoryURLProvider class to schedule an autocomplete, it 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be called back on the internal history thread with the history 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // database so it can query. See history_autocomplete.cc for a diagram. 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleAutocomplete(HistoryURLProvider* provider, 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HistoryURLProviderParams* params); 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Broadcasts the given notification. This is called by the backend so that 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the notification will be broadcast on the main thread. 638a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void BroadcastNotificationsHelper( 639a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) int type, 640a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<history::HistoryDetails> details); 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notification from the backend that it has finished loading. Sends 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. 644a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void OnDBLoaded(); 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Helper function for getting URL information. 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reads a URLRow from in-memory database. Returns false if database is not 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // available or the URL does not exist. 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetRowForURL(const GURL& url, history::URLRow* url_row); 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Favicon ------------------------------------------------------------------- 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These favicon methods are exposed to the FaviconService. Instead of calling 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // these methods directly you should call the respective method on the 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // FaviconService. 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by FaviconService to get the favicon bitmaps from the history backend 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // which most closely match |desired_size_in_dip| x |desired_size_in_dip| and 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |desired_scale_factors| for |icon_types|. If |desired_size_in_dip| is 0, 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the largest favicon bitmap for |icon_types| is returned. The returned 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // FaviconBitmapResults will have at most one result for each of 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |desired_scale_factors|. If a favicon bitmap is determined to be the best 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // candidate for multiple scale factors there will be less results. 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |icon_types| has several types, results for only a single type will be 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // FAVICON. 6675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker::TaskId GetFavicons( 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<GURL>& icon_urls, 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int icon_types, 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int desired_size_in_dip, 6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<ui::ScaleFactor>& desired_scale_factors, 672cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const favicon_base::FaviconResultsCallback& callback, 6735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker* tracker); 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by the FaviconService to get favicons mapped to |page_url| for 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |icon_types| which most closely match |desired_size_in_dip| and 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |desired_scale_factors|. If |desired_size_in_dip| is 0, the largest favicon 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // bitmap for |icon_types| is returned. The returned FaviconBitmapResults will 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // have at most one result for each of |desired_scale_factors|. If a favicon 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // bitmap is determined to be the best candidate for multiple scale factors 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // there will be less results. If |icon_types| has several types, results for 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // only a single type will be returned in the priority of 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and FAVICON. 6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker::TaskId GetFaviconsForURL( 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& page_url, 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int icon_types, 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int desired_size_in_dip, 6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<ui::ScaleFactor>& desired_scale_factors, 689cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const favicon_base::FaviconResultsCallback& callback, 6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker* tracker); 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Used by FaviconService to find the first favicon bitmap whose width and 6938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // height are greater than that of |minimum_size_in_pixels|. This searches 6948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // for icons by IconType. Each element of |icon_types| is a bitmask of 6958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // IconTypes indicating the types to search for. 6968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // If the largest icon of |icon_types[0]| is not larger than 6978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // |minimum_size_in_pixel|, the next icon types of 6988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // |icon_types| will be searched and so on. 6998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // If no icon is larger than |minimum_size_in_pixel|, the largest one of all 7008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // icon types in |icon_types| is returned. 7018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // This feature is especially useful when some types of icon is perfered as 7028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // long as its size is larger than a specific value. 7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker::TaskId GetLargestFaviconForURL( 7048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const GURL& page_url, 7058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const std::vector<int>& icon_types, 7068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) int minimum_size_in_pixels, 707cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const favicon_base::FaviconRawCallback& callback, 7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker* tracker); 7098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by the FaviconService to get the favicon bitmap which most closely 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // matches |desired_size_in_dip| and |desired_scale_factor| from the favicon 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // with |favicon_id| from the history backend. If |desired_size_in_dip| is 0, 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the largest favicon bitmap for |favicon_id| is returned. 7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker::TaskId GetFaviconForID( 7150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch favicon_base::FaviconID favicon_id, 7162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int desired_size_in_dip, 7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScaleFactor desired_scale_factor, 718cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const favicon_base::FaviconResultsCallback& callback, 7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker* tracker); 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by the FaviconService to replace the favicon mappings to |page_url| 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for |icon_types| on the history backend. 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sample |icon_urls|: 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // { ICON_URL1 -> TOUCH_ICON, known to the database, 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ICON_URL2 -> TOUCH_ICON, not known to the database, 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The new mappings are computed from |icon_urls| with these rules: 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1) Any urls in |icon_urls| which are not already known to the database are 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // rejected. 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2) If |icon_types| has multiple types, the mappings are only set for the 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // largest icon type. 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sample new mappings to |page_url|: { ICON_URL3 } 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |icon_types| can only have multiple IconTypes if 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The favicon bitmaps which most closely match |desired_size_in_dip| 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and |desired_scale_factors| from the favicons which were just mapped 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to |page_url| are returned. If |desired_size_in_dip| is 0, the 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // largest favicon bitmap is returned. 7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& page_url, 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::vector<GURL>& icon_urls, 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int icon_types, 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int desired_size_in_dip, 7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<ui::ScaleFactor>& desired_scale_factors, 746cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const favicon_base::FaviconResultsCallback& callback, 7475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::CancelableTaskTracker* tracker); 7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Used by FaviconService to set a favicon for |page_url| and |icon_url| with 7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |pixel_size|. 7512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Example: 7522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |page_url|: www.google.com 7532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 2 favicons in history for |page_url|: 7542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // www.google.com/a.ico 16x16 7552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // www.google.com/b.ico 32x32 7562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // MergeFavicon(|page_url|, www.google.com/a.ico, ..., ..., 16x16) 7572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Merging occurs in the following manner: 7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 1) |page_url| is set to map to only to |icon_url|. In order to not lose 7602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // data, favicon bitmaps mapped to |page_url| but not to |icon_url| are 7612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // copied to the favicon at |icon_url|. 7622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // For the example above, |page_url| will only be mapped to a.ico. 7632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The 32x32 favicon bitmap at b.ico is copied to a.ico 7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 2) |bitmap_data| is added to the favicon at |icon_url|, overwriting any 7652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // favicon bitmaps of |pixel_size|. 7662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // For the example above, |bitmap_data| overwrites the 16x16 favicon 7672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // bitmap for a.ico. 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(pkotwicz): Remove once no longer required by sync. 7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void MergeFavicon(const GURL& page_url, 7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& icon_url, 7710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch favicon_base::IconType icon_type, 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<base::RefCountedMemory> bitmap_data, 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Size& pixel_size); 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by the FaviconService to set the favicons for a page on the history 7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // backend. 7772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |favicon_bitmap_data| replaces all the favicon bitmaps mapped to 7782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |page_url|. 7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |expired| and |icon_type| fields in FaviconBitmapData are ignored. 7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Use MergeFavicon() if |favicon_bitmap_data| is incomplete, and favicon 7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // bitmaps in the database should be preserved if possible. For instance, 7822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // favicon bitmaps from sync are 1x only. MergeFavicon() is used to avoid 7832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // deleting the 2x favicon bitmap if it is present in the history backend. 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // See HistoryBackend::ValidateSetFaviconsParams() for more details on the 7852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // criteria for |favicon_bitmap_data| to be valid. 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetFavicons( 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& page_url, 7880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch favicon_base::IconType icon_type, 7890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const std::vector<favicon_base::FaviconBitmapData>& favicon_bitmap_data); 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by the FaviconService to mark the favicon for the page as being out 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of date. 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetFaviconsOutOfDateForPage(const GURL& page_url); 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by the FaviconService to clone favicons from one page to another, 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // provided that other page does not already have favicons. 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url); 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by the FaviconService for importing many favicons for many pages at 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // once. The pages must exist, any favicon sets for unknown pages will be 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // discarded. Existing favicons will not be overwritten. 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetImportedFavicons( 803a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const std::vector<ImportedFaviconUsage>& favicon_usage); 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the in-memory URL database. This is called by the backend once the 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // database is loaded to make it available. 807eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void SetInMemoryBackend( 808eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<history::InMemoryHistoryBackend> mem_backend); 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called by our BackendDelegate when there is a problem reading the database. 811a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void NotifyProfileError(sql::InitStatus init_status); 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Call to schedule a given task for running on the history thread with the 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // specified priority. The task will have ownership taken. 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleTask(SchedulePriority priority, const base::Closure& task); 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Schedule ------------------------------------------------------------------ 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Functions for scheduling operations on the history thread that have a 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // handle and may be cancelable. For fire-and-forget operations, see 8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ScheduleAndForget below. 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, class RequestType> 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle Schedule(SchedulePriority priority, 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on the HistoryBackend. 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RequestType* request) { 8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (consumer) 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddRequest(request, consumer); 8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(func, history_backend_.get(), 8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<RequestType>(request))); 8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return request->handle(); 8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, class RequestType, typename ArgA> 8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle Schedule(SchedulePriority priority, 8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on the HistoryBackend. 8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RequestType* request, 8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgA& a) { 8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (consumer) 8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddRequest(request, consumer); 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, 8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(func, history_backend_.get(), 8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<RequestType>(request), a)); 8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return request->handle(); 8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, 8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class RequestType, // Descendant of CancelableRequestBase. 8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgA, 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgB> 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle Schedule(SchedulePriority priority, 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on the HistoryBackend. 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RequestType* request, 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgA& a, 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgB& b) { 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (consumer) 8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddRequest(request, consumer); 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(func, history_backend_.get(), 8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<RequestType>(request), a, b)); 8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return request->handle(); 8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, 8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class RequestType, // Descendant of CancelableRequestBase. 8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgA, 8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgB, 8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgC> 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle Schedule(SchedulePriority priority, 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on the HistoryBackend. 8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RequestType* request, 8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgA& a, 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgB& b, 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgC& c) { 8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (consumer) 8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddRequest(request, consumer); 8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, 8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(func, history_backend_.get(), 8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<RequestType>(request), a, b, c)); 8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return request->handle(); 8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, 8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class RequestType, // Descendant of CancelableRequestBase. 8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgA, 8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgB, 9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgC, 9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgD> 9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Handle Schedule(SchedulePriority priority, 9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on the HistoryBackend. 9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumerBase* consumer, 9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RequestType* request, 9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgA& a, 9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgB& b, 9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgC& c, 9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgD& d) { 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (consumer) 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddRequest(request, consumer); 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, 9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(func, history_backend_.get(), 9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<RequestType>(request), a, b, c, d)); 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return request->handle(); 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ScheduleAndForget --------------------------------------------------------- 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Functions for scheduling operations on the history thread that do not need 9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // any callbacks and are not cancelable. 9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc> 9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleAndForget(SchedulePriority priority, 9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func) { // Function to call on backend. 9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, base::Bind(func, history_backend_.get())); 9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, typename ArgA> 9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleAndForget(SchedulePriority priority, 9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on backend. 9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgA& a) { 9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, base::Bind(func, history_backend_.get(), a)); 9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, typename ArgA, typename ArgB> 9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleAndForget(SchedulePriority priority, 9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on backend. 9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgA& a, 9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgB& b) { 9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, base::Bind(func, history_backend_.get(), a, b)); 9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, typename ArgA, typename ArgB, typename ArgC> 9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleAndForget(SchedulePriority priority, 9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on backend. 9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgA& a, 9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgB& b, 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgC& c) { 9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, base::Bind(func, history_backend_.get(), a, b, c)); 9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, 9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgA, 9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgB, 9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgC, 9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgD> 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleAndForget(SchedulePriority priority, 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on backend. 9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgA& a, 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgB& b, 9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgC& c, 9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgD& d) { 9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, base::Bind(func, history_backend_.get(), 9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) a, b, c, d)); 9785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename BackendFunc, 9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgA, 9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgB, 9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgC, 9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgD, 9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typename ArgE> 9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleAndForget(SchedulePriority priority, 9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BackendFunc func, // Function to call on backend. 9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgA& a, 9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgB& b, 9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgC& c, 9915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgD& d, 9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ArgE& e) { 9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_) << "History service being called after cleanup"; 9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(thread_checker_.CalledOnValidThread()); 9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleTask(priority, base::Bind(func, history_backend_.get(), 9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) a, b, c, d, e)); 9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // All vended weak pointers are invalidated in Cleanup(). 10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::WeakPtrFactory<HistoryService> weak_ptr_factory_; 10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::ThreadChecker thread_checker_; 10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::NotificationRegistrar registrar_; 10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Some void primitives require some internal processing in the main thread 10075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when done. We use this internal consumer for this purpose. 10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CancelableRequestConsumer internal_consumer_; 10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The thread used by the history service to run complicated operations. 10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |thread_| is NULL once |Cleanup| is NULL. 10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Thread* thread_; 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This class has most of the implementation and runs on the 'thread_'. 10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // You MUST communicate with this class ONLY through the thread_'s 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // message_loop(). 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This pointer will be NULL once Cleanup() has been called, meaning no 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // more calls should be made to the history thread. 10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<history::HistoryBackend> history_backend_; 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A cache of the user-typed URLs kept in memory that is used by the 10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // autocomplete system. This will be NULL until the database has been created 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on the background thread. 10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1028cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // The history client, may be null when testing. The object should otherwise 1029cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // outlive |HistoryService|. 1030cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) history::HistoryClient* history_client_; 1031cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 10325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The profile, may be null when testing. 10335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile_; 10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Used for propagating link highlighting data across renderers. May be null 10362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in tests. 103790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_; 10382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Has the backend finished loading? The backend is loaded once Init has 10405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // completed. 10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool backend_loaded_; 10425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cached values from Init(), used whenever we need to reload the backend. 10442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath history_dir_; 10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BookmarkService* bookmark_service_; 10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool no_db_; 10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The index used for quick history lookups. 10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(mrossetti): Move in_memory_url_index out of history_service. 10505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // See http://crbug.com/138321 10515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; 10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObserverList<history::VisitDatabaseObserver> visit_database_observers_; 10545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) history::DeleteDirectiveHandler delete_directive_handler_; 10562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(HistoryService); 10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 10595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ 1061