Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_META_TABLE_HELPER_H__ | 5 #ifndef CHROME_BROWSER_META_TABLE_HELPER_H__ |
| 6 #define CHROME_BROWSER_META_TABLE_HELPER_H__ | 6 #define CHROME_BROWSER_META_TABLE_HELPER_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 | 11 |
| 12 struct sqlite3; | 12 struct sqlite3; |
| 13 class SQLStatement; | 13 class SQLStatement; |
| 14 | 14 |
| 15 // MetaTableHelper maintains arbitrary key/value pairs in a table, as well | 15 // MetaTableHelper maintains arbitrary key/value pairs in a table, as well |
| 16 // as version information. MetaTableHelper is used by both WebDatabase and | 16 // as version information. MetaTableHelper is used by both WebDatabase and |
| 17 // HistoryDatabase to maintain version information. | 17 // HistoryDatabase to maintain version information. |
| 18 // | 18 // |
| 19 // To use a MetalTableHelper you must invoke the init method specifying the | 19 // To use a MetalTableHelper you must invoke the init method specifying the |
| 20 // database to use. | 20 // database to use. |
| 21 class MetaTableHelper { | 21 class MetaTableHelper { |
| 22 public: | 22 public: |
| 23 // Primes the sqlite cache by filling it with the file in sequence | |
| 24 // until there is no more data or the cache is full. Since this is one | |
| 25 // contiguous read operation, it is much faster than letting the pages come | |
| 26 // in on-demand (which causes lots of seeks). | |
| 27 static void PrimeCache(const std::string& db_name, sqlite3* db); | |
| 28 | |
| 23 // Creates a new MetaTableHelper. After construction you must invoke | 29 // Creates a new MetaTableHelper. After construction you must invoke |
| 24 // Init with the appropriate database. | 30 // Init with the appropriate database. |
| 25 MetaTableHelper(); | 31 MetaTableHelper(); |
| 26 ~MetaTableHelper(); | 32 ~MetaTableHelper(); |
| 27 | 33 |
| 28 // Initializes the MetaTableHelper, creating the meta table if necessary. For | 34 // Initializes the MetaTableHelper, creating the meta table if necessary. For |
| 29 // new tables, it will initialize the version number to |version| and the | 35 // new tables, it will initialize the version number to |version| and the |
| 30 // compatible version number to |compatible_version|. | 36 // compatible version number to |compatible_version|. |
| 31 // | 37 // |
| 32 // The name of the database in the sqlite connection (for tables named with | 38 // The name of the database in the sqlite connection (for tables named with |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 62 | 68 |
| 63 // Arbitrary key/value pair with an int value. | 69 // Arbitrary key/value pair with an int value. |
| 64 bool SetValue(const std::string& key, int value); | 70 bool SetValue(const std::string& key, int value); |
| 65 bool GetValue(const std::string& key, int* value); | 71 bool GetValue(const std::string& key, int* value); |
| 66 | 72 |
| 67 // Arbitrary key/value pair with an int64 value. | 73 // Arbitrary key/value pair with an int64 value. |
| 68 bool SetValue(const std::string& key, int64 value); | 74 bool SetValue(const std::string& key, int64 value); |
| 69 bool GetValue(const std::string& key, int64* value); | 75 bool GetValue(const std::string& key, int64* value); |
| 70 | 76 |
| 71 private: | 77 private: |
| 78 friend class MetaTableHelperTest; | |
|
M-A Ruel
2009/07/01 10:59:34
you could also use FRIEND_TEST() in gtest_prod.h.
| |
| 79 | |
| 80 // Appends the meta table name to the SQL statement. | |
| 81 static void appendMetaTableName(const std::string& db_name, std::string* sql); | |
| 82 | |
| 72 // Conveniences to prepare the two types of statements used by | 83 // Conveniences to prepare the two types of statements used by |
| 73 // MetaTableHelper. | 84 // MetaTableHelper. |
| 74 bool PrepareSetStatement(SQLStatement* statement, const std::string& key); | 85 bool PrepareSetStatement(SQLStatement* statement, const std::string& key); |
| 75 bool PrepareGetStatement(SQLStatement* statement, const std::string& key); | 86 bool PrepareGetStatement(SQLStatement* statement, const std::string& key); |
| 76 | 87 |
| 77 sqlite3* db_; | 88 sqlite3* db_; |
| 78 | 89 |
| 79 // Name of the database within the connection, if there is one. When empty, | 90 // Name of the database within the connection, if there is one. When empty, |
| 80 // there is no special database name. | 91 // there is no special database name. |
| 81 std::string db_name_; | 92 std::string db_name_; |
| 82 | 93 |
| 83 DISALLOW_EVIL_CONSTRUCTORS(MetaTableHelper); | 94 DISALLOW_EVIL_CONSTRUCTORS(MetaTableHelper); |
| 84 }; | 95 }; |
| 85 | 96 |
| 86 #endif // CHROME_BROWSER_META_TABLE_HELPER_H__ | 97 #endif // CHROME_BROWSER_META_TABLE_HELPER_H__ |
| OLD | NEW |