- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / in_memory_history_backend.h
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.
4
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.
8 //
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.
12
13 #ifndef CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_
14 #define CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_
15
16 #include <string>
17
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"
23
24 class GURL;
25 class Profile;
26
27 namespace base {
28 class FilePath;
29 }
30
31 namespace history {
32
33 class InMemoryDatabase;
34 class InMemoryURLIndex;
35 struct KeywordSearchUpdatedDetails;
36 struct KeywordSearchDeletedDetails;
37 class URLDatabase;
38 struct URLsDeletedDetails;
39 struct URLsModifiedDetails;
40
41 class InMemoryHistoryBackend : public content::NotificationObserver {
42  public:
43   InMemoryHistoryBackend();
44   virtual ~InMemoryHistoryBackend();
45
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
48   // InMemoryDatabase.
49   bool Init(const base::FilePath& history_filename, URLDatabase* db);
50
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);
55
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 {
60     return db_.get();
61   }
62
63   // Notification callback.
64   virtual void Observe(int type,
65                        const content::NotificationSource& source,
66                        const content::NotificationDetails& details) OVERRIDE;
67
68  private:
69   FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll);
70
71   // Handler for NOTIFY_HISTORY_TYPED_URLS_MODIFIED.
72   void OnTypedURLsModified(const URLsModifiedDetails& details);
73
74   // Handler for NOTIFY_HISTORY_URLS_DELETED.
75   void OnURLsDeleted(const URLsDeletedDetails& details);
76
77   // Handler for HISTORY_KEYWORD_SEARCH_TERM_UPDATED.
78   void OnKeywordSearchTermUpdated(const KeywordSearchUpdatedDetails& details);
79
80   // Handler for HISTORY_KEYWORD_SEARCH_TERM_DELETED.
81   void OnKeywordSearchTermDeleted(const KeywordSearchDeletedDetails& details);
82
83   // Returns true if there is a keyword associated with the specified url.
84   bool HasKeyword(const GURL& url);
85
86   content::NotificationRegistrar registrar_;
87
88   scoped_ptr<InMemoryDatabase> db_;
89
90   // The profile that this object is attached. May be NULL before
91   // initialization.
92   Profile* profile_;
93
94   DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend);
95 };
96
97 }  // namespace history
98
99 #endif  // CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_