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)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Contains the history backend wrapper around the in-memory URL database. This
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// object maintains an in-memory cache of the subset of history required to do
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in-line autocomplete.
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// It is created on the history thread and passed to the main thread where
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// operations can be completed synchronously. It listens for notifications
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// from the "regular" history backend and keeps itself in sync.
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/gtest_prod_util.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base {
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace history {
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InMemoryDatabase;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InMemoryURLIndex;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct KeywordSearchTermDetails;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLDatabase;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct URLsDeletedDetails;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct URLsModifiedDetails;
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InMemoryHistoryBackend : public content::NotificationObserver {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InMemoryHistoryBackend();
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~InMemoryHistoryBackend();
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initializes the backend from the history database pointed to by the
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // full path in |history_filename|. |db| is used for setting up the
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // InMemoryDatabase.
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool Init(const base::FilePath& history_filename, URLDatabase* db);
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Does initialization work when this object is attached to the history
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // system on the main thread. The argument is the profile with which the
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // attached history service is under.
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AttachToHistoryService(Profile* profile);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the underlying database associated with this backend. The current
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // autocomplete code was written fro this, but it should probably be removed
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // so that it can deal directly with this object, rather than the DB.
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InMemoryDatabase* db() const {
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return db_.get();
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notification callback.
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Observe(int type,
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationSource& source,
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll);
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Handler for NOTIFY_HISTORY_TYPED_URLS_MODIFIED.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnTypedURLsModified(const URLsModifiedDetails& details);
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Handler for NOTIFY_HISTORY_URLS_DELETED.
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnURLsDeleted(const URLsDeletedDetails& details);
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Handler for HISTORY_KEYWORD_SEARCH_TERM_UPDATED.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnKeywordSearchTermUpdated(const KeywordSearchTermDetails& details);
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if there is a keyword associated with the specified url.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HasKeyword(const GURL& url);
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationRegistrar registrar_;
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<InMemoryDatabase> db_;
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The profile that this object is attached. May be NULL before
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // initialization.
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_;
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend);
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace history
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_
96