Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: chrome/browser/history/text_database_manager.h

Issue 7995: Move Time, TimeDelta and TimeTicks into namespace base. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H__ 5 #ifndef CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H__
6 #define CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H__ 6 #define CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H__
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // In normal operation, URLs will be added as the user visits them, the titles 88 // In normal operation, URLs will be added as the user visits them, the titles
89 // and bodies will come in some time after that. These changes will be 89 // and bodies will come in some time after that. These changes will be
90 // automatically coalesced and added to the database some time in the future 90 // automatically coalesced and added to the database some time in the future
91 // using AddPageData(). 91 // using AddPageData().
92 // 92 //
93 // AddPageURL must be called for a given URL (+ its corresponding ID) before 93 // AddPageURL must be called for a given URL (+ its corresponding ID) before
94 // either the title or body set. The visit ID specifies the visit that will 94 // either the title or body set. The visit ID specifies the visit that will
95 // get updated to refer to the full text indexed information. The visit time 95 // get updated to refer to the full text indexed information. The visit time
96 // should be the time corresponding to that visit in the database. 96 // should be the time corresponding to that visit in the database.
97 void AddPageURL(const GURL& url, URLID url_id, VisitID visit_id, 97 void AddPageURL(const GURL& url, URLID url_id, VisitID visit_id,
98 Time visit_time); 98 base::Time visit_time);
99 void AddPageTitle(const GURL& url, const std::wstring& title); 99 void AddPageTitle(const GURL& url, const std::wstring& title);
100 void AddPageContents(const GURL& url, const std::wstring& body); 100 void AddPageContents(const GURL& url, const std::wstring& body);
101 101
102 // Adds the given data to the appropriate database file, returning true on 102 // Adds the given data to the appropriate database file, returning true on
103 // success. The visit database row identified by |visit_id| will be updated 103 // success. The visit database row identified by |visit_id| will be updated
104 // to refer to the full text index entry. If the visit ID is 0, the visit 104 // to refer to the full text index entry. If the visit ID is 0, the visit
105 // database will not be updated. 105 // database will not be updated.
106 bool AddPageData(const GURL& url, 106 bool AddPageData(const GURL& url,
107 URLID url_id, 107 URLID url_id,
108 VisitID visit_id, 108 VisitID visit_id,
109 Time visit_time, 109 base::Time visit_time,
110 const std::wstring& title, 110 const std::wstring& title,
111 const std::wstring& body); 111 const std::wstring& body);
112 112
113 // Deletes the instance of indexed data identified by the given time and URL. 113 // Deletes the instance of indexed data identified by the given time and URL.
114 // Any changes will be tracked in the optional change set for use when calling 114 // Any changes will be tracked in the optional change set for use when calling
115 // OptimizeChangedDatabases later. change_set can be NULL. 115 // OptimizeChangedDatabases later. change_set can be NULL.
116 void DeletePageData(Time time, const GURL& url, 116 void DeletePageData(base::Time time, const GURL& url,
117 ChangeSet* change_set); 117 ChangeSet* change_set);
118 118
119 // The text database manager keeps a list of changes that are made to the 119 // The text database manager keeps a list of changes that are made to the
120 // file AddPageURL/Title/Body that may not be committed to the database yet. 120 // file AddPageURL/Title/Body that may not be committed to the database yet.
121 // This function removes entires from this list happening between the given 121 // This function removes entires from this list happening between the given
122 // time range. It is called when the user clears their history for a time 122 // time range. It is called when the user clears their history for a time
123 // range, and we don't want any of our data to "leak." 123 // range, and we don't want any of our data to "leak."
124 // 124 //
125 // Either or both times my be is_null to be unbounded in that direction. When 125 // Either or both times my be is_null to be unbounded in that direction. When
126 // non-null, the range is [begin, end). 126 // non-null, the range is [begin, end).
127 void DeleteFromUncommitted(Time begin, Time end); 127 void DeleteFromUncommitted(base::Time begin, base::Time end);
128 128
129 // Same as DeleteFromUncommitted but for a single URL. 129 // Same as DeleteFromUncommitted but for a single URL.
130 void DeleteURLFromUncommitted(const GURL& url); 130 void DeleteURLFromUncommitted(const GURL& url);
131 131
132 // Deletes all full text search data by removing the files from the disk. 132 // Deletes all full text search data by removing the files from the disk.
133 // This must be called OUTSIDE of a transaction since it actually deletes the 133 // This must be called OUTSIDE of a transaction since it actually deletes the
134 // files rather than messing with the database. 134 // files rather than messing with the database.
135 void DeleteAll(); 135 void DeleteAll();
136 136
137 // Calls optimize on all the databases identified in a given change set (see 137 // Calls optimize on all the databases identified in a given change set (see
138 // the definition of ChangeSet above for more). Optimizing means that old data 138 // the definition of ChangeSet above for more). Optimizing means that old data
139 // will be removed rather than marked unused. 139 // will be removed rather than marked unused.
140 void OptimizeChangedDatabases(const ChangeSet& change_set); 140 void OptimizeChangedDatabases(const ChangeSet& change_set);
141 141
142 // Executes the given query. See QueryOptions for more info on input. 142 // Executes the given query. See QueryOptions for more info on input.
143 // 143 //
144 // The results are filled into |results|, and the first time considered for 144 // The results are filled into |results|, and the first time considered for
145 // the output is in |first_time_searched| (see QueryResults for more). 145 // the output is in |first_time_searched| (see QueryResults for more).
146 // 146 //
147 // This function will return more than one match per URL if there is more than 147 // This function will return more than one match per URL if there is more than
148 // one entry for that URL in the database. 148 // one entry for that URL in the database.
149 void GetTextMatches(const std::wstring& query, 149 void GetTextMatches(const std::wstring& query,
150 const QueryOptions& options, 150 const QueryOptions& options,
151 std::vector<TextDatabase::Match>* results, 151 std::vector<TextDatabase::Match>* results,
152 Time* first_time_searched); 152 base::Time* first_time_searched);
153 153
154 private: 154 private:
155 // These tests call ExpireRecentChangesForTime to force expiration. 155 // These tests call ExpireRecentChangesForTime to force expiration.
156 FRIEND_TEST(TextDatabaseManagerTest, InsertPartial); 156 FRIEND_TEST(TextDatabaseManagerTest, InsertPartial);
157 FRIEND_TEST(ExpireHistoryTest, DeleteURLAndFavicon); 157 FRIEND_TEST(ExpireHistoryTest, DeleteURLAndFavicon);
158 FRIEND_TEST(ExpireHistoryTest, FlushRecentURLsUnstarred); 158 FRIEND_TEST(ExpireHistoryTest, FlushRecentURLsUnstarred);
159 159
160 // Stores "recent stuff" that has happened with the page, since the page 160 // Stores "recent stuff" that has happened with the page, since the page
161 // visit, title, and body all come in at different times. 161 // visit, title, and body all come in at different times.
162 class PageInfo { 162 class PageInfo {
163 public: 163 public:
164 PageInfo(URLID url_id, VisitID visit_id, Time visit_time); 164 PageInfo(URLID url_id, VisitID visit_id, base::Time visit_time);
165 165
166 // Getters. 166 // Getters.
167 URLID url_id() const { return url_id_; } 167 URLID url_id() const { return url_id_; }
168 VisitID visit_id() const { return visit_id_; } 168 VisitID visit_id() const { return visit_id_; }
169 Time visit_time() const { return visit_time_; } 169 base::Time visit_time() const { return visit_time_; }
170 const std::wstring& title() const { return title_; } 170 const std::wstring& title() const { return title_; }
171 const std::wstring& body() const { return body_; } 171 const std::wstring& body() const { return body_; }
172 172
173 // Setters, we can only update the title and body. 173 // Setters, we can only update the title and body.
174 void set_title(const std::wstring& ttl); 174 void set_title(const std::wstring& ttl);
175 void set_body(const std::wstring& bdy); 175 void set_body(const std::wstring& bdy);
176 176
177 // Returns true if both the title or body of the entry has been set. Since 177 // Returns true if both the title or body of the entry has been set. Since
178 // both the title and body setters will "fix" empty strings to be a space, 178 // both the title and body setters will "fix" empty strings to be a space,
179 // these indicate if the setter was ever called. 179 // these indicate if the setter was ever called.
180 bool has_title() const { return !title_.empty(); } 180 bool has_title() const { return !title_.empty(); }
181 bool has_body() { return !body_.empty(); } 181 bool has_body() { return !body_.empty(); }
182 182
183 // Returns true if this entry was added too long ago and we should give up 183 // Returns true if this entry was added too long ago and we should give up
184 // waiting for more data. The current time is passed in as an argument so we 184 // waiting for more data. The current time is passed in as an argument so we
185 // can check many without re-querying the timer. 185 // can check many without re-querying the timer.
186 bool Expired(TimeTicks now) const; 186 bool Expired(base::TimeTicks now) const;
187 187
188 private: 188 private:
189 URLID url_id_; 189 URLID url_id_;
190 VisitID visit_id_; 190 VisitID visit_id_;
191 191
192 // Time of the visit of the URL. This will be the value stored in the URL 192 // Time of the visit of the URL. This will be the value stored in the URL
193 // and visit tables for the entry. 193 // and visit tables for the entry.
194 Time visit_time_; 194 base::Time visit_time_;
195 195
196 // When this page entry was created. We have a cap on the maximum time that 196 // When this page entry was created. We have a cap on the maximum time that
197 // an entry will be in the queue before being flushed to the database. 197 // an entry will be in the queue before being flushed to the database.
198 TimeTicks added_time_; 198 base::TimeTicks added_time_;
199 199
200 // Will be the string " " when they are set to distinguish set and unset. 200 // Will be the string " " when they are set to distinguish set and unset.
201 std::wstring title_; 201 std::wstring title_;
202 std::wstring body_; 202 std::wstring body_;
203 }; 203 };
204 204
205 // Converts the given time to a database identifier or vice-versa. 205 // Converts the given time to a database identifier or vice-versa.
206 static TextDatabase::DBIdent TimeToID(Time time); 206 static TextDatabase::DBIdent TimeToID(base::Time time);
207 static Time IDToTime(TextDatabase::DBIdent id); 207 static base::Time IDToTime(TextDatabase::DBIdent id);
208 208
209 // Returns a text database for the given identifier or time. This file will 209 // Returns a text database for the given identifier or time. This file will
210 // be created if it doesn't exist and |for_writing| is set. On error, 210 // be created if it doesn't exist and |for_writing| is set. On error,
211 // including the case where the file doesn't exist and |for_writing| 211 // including the case where the file doesn't exist and |for_writing|
212 // is false, it will return NULL. 212 // is false, it will return NULL.
213 // 213 //
214 // When |for_writing| is set, a transaction on the database will be opened 214 // When |for_writing| is set, a transaction on the database will be opened
215 // if there is a transaction open on this manager. 215 // if there is a transaction open on this manager.
216 // 216 //
217 // The pointer will be tracked in the cache. The caller should not store it 217 // The pointer will be tracked in the cache. The caller should not store it
218 // or delete it since it will get automatically deleted as necessary. 218 // or delete it since it will get automatically deleted as necessary.
219 TextDatabase* GetDB(TextDatabase::DBIdent id, bool for_writing); 219 TextDatabase* GetDB(TextDatabase::DBIdent id, bool for_writing);
220 TextDatabase* GetDBForTime(Time time, bool for_writing); 220 TextDatabase* GetDBForTime(base::Time time, bool for_writing);
221 221
222 // Populates the present_databases_ list based on which files are on disk. 222 // Populates the present_databases_ list based on which files are on disk.
223 // When the list is already initialized, this will do nothing, so you can 223 // When the list is already initialized, this will do nothing, so you can
224 // call it whenever you want to ensure the present_databases_ set is filled. 224 // call it whenever you want to ensure the present_databases_ set is filled.
225 void InitDBList(); 225 void InitDBList();
226 226
227 // Schedules a call to ExpireRecentChanges in the future. 227 // Schedules a call to ExpireRecentChanges in the future.
228 void ScheduleFlushOldChanges(); 228 void ScheduleFlushOldChanges();
229 229
230 // Checks the recent_changes_ list and commits partial data that has been 230 // Checks the recent_changes_ list and commits partial data that has been
231 // around too long. 231 // around too long.
232 void FlushOldChanges(); 232 void FlushOldChanges();
233 233
234 // Given "now," this will expire old things from the recent_changes_ list. 234 // Given "now," this will expire old things from the recent_changes_ list.
235 // This is used as the backend for FlushOldChanges and is called directly 235 // This is used as the backend for FlushOldChanges and is called directly
236 // by the unit tests with fake times. 236 // by the unit tests with fake times.
237 void FlushOldChangesForTime(TimeTicks now); 237 void FlushOldChangesForTime(base::TimeTicks now);
238 238
239 // Directory holding our index files. 239 // Directory holding our index files.
240 const std::wstring dir_; 240 const std::wstring dir_;
241 241
242 // The database connection. 242 // The database connection.
243 sqlite3* db_; 243 sqlite3* db_;
244 DBCloseScoper db_close_scoper_; 244 DBCloseScoper db_close_scoper_;
245 245
246 // Non-owning pointers to the recent history databases for URLs and visits. 246 // Non-owning pointers to the recent history databases for URLs and visits.
247 VisitDatabase* visit_database_; 247 VisitDatabase* visit_database_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // Generates tasks for our periodic checking of expired "recent changes". 290 // Generates tasks for our periodic checking of expired "recent changes".
291 ScopedRunnableMethodFactory<TextDatabaseManager> factory_; 291 ScopedRunnableMethodFactory<TextDatabaseManager> factory_;
292 292
293 DISALLOW_EVIL_CONSTRUCTORS(TextDatabaseManager); 293 DISALLOW_EVIL_CONSTRUCTORS(TextDatabaseManager);
294 }; 294 };
295 295
296 } // namespace history 296 } // namespace history
297 297
298 #endif // CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H__ 298 #endif // CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H__
299 299
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698