diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-05-20 09:47:09 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-06-07 11:15:42 +0000 |
commit | 189d4fd8fad9e3c776873be51938cd31a42b6177 (patch) | |
tree | 6497caeff5e383937996768766ab3bb2081a40b2 /chromium/sql | |
parent | 8bc75099d364490b22f43a7ce366b366c08f4164 (diff) | |
download | qtwebengine-chromium-189d4fd8fad9e3c776873be51938cd31a42b6177.tar.gz |
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/sql')
-rw-r--r-- | chromium/sql/OWNERS | 2 | ||||
-rw-r--r-- | chromium/sql/database.h | 80 | ||||
-rw-r--r-- | chromium/sql/database_unittest.cc | 20 | ||||
-rw-r--r-- | chromium/sql/meta_table.h | 10 | ||||
-rw-r--r-- | chromium/sql/recover_module/pager.cc | 7 | ||||
-rw-r--r-- | chromium/sql/recover_module/pager.h | 2 | ||||
-rw-r--r-- | chromium/sql/statement.cc | 137 | ||||
-rw-r--r-- | chromium/sql/statement.h | 17 |
8 files changed, 200 insertions, 75 deletions
diff --git a/chromium/sql/OWNERS b/chromium/sql/OWNERS index 82632a40b36..f1d3c71464f 100644 --- a/chromium/sql/OWNERS +++ b/chromium/sql/OWNERS @@ -1,3 +1,5 @@ +set noparent + # Primary: pwnall@chromium.org diff --git a/chromium/sql/database.h b/chromium/sql/database.h index b4eeb9b0c6a..35601a48e1d 100644 --- a/chromium/sql/database.h +++ b/chromium/sql/database.h @@ -56,6 +56,19 @@ struct COMPONENT_EXPORT(SQL) DatabaseOptions { // If true, the database can only be opened by one process at a time. // + // SQLite supports a locking protocol that allows multiple processes to safely + // operate on the same database at the same time. The locking protocol is used + // on every transaction, and comes with a small performance penalty. + // + // Setting this to true causes the locking protocol to be used once, when the + // database is opened. No other process will be able to access the database at + // the same time. + // + // More details at https://www.sqlite.org/pragma.html#pragma_locking_mode + // + // SQLite's locking protocol is summarized at + // https://www.sqlite.org/c3ref/io_methods.html + // // Exclusive mode is strongly recommended. It reduces the I/O cost of setting // up a transaction. It also removes the need of handling transaction failures // due to lock contention. @@ -67,6 +80,13 @@ struct COMPONENT_EXPORT(SQL) DatabaseOptions { // Chrome features yet. In particular, our custom database recovery code does // not support the WAL log file. // + // WAL mode is currently not fully supported on FuchsiaOS. It will only be + // turned on if the database is also using exclusive locking mode. + // (https://crbug.com/1082059) + // + // Note: Changing page size is not supported when in WAL mode. So running + // 'PRAGMA page_size = <new-size>' will result in no-ops. + // // More details at https://www.sqlite.org/wal.html bool wal_mode = base::FeatureList::IsEnabled(sql::features::kEnableWALModeByDefault); @@ -76,6 +96,8 @@ struct COMPONENT_EXPORT(SQL) DatabaseOptions { // Larger page sizes result in shallower B-trees, because they allow an inner // page to hold more keys. On the flip side, larger page sizes may result in // more I/O when making small changes to existing records. + // + // Must be a power of two between 512 and 65536 inclusive. int page_size = kDefaultPageSize; // The size of in-memory cache, in pages. @@ -116,70 +138,12 @@ class COMPONENT_EXPORT(SQL) Database { // Pre-init configuration ---------------------------------------------------- - // Sets the page size that will be used when creating a new database. This - // must be called before Init(), and will only have an effect on new - // databases. - // - // The page size must be a power of two between 512 and 65536 inclusive. - void set_page_size(int page_size) { - DCHECK_GE(page_size, 512); - DCHECK_LE(page_size, 65536); - DCHECK(!(page_size & (page_size - 1))) - << "page_size must be a power of two"; - - options_.page_size = page_size; - } - // The page size that will be used when creating a new database. int page_size() const { return options_.page_size; } - // Sets the number of pages that will be cached in memory by sqlite. The - // total cache size in bytes will be page_size * cache_size. This must be - // called before Open() to have an effect. - void set_cache_size(int cache_size) { - DCHECK_GE(cache_size, 0); - - options_.cache_size = cache_size; - } - // Returns whether a database will be opened in WAL mode. bool UseWALMode() const; - // Enables/disables WAL mode (https://www.sqlite.org/wal.html) when - // opening a new database. - // - // WAL mode is currently not fully supported on FuchsiaOS. It will only be - // turned on if the database is also using exclusive locking mode. - // (https://crbug.com/1082059) - // - // Note: Changing page size is not supported when in WAL mode. So running - // 'PRAGMA page_size = <new-size>' or using set_page_size will result in - // no-ops. - // - // This must be called before Open() to have an effect. - void want_wal_mode(bool enabled) { options_.wal_mode = enabled; } - - // Makes database accessible by only one process at a time. - // - // TODO(https://crbug.com/1120969): This should be the default mode. The - // "NORMAL" mode should be opt-in. - // - // SQLite supports a locking protocol that allows multiple processes to safely - // operate on the same database at the same time. The locking protocol is used - // on every transaction, and comes with a small performance penalty. - // - // Calling this method causes the locking protocol to be used once, when the - // database is opened. No other process will be able to access the database at - // the same time. - // - // This method must be called before Open() to have an effect. - // - // More details at https://www.sqlite.org/pragma.html#pragma_locking_mode - // - // SQLite's locking protocol is summarized at - // https://www.sqlite.org/c3ref/io_methods.html - void set_exclusive_locking() { options_.exclusive_locking = true; } - // Call to use alternative status-tracking for mmap. Usually this is tracked // in the meta table, but some databases have no meta table. // TODO(shess): Maybe just have all databases use the alt option? diff --git a/chromium/sql/database_unittest.cc b/chromium/sql/database_unittest.cc index df610537ec1..9ae6a176e67 100644 --- a/chromium/sql/database_unittest.cc +++ b/chromium/sql/database_unittest.cc @@ -853,13 +853,6 @@ TEST_P(SQLDatabaseTest, Delete) { EXPECT_FALSE(GetPathExists(wal_path)); } -// WAL mode is currently not supported on Fuchsia -#if !defined(OS_FUCHSIA) -INSTANTIATE_TEST_SUITE_P(JournalMode, SQLDatabaseTest, testing::Bool()); -#else -INSTANTIATE_TEST_SUITE_P(JournalMode, SQLDatabaseTest, testing::Values(false)); -#endif - #if defined(OS_POSIX) // This test operates on POSIX file permissions. TEST_P(SQLDatabaseTest, PosixFilePermissions) { db().Close(); @@ -1375,4 +1368,17 @@ TEST_P(SQLDatabaseTest, CompileError) { #endif // !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_FUCHSIA) } +// WAL mode is currently not supported on Fuchsia. +#if !defined(OS_FUCHSIA) +INSTANTIATE_TEST_SUITE_P(JournalMode, SQLDatabaseTest, testing::Bool()); +INSTANTIATE_TEST_SUITE_P(JournalMode, + SQLDatabaseTestExclusiveMode, + testing::Bool()); +#else +INSTANTIATE_TEST_SUITE_P(JournalMode, SQLDatabaseTest, testing::Values(false)); +INSTANTIATE_TEST_SUITE_P(JournalMode, + SQLDatabaseTestExclusiveMode, + testing::Values(false)); +#endif + } // namespace sql diff --git a/chromium/sql/meta_table.h b/chromium/sql/meta_table.h index 02aa88b3d4b..f591ab3a1a6 100644 --- a/chromium/sql/meta_table.h +++ b/chromium/sql/meta_table.h @@ -76,16 +76,18 @@ class COMPONENT_EXPORT(SQL) MetaTable { void SetVersionNumber(int version); int GetVersionNumber(); - // The compatible version number is the lowest version of the code that this - // database can be read by. If there are minor changes or additions, old - // versions of the code can still work with the database without failing. + // The compatible version number is the lowest current version embedded in + // Chrome code that can still use this database. This is usually the same as + // the current version. In some limited cases, such as adding a column without + // a NOT NULL constraint, the SQL queries embedded in older code can still + // execute successfully. // // For example, if an optional column is added to a table in version 3, the // new code will set the version to 3, and the compatible version to 2, since // the code expecting version 2 databases can still read and write the table. // // Rule of thumb: check the version number when you're upgrading, but check - // the compatible version number to see if you can read the file at all. If + // the compatible version number to see if you can use the file at all. If // it's larger than you code is expecting, fail. // // The compatible version number will be 0 if there is no previously set diff --git a/chromium/sql/recover_module/pager.cc b/chromium/sql/recover_module/pager.cc index c16aea6d74f..58e75de2704 100644 --- a/chromium/sql/recover_module/pager.cc +++ b/chromium/sql/recover_module/pager.cc @@ -50,8 +50,9 @@ int DatabasePageReader::ReadPage(int page_id) { DCHECK_GE(page_size_, kMinUsablePageSize); DCHECK_LE(page_size_, kMaxPageSize); - const int64_t read_offset = (page_id - 1) * page_size + page_offset; - static_assert((kMaxPageId - 1) * static_cast<int64_t>(kMaxPageSize) + + const int64_t read_offset = + static_cast<int64_t>(page_id - 1) * page_size + page_offset; + static_assert(static_cast<int64_t>(kMaxPageId - 1) * kMaxPageSize + kDatabaseHeaderSize <= std::numeric_limits<int64_t>::max(), "The |read_offset| computation above may overflow"); @@ -118,4 +119,4 @@ int DatabasePageReader::RawRead(sqlite3_file* sqlite_file, } } // namespace recover -} // namespace sql
\ No newline at end of file +} // namespace sql diff --git a/chromium/sql/recover_module/pager.h b/chromium/sql/recover_module/pager.h index 5533c5b5d8c..0e388ddc3b0 100644 --- a/chromium/sql/recover_module/pager.h +++ b/chromium/sql/recover_module/pager.h @@ -45,7 +45,7 @@ class DatabasePageReader { // after the database header. static constexpr int kMinUsablePageSize = kMinPageSize - kDatabaseHeaderSize; - // Maximum number of pages in a SQLite database. + // Largest valid page ID in a SQLite database. // // This is the maximum value of SQLITE_MAX_PAGE_COUNT plus 1, because page IDs // start at 1. The numerical value, which is the same as diff --git a/chromium/sql/statement.cc b/chromium/sql/statement.cc index e953caf483c..c3a2a70be0e 100644 --- a/chromium/sql/statement.cc +++ b/chromium/sql/statement.cc @@ -9,9 +9,11 @@ #include "base/logging.h" #include "base/numerics/safe_conversions.h" +#include "base/sequence_checker.h" #include "base/strings/string_piece_forward.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" +#include "build/build_config.h" // TODO(crbug.com/866218): Remove this include. #include "third_party/sqlite/sqlite3.h" namespace sql { @@ -28,6 +30,10 @@ Statement::Statement(scoped_refptr<Database::StatementRef> ref) : ref_(std::move(ref)) {} Statement::~Statement() { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // !defined(OS_ANDROID) + // Free the resources associated with this statement. We assume there's only // one statement active for a given sqlite3_stmt at any time, so this won't // mess with anything. @@ -35,16 +41,28 @@ Statement::~Statement() { } void Statement::Assign(scoped_refptr<Database::StatementRef> ref) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // !defined(OS_ANDROID) + Reset(true); ref_ = std::move(ref); } void Statement::Clear() { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // !defined(OS_ANDROID) + Assign(base::MakeRefCounted<Database::StatementRef>(nullptr, nullptr, false)); succeeded_ = false; } bool Statement::CheckValid() const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // !defined(OS_ANDROID) + // Allow operations to fail silently if a statement was invalidated // because the database was closed by an error handler. DLOG_IF(FATAL, !ref_->was_valid()) @@ -53,6 +71,10 @@ bool Statement::CheckValid() const { } int Statement::StepInternal() { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return SQLITE_ERROR; @@ -65,15 +87,27 @@ int Statement::StepInternal() { } bool Statement::Run() { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + DCHECK(!stepped_); return StepInternal() == SQLITE_DONE; } bool Statement::Step() { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + return StepInternal() == SQLITE_ROW; } void Statement::Reset(bool clear_bound_vars) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + base::Optional<base::ScopedBlockingCall> scoped_blocking_call; ref_->InitScopedBlockingCall(FROM_HERE, &scoped_blocking_call); if (is_valid()) { @@ -97,38 +131,61 @@ void Statement::Reset(bool clear_bound_vars) { } bool Statement::Succeeded() const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + return is_valid() && succeeded_; } bool Statement::BindNull(int col) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID DCHECK(!stepped_); return is_valid() && CheckOk(sqlite3_bind_null(ref_->stmt(), col + 1)); } bool Statement::BindBool(int col, bool val) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + return BindInt(col, val ? 1 : 0); } bool Statement::BindInt(int col, int val) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID DCHECK(!stepped_); return is_valid() && CheckOk(sqlite3_bind_int(ref_->stmt(), col + 1, val)); } bool Statement::BindInt64(int col, int64_t val) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID DCHECK(!stepped_); return is_valid() && CheckOk(sqlite3_bind_int64(ref_->stmt(), col + 1, val)); } bool Statement::BindDouble(int col, double val) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID DCHECK(!stepped_); return is_valid() && CheckOk(sqlite3_bind_double(ref_->stmt(), col + 1, val)); } bool Statement::BindCString(int col, const char* val) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID DCHECK(!stepped_); return is_valid() && CheckOk(sqlite3_bind_text(ref_->stmt(), col + 1, val, -1, @@ -136,6 +193,9 @@ bool Statement::BindCString(int col, const char* val) { } bool Statement::BindString(int col, const std::string& val) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID DCHECK(!stepped_); return is_valid() && @@ -145,10 +205,17 @@ bool Statement::BindString(int col, const std::string& val) { } bool Statement::BindString16(int col, base::StringPiece16 value) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + return BindString(col, base::UTF16ToUTF8(value)); } bool Statement::BindBlob(int col, const void* val, int val_len) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID DCHECK(!stepped_); return is_valid() && CheckOk(sqlite3_bind_blob(ref_->stmt(), col + 1, val, @@ -156,6 +223,10 @@ bool Statement::BindBlob(int col, const void* val, int val_len) { } int Statement::ColumnCount() const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!is_valid()) return 0; return sqlite3_column_count(ref_->stmt()); @@ -174,32 +245,56 @@ static_assert(static_cast<int>(ColumnType::kNull) == SQLITE_NULL, "NULL mismatch"); ColumnType Statement::GetColumnType(int col) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + return static_cast<enum ColumnType>(sqlite3_column_type(ref_->stmt(), col)); } bool Statement::ColumnBool(int col) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + return static_cast<bool>(ColumnInt(col)); } int Statement::ColumnInt(int col) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return 0; return sqlite3_column_int(ref_->stmt(), col); } int64_t Statement::ColumnInt64(int col) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return 0; return sqlite3_column_int64(ref_->stmt(), col); } double Statement::ColumnDouble(int col) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return 0; return sqlite3_column_double(ref_->stmt(), col); } std::string Statement::ColumnString(int col) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return std::string(); @@ -214,6 +309,10 @@ std::string Statement::ColumnString(int col) const { } base::string16 Statement::ColumnString16(int col) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return base::string16(); @@ -222,12 +321,20 @@ base::string16 Statement::ColumnString16(int col) const { } int Statement::ColumnByteLength(int col) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return 0; return sqlite3_column_bytes(ref_->stmt(), col); } const void* Statement::ColumnBlob(int col) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return nullptr; @@ -235,6 +342,10 @@ const void* Statement::ColumnBlob(int col) const { } bool Statement::ColumnBlobAsString(int col, std::string* blob) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return false; @@ -249,6 +360,10 @@ bool Statement::ColumnBlobAsString(int col, std::string* blob) const { } bool Statement::ColumnBlobAsString16(int col, base::string16* val) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + if (!CheckValid()) return false; @@ -262,6 +377,10 @@ bool Statement::ColumnBlobAsString16(int col, base::string16* val) const { } bool Statement::ColumnBlobAsVector(int col, std::vector<char>* val) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + val->clear(); if (!CheckValid()) @@ -279,14 +398,26 @@ bool Statement::ColumnBlobAsVector(int col, std::vector<char>* val) const { bool Statement::ColumnBlobAsVector( int col, std::vector<unsigned char>* val) const { - return ColumnBlobAsVector(col, reinterpret_cast< std::vector<char>* >(val)); +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + + return ColumnBlobAsVector(col, reinterpret_cast<std::vector<char>*>(val)); } const char* Statement::GetSQLStatement() { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + return sqlite3_sql(ref_->stmt()); } bool Statement::CheckOk(int err) const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + // Binding to a non-existent variable is evidence of a serious error. // TODO(gbillock,shess): make this invalidate the statement so it // can't wreak havoc. @@ -295,6 +426,10 @@ bool Statement::CheckOk(int err) const { } int Statement::CheckError(int err) { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // OS_ANDROID + // Please don't add DCHECKs here, OnSqliteError() already has them. succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); if (!succeeded_ && ref_.get() && ref_->database()) diff --git a/chromium/sql/statement.h b/chromium/sql/statement.h index c609610ecd1..4ae259ba4f7 100644 --- a/chromium/sql/statement.h +++ b/chromium/sql/statement.h @@ -6,6 +6,7 @@ #define SQL_STATEMENT_H_ #include <stdint.h> + #include <string> #include <vector> @@ -15,6 +16,7 @@ #include "base/sequence_checker.h" #include "base/strings/string16.h" #include "base/strings/string_piece_forward.h" +#include "build/build_config.h" // TODO(crbug.com/866218): Remove this include. #include "sql/database.h" namespace sql { @@ -29,6 +31,11 @@ enum class ColumnType { kNull = 5, }; +// Compiles and executes SQL statements. +// +// This class is not thread-safe. An instance must be accessed from a single +// sequence. This is enforced in DCHECK-enabled builds. +// // Normal usage: // sql::Statement s(connection_.GetUniqueStatement(...)); // s.BindInt(0, a); @@ -66,7 +73,13 @@ class COMPONENT_EXPORT(SQL) Statement { // default value. This is because the statement can become invalid in the // middle of executing a command if there is a serious error and the database // has to be reset. - bool is_valid() const { return ref_->is_valid(); } + bool is_valid() const { +#if !defined(OS_ANDROID) // TODO(crbug.com/866218): Remove this conditional + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +#endif // !defined(OS_ANDROID) + + return ref_->is_valid(); + } // Running ------------------------------------------------------------------- @@ -195,6 +208,8 @@ class COMPONENT_EXPORT(SQL) Statement { // See Succeeded() for what this holds. bool succeeded_ = false; + SEQUENCE_CHECKER(sequence_checker_); + DISALLOW_COPY_AND_ASSIGN(Statement); }; |