OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Contains the history backend wrapper around the in-memory URL database. This | 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 | 6 // object maintains an in-memory cache of the subset of history required to do |
7 // in-line autocomplete. | 7 // in-line autocomplete. |
8 // | 8 // |
9 // It is created on the history thread and passed to the main thread where | 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 | 10 // operations can be completed synchronously. It listens for notifications |
(...skipping 23 matching lines...) Expand all Loading... |
34 class URLDatabase; | 34 class URLDatabase; |
35 struct URLsDeletedDetails; | 35 struct URLsDeletedDetails; |
36 struct URLsModifiedDetails; | 36 struct URLsModifiedDetails; |
37 | 37 |
38 class InMemoryHistoryBackend : public content::NotificationObserver { | 38 class InMemoryHistoryBackend : public content::NotificationObserver { |
39 public: | 39 public: |
40 InMemoryHistoryBackend(); | 40 InMemoryHistoryBackend(); |
41 virtual ~InMemoryHistoryBackend(); | 41 virtual ~InMemoryHistoryBackend(); |
42 | 42 |
43 // Initializes the backend from the history database pointed to by the | 43 // Initializes the backend from the history database pointed to by the |
44 // full path in |history_filename|. |history_dir| is the path to the | 44 // full path in |history_filename|. |db| is used for setting up the |
45 // directory containing the history database and is also used | 45 // InMemoryDatabase. |
46 // as the directory where the InMemoryURLIndex's cache is kept. |db| is | 46 bool Init(const FilePath& history_filename, URLDatabase* db); |
47 // used for building the InMemoryURLIndex. |languages| gives the | |
48 // preferred user languages with which URLs and page titles are | |
49 // interpreted while decomposing into words and characters during indexing. | |
50 bool Init(const FilePath& history_filename, | |
51 const FilePath& history_dir, | |
52 URLDatabase* db, | |
53 const std::string& languages); | |
54 | 47 |
55 // Does initialization work when this object is attached to the history | 48 // Does initialization work when this object is attached to the history |
56 // system on the main thread. The argument is the profile with which the | 49 // system on the main thread. The argument is the profile with which the |
57 // attached history service is under. | 50 // attached history service is under. |
58 void AttachToHistoryService(Profile* profile); | 51 void AttachToHistoryService(Profile* profile); |
59 | 52 |
60 // Returns the underlying database associated with this backend. The current | 53 // Returns the underlying database associated with this backend. The current |
61 // autocomplete code was written fro this, but it should probably be removed | 54 // autocomplete code was written fro this, but it should probably be removed |
62 // so that it can deal directly with this object, rather than the DB. | 55 // so that it can deal directly with this object, rather than the DB. |
63 InMemoryDatabase* db() const { | 56 InMemoryDatabase* db() const { |
64 return db_.get(); | 57 return db_.get(); |
65 } | 58 } |
66 | 59 |
67 // Notification callback. | 60 // Notification callback. |
68 virtual void Observe(int type, | 61 virtual void Observe(int type, |
69 const content::NotificationSource& source, | 62 const content::NotificationSource& source, |
70 const content::NotificationDetails& details) OVERRIDE; | 63 const content::NotificationDetails& details) OVERRIDE; |
71 | 64 |
72 // Return the quick history index. | |
73 history::InMemoryURLIndex* InMemoryIndex() const { return index_.get(); } | |
74 | |
75 private: | 65 private: |
76 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll); | 66 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll); |
77 | 67 |
78 // Handler for NOTIFY_HISTORY_TYPED_URLS_MODIFIED. | 68 // Handler for NOTIFY_HISTORY_TYPED_URLS_MODIFIED. |
79 void OnTypedURLsModified(const URLsModifiedDetails& details); | 69 void OnTypedURLsModified(const URLsModifiedDetails& details); |
80 | 70 |
81 // Handler for NOTIFY_HISTORY_URLS_DELETED. | 71 // Handler for NOTIFY_HISTORY_URLS_DELETED. |
82 void OnURLsDeleted(const URLsDeletedDetails& details); | 72 void OnURLsDeleted(const URLsDeletedDetails& details); |
83 | 73 |
84 // Handler for HISTORY_KEYWORD_SEARCH_TERM_UPDATED. | 74 // Handler for HISTORY_KEYWORD_SEARCH_TERM_UPDATED. |
85 void OnKeywordSearchTermUpdated(const KeywordSearchTermDetails& details); | 75 void OnKeywordSearchTermUpdated(const KeywordSearchTermDetails& details); |
86 | 76 |
87 // Returns true if there is a keyword associated with the specified url. | 77 // Returns true if there is a keyword associated with the specified url. |
88 bool HasKeyword(const GURL& url); | 78 bool HasKeyword(const GURL& url); |
89 | 79 |
90 content::NotificationRegistrar registrar_; | 80 content::NotificationRegistrar registrar_; |
91 | 81 |
92 scoped_ptr<InMemoryDatabase> db_; | 82 scoped_ptr<InMemoryDatabase> db_; |
93 | 83 |
94 // The profile that this object is attached. May be NULL before | 84 // The profile that this object is attached. May be NULL before |
95 // initialization. | 85 // initialization. |
96 Profile* profile_; | 86 Profile* profile_; |
97 | 87 |
98 // The index used for quick history lookups. | |
99 scoped_ptr<history::InMemoryURLIndex> index_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend); | 88 DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend); |
102 }; | 89 }; |
103 | 90 |
104 } // namespace history | 91 } // namespace history |
105 | 92 |
106 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_ | 93 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_ |
OLD | NEW |