| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_URL_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_URL_DATABASE_H_ |
| 6 #define CHROME_BROWSER_HISTORY_URL_DATABASE_H_ | 6 #define CHROME_BROWSER_HISTORY_URL_DATABASE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "chrome/browser/history/history_types.h" | 9 #include "chrome/browser/history/history_types.h" |
| 10 #include "chrome/browser/search_engines/template_url_id.h" | 10 #include "chrome/browser/search_engines/template_url_id.h" |
| 11 #include "components/query_parser/query_parser.h" | 11 #include "components/query_parser/query_parser.h" |
| 12 #include "sql/statement.h" | 12 #include "sql/statement.h" |
| 13 | 13 |
| 14 class GURL; | 14 class GURL; |
| 15 | 15 |
| 16 namespace sql { | 16 namespace sql { |
| 17 class Connection; | 17 class Connection; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace history { | 20 namespace history { |
| 21 | 21 |
| 22 class VisitDatabase; // For friend statement. | 22 class VisitDatabase; // For friend statement. |
| 23 | 23 |
| 24 // Encapsulates an SQL database that holds URL info. This is a subset of the | 24 // Encapsulates an SQL database that holds URL info. This is a subset of the |
| 25 // full history data. We split this class' functionality out from the larger | 25 // full history data. We split this class' functionality out from the larger |
| 26 // HistoryDatabase class to support maintaining separate databases of URLs with | 26 // HistoryDatabase class to support maintaining separate databases of URLs with |
| 27 // different capabilities (for example, in-memory, or archived). | 27 // different capabilities (for example, the in-memory database). |
| 28 // | 28 // |
| 29 // This is refcounted to support calling InvokeLater() with some of its methods | 29 // This is refcounted to support calling InvokeLater() with some of its methods |
| 30 // (necessary to maintain ordering of DB operations). | 30 // (necessary to maintain ordering of DB operations). |
| 31 class URLDatabase { | 31 class URLDatabase { |
| 32 public: | 32 public: |
| 33 // Must call CreateURLTable() and CreateURLIndexes() before using to make | 33 // Must call CreateURLTable() and CreateURLIndexes() before using to make |
| 34 // sure the database is initialized. | 34 // sure the database is initialized. |
| 35 URLDatabase(); | 35 URLDatabase(); |
| 36 | 36 |
| 37 // This object must be destroyed on the thread where all accesses are | 37 // This object must be destroyed on the thread where all accesses are |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // Adds a row to the temporary URL table. This must be called between | 104 // Adds a row to the temporary URL table. This must be called between |
| 105 // CreateTemporaryURLTable() and CommitTemporaryURLTable() (see those for more | 105 // CreateTemporaryURLTable() and CommitTemporaryURLTable() (see those for more |
| 106 // info). The ID of the URL will change in the temporary table, so the new ID | 106 // info). The ID of the URL will change in the temporary table, so the new ID |
| 107 // is returned. Returns 0 on failure. | 107 // is returned. Returns 0 on failure. |
| 108 URLID AddTemporaryURL(const URLRow& row) { | 108 URLID AddTemporaryURL(const URLRow& row) { |
| 109 return AddURLInternal(row, true); | 109 return AddURLInternal(row, true); |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Ends the mass-deleting by replacing the original URL table with the | 112 // Ends the mass-deleting by replacing the original URL table with the |
| 113 // temporary one created in CreateTemporaryURLTable. Returns true on success. | 113 // temporary one created in CreateTemporaryURLTable. Returns true on success. |
| 114 // | 114 bool CommitTemporaryURLTable(); |
| 115 // This function does not create the supplimentary indices. It is virtual so | |
| 116 // that the main history database can provide this additional behavior. | |
| 117 virtual bool CommitTemporaryURLTable(); | |
| 118 | 115 |
| 119 // Enumeration --------------------------------------------------------------- | 116 // Enumeration --------------------------------------------------------------- |
| 120 | 117 |
| 121 // A basic enumerator to enumerate urls database. | 118 // A basic enumerator to enumerate urls database. |
| 122 class URLEnumeratorBase { | 119 class URLEnumeratorBase { |
| 123 public: | 120 public: |
| 124 URLEnumeratorBase(); | 121 URLEnumeratorBase(); |
| 125 virtual ~URLEnumeratorBase(); | 122 virtual ~URLEnumeratorBase(); |
| 126 | 123 |
| 127 private: | 124 private: |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 246 |
| 250 // Initialization functions. The indexing functions are separate from the | 247 // Initialization functions. The indexing functions are separate from the |
| 251 // table creation functions so the in-memory database and the temporary tables | 248 // table creation functions so the in-memory database and the temporary tables |
| 252 // used when clearing history can populate the table and then create the | 249 // used when clearing history can populate the table and then create the |
| 253 // index, which is faster than the reverse. | 250 // index, which is faster than the reverse. |
| 254 // | 251 // |
| 255 // is_temporary is false when generating the "regular" URLs table. The expirer | 252 // is_temporary is false when generating the "regular" URLs table. The expirer |
| 256 // sets this to true to generate the temporary table, which will have a | 253 // sets this to true to generate the temporary table, which will have a |
| 257 // different name but the same schema. | 254 // different name but the same schema. |
| 258 bool CreateURLTable(bool is_temporary); | 255 bool CreateURLTable(bool is_temporary); |
| 259 // We have two tiers of indices for the URL table. The main tier is used by | 256 |
| 260 // all URL databases, and is an index over the URL itself. | 257 // Creates the index over URLs so we can quickly look up based on URL. |
| 261 bool CreateMainURLIndex(); | 258 bool CreateMainURLIndex(); |
| 262 | 259 |
| 263 // Ensures the keyword search terms table exists. | 260 // Ensures the keyword search terms table exists. |
| 264 bool InitKeywordSearchTermsTable(); | 261 bool InitKeywordSearchTermsTable(); |
| 265 | 262 |
| 266 // Creates the indices used for keyword search terms. | 263 // Creates the indices used for keyword search terms. |
| 267 bool CreateKeywordSearchTermsIndices(); | 264 bool CreateKeywordSearchTermsIndices(); |
| 268 | 265 |
| 269 // Deletes the keyword search terms table. | 266 // Deletes the keyword search terms table. |
| 270 bool DropKeywordSearchTermsTable(); | 267 bool DropKeywordSearchTermsTable(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 // the macro if you want to put this in the middle of an otherwise constant | 299 // the macro if you want to put this in the middle of an otherwise constant |
| 303 // string, it will save time doing string appends. If you have to build a SQL | 300 // string, it will save time doing string appends. If you have to build a SQL |
| 304 // string dynamically anyway, use the constant, it will save space. | 301 // string dynamically anyway, use the constant, it will save space. |
| 305 #define HISTORY_URL_ROW_FIELDS \ | 302 #define HISTORY_URL_ROW_FIELDS \ |
| 306 " urls.id, urls.url, urls.title, urls.visit_count, urls.typed_count, " \ | 303 " urls.id, urls.url, urls.title, urls.visit_count, urls.typed_count, " \ |
| 307 "urls.last_visit_time, urls.hidden " | 304 "urls.last_visit_time, urls.hidden " |
| 308 | 305 |
| 309 } // namespace history | 306 } // namespace history |
| 310 | 307 |
| 311 #endif // CHROME_BROWSER_HISTORY_URL_DATABASE_H_ | 308 #endif // CHROME_BROWSER_HISTORY_URL_DATABASE_H_ |
| OLD | NEW |