1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Contains the history backend wrapper around the in-memory URL database. This
6 // object maintains an in-memory cache of the subset of history required to do
7 // in-line autocomplete.
9 // It is created on the history thread and passed to the main thread where
10 // operations can be completed synchronously. It listens for notifications
11 // from the "regular" history backend and keeps itself in sync.
13 #ifndef CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_
14 #define CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_
18 #include "base/basictypes.h"
19 #include "base/gtest_prod_util.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
33 class InMemoryDatabase;
34 class InMemoryURLIndex;
35 struct KeywordSearchUpdatedDetails;
36 struct KeywordSearchDeletedDetails;
38 struct URLsDeletedDetails;
39 struct URLsModifiedDetails;
41 class InMemoryHistoryBackend : public content::NotificationObserver {
43 InMemoryHistoryBackend();
44 virtual ~InMemoryHistoryBackend();
46 // Initializes the backend from the history database pointed to by the
47 // full path in |history_filename|. |db| is used for setting up the
49 bool Init(const base::FilePath& history_filename, URLDatabase* db);
51 // Does initialization work when this object is attached to the history
52 // system on the main thread. The argument is the profile with which the
53 // attached history service is under.
54 void AttachToHistoryService(Profile* profile);
56 // Returns the underlying database associated with this backend. The current
57 // autocomplete code was written fro this, but it should probably be removed
58 // so that it can deal directly with this object, rather than the DB.
59 InMemoryDatabase* db() const {
63 // Notification callback.
64 virtual void Observe(int type,
65 const content::NotificationSource& source,
66 const content::NotificationDetails& details) OVERRIDE;
69 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll);
71 // Handler for NOTIFY_HISTORY_TYPED_URLS_MODIFIED.
72 void OnTypedURLsModified(const URLsModifiedDetails& details);
74 // Handler for NOTIFY_HISTORY_URLS_DELETED.
75 void OnURLsDeleted(const URLsDeletedDetails& details);
77 // Handler for HISTORY_KEYWORD_SEARCH_TERM_UPDATED.
78 void OnKeywordSearchTermUpdated(const KeywordSearchUpdatedDetails& details);
80 // Handler for HISTORY_KEYWORD_SEARCH_TERM_DELETED.
81 void OnKeywordSearchTermDeleted(const KeywordSearchDeletedDetails& details);
83 // Returns true if there is a keyword associated with the specified url.
84 bool HasKeyword(const GURL& url);
86 content::NotificationRegistrar registrar_;
88 scoped_ptr<InMemoryDatabase> db_;
90 // The profile that this object is attached. May be NULL before
94 DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend);
97 } // namespace history
99 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_