diff options
author | Iain Merrick <husky@google.com> | 2010-10-19 14:37:37 +0100 |
---|---|---|
committer | Iain Merrick <husky@google.com> | 2010-10-19 14:37:37 +0100 |
commit | 3345a6884c488ff3a535c2c9acdd33d74b37e311 (patch) | |
tree | 7784b988ef1698cb6967ea1bdf07616237716c6c /app | |
parent | efc8475837ec58186051f23bb03542620424f6ce (diff) | |
download | external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.zip external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.tar.gz external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.tar.bz2 |
Merge Chromium at 7.0.540.0 : Initial merge by git
Not including third_party/icu as it contains huge data files that break Gerrit, and aren't actually used.
Change-Id: I428a386e70f3b58cacd28677b8cfda282e891e15
Diffstat (limited to 'app')
-rw-r--r-- | app/sql/DEPS | 2 | ||||
-rw-r--r-- | app/sql/connection.cc | 107 | ||||
-rw-r--r-- | app/sql/connection.h | 13 | ||||
-rw-r--r-- | app/sql/connection_unittest.cc | 6 | ||||
-rw-r--r-- | app/sql/diagnostic_error_delegate.h | 9 | ||||
-rw-r--r-- | app/sql/init_status.h | 1 | ||||
-rw-r--r-- | app/sql/meta_table.h | 1 | ||||
-rw-r--r-- | app/sql/statement.cc | 4 | ||||
-rw-r--r-- | app/sql/statement.h | 1 | ||||
-rw-r--r-- | app/sql/statement_unittest.cc | 2 | ||||
-rw-r--r-- | app/sql/transaction.cc | 6 | ||||
-rw-r--r-- | app/sql/transaction.h | 1 | ||||
-rw-r--r-- | app/sql/transaction_unittest.cc | 2 |
13 files changed, 131 insertions, 24 deletions
diff --git a/app/sql/DEPS b/app/sql/DEPS index 7bfcce1..0f76c3a 100644 --- a/app/sql/DEPS +++ b/app/sql/DEPS @@ -1,3 +1,3 @@ include_rules = [ - "+third_party/sqlite/preprocessed", + "+third_party/sqlite", ] diff --git a/app/sql/connection.cc b/app/sql/connection.cc index ba40a11..1e0aa2c 100644 --- a/app/sql/connection.cc +++ b/app/sql/connection.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,11 +11,43 @@ #include "base/logging.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +<<<<<<< HEAD #ifdef ANDROID #include "sqlite3.h" #else #include "third_party/sqlite/preprocessed/sqlite3.h" #endif +======= +#include "third_party/sqlite/sqlite3.h" + +namespace { + +// Spin for up to a second waiting for the lock to clear when setting +// up the database. +// TODO(shess): Better story on this. http://crbug.com/56559 +const base::TimeDelta kBusyTimeout = base::TimeDelta::FromSeconds(1); + +class ScopedBusyTimeout { + public: + explicit ScopedBusyTimeout(sqlite3* db) + : db_(db) { + } + ~ScopedBusyTimeout() { + sqlite3_busy_timeout(db_, 0); + } + + int SetTimeout(base::TimeDelta timeout) { + DCHECK_LT(timeout.InMilliseconds(), INT_MAX); + return sqlite3_busy_timeout(db_, + static_cast<int>(timeout.InMilliseconds())); + } + + private: + sqlite3* db_; +}; + +} // namespace +>>>>>>> Chromium at release 7.0.540.0 namespace sql { @@ -25,6 +57,12 @@ bool StatementID::operator<(const StatementID& other) const { return strcmp(str_, other.str_) < 0; } +ErrorDelegate::ErrorDelegate() { +} + +ErrorDelegate::~ErrorDelegate() { +} + Connection::StatementRef::StatementRef() : connection_(NULL), stmt_(NULL) { @@ -135,7 +173,7 @@ bool Connection::BeginTransaction() { void Connection::RollbackTransaction() { if (!transaction_nesting_) { - NOTREACHED() << "Rolling back a nonexistant transaction"; + NOTREACHED() << "Rolling back a nonexistent transaction"; return; } @@ -152,7 +190,7 @@ void Connection::RollbackTransaction() { bool Connection::CommitTransaction() { if (!transaction_nesting_) { - NOTREACHED() << "Rolling back a nonexistant transaction"; + NOTREACHED() << "Rolling back a nonexistent transaction"; return false; } transaction_nesting_--; @@ -179,6 +217,15 @@ bool Connection::Execute(const char* sql) { return sqlite3_exec(db_, sql, NULL, NULL, NULL) == SQLITE_OK; } +bool Connection::ExecuteWithTimeout(const char* sql, base::TimeDelta timeout) { + if (!db_) + return false; + + ScopedBusyTimeout busy_timeout(db_); + busy_timeout.SetTimeout(timeout); + return sqlite3_exec(db_, sql, NULL, NULL, NULL) == SQLITE_OK; +} + bool Connection::HasCachedStatement(const StatementID& id) const { return statement_cache_.find(id) != statement_cache_.end(); } @@ -271,6 +318,17 @@ int Connection::GetErrorCode() const { return sqlite3_errcode(db_); } +int Connection::GetLastErrno() const { + if (!db_) + return -1; + + int err = 0; + if (SQLITE_OK != sqlite3_file_control(db_, NULL, SQLITE_LAST_ERRNO, &err)) + return -2; + + return err; +} + const char* Connection::GetErrorMessage() const { if (!db_) return "sql::Connection has no connection."; @@ -290,19 +348,44 @@ bool Connection::OpenInternal(const std::string& file_name) { return false; } - if (page_size_ != 0) { - if (!Execute(StringPrintf("PRAGMA page_size=%d", page_size_).c_str())) - NOTREACHED() << "Could not set page size"; + // Enable extended result codes to provide more color on I/O errors. + // Not having extended result codes is not a fatal problem, as + // Chromium code does not attempt to handle I/O errors anyhow. The + // current implementation always returns SQLITE_OK, the DCHECK is to + // quickly notify someone if SQLite changes. + err = sqlite3_extended_result_codes(db_, 1); + DCHECK_EQ(err, SQLITE_OK) << "Could not enable extended result codes"; + + // If indicated, lock up the database before doing anything else, so + // that the following code doesn't have to deal with locking. + // TODO(shess): This code is brittle. Find the cases where code + // doesn't request |exclusive_locking_| and audit that it does the + // right thing with SQLITE_BUSY, and that it doesn't make + // assumptions about who might change things in the database. + // http://crbug.com/56559 + if (exclusive_locking_) { + // TODO(shess): This should probably be a full CHECK(). Code + // which requests exclusive locking but doesn't get it is almost + // certain to be ill-tested. + if (!Execute("PRAGMA locking_mode=EXCLUSIVE")) + NOTREACHED() << "Could not set locking mode: " << GetErrorMessage(); } - if (cache_size_ != 0) { - if (!Execute(StringPrintf("PRAGMA cache_size=%d", cache_size_).c_str())) - NOTREACHED() << "Could not set page size"; + if (page_size_ != 0) { + // Enforce SQLite restrictions on |page_size_|. + DCHECK(!(page_size_ & (page_size_ - 1))) + << " page_size_ " << page_size_ << " is not a power of two."; + static const int kSqliteMaxPageSize = 32768; // from sqliteLimit.h + DCHECK_LE(page_size_, kSqliteMaxPageSize); + const std::string sql = StringPrintf("PRAGMA page_size=%d", page_size_); + if (!ExecuteWithTimeout(sql.c_str(), kBusyTimeout)) + NOTREACHED() << "Could not set page size: " << GetErrorMessage(); } - if (exclusive_locking_) { - if (!Execute("PRAGMA locking_mode=EXCLUSIVE")) - NOTREACHED() << "Could not set locking mode."; + if (cache_size_ != 0) { + const std::string sql = StringPrintf("PRAGMA cache_size=%d", cache_size_); + if (!ExecuteWithTimeout(sql.c_str(), kBusyTimeout)) + NOTREACHED() << "Could not set cache size: " << GetErrorMessage(); } return true; diff --git a/app/sql/connection.h b/app/sql/connection.h index 6927c89..0b685cc 100644 --- a/app/sql/connection.h +++ b/app/sql/connection.h @@ -4,6 +4,7 @@ #ifndef APP_SQL_CONNECTION_H_ #define APP_SQL_CONNECTION_H_ +#pragma once #include <map> #include <set> @@ -11,6 +12,7 @@ #include "base/basictypes.h" #include "base/ref_counted.h" +#include "base/time.h" class FilePath; struct sqlite3; @@ -76,6 +78,8 @@ class Connection; // corruption, low-level IO errors or locking violations. class ErrorDelegate : public base::RefCounted<ErrorDelegate> { public: + ErrorDelegate(); + // |error| is an sqlite result code as seen in sqlite\preprocessed\sqlite3.h // |connection| is db connection where the error happened and |stmt| is // our best guess at the statement that triggered the error. Do not store @@ -92,7 +96,7 @@ class ErrorDelegate : public base::RefCounted<ErrorDelegate> { protected: friend class base::RefCounted<ErrorDelegate>; - virtual ~ErrorDelegate() {} + virtual ~ErrorDelegate(); }; class Connection { @@ -260,6 +264,10 @@ class Connection { // Returns the error code associated with the last sqlite operation. int GetErrorCode() const; + // Returns the errno associated with GetErrorCode(). See + // SQLITE_LAST_ERRNO in SQLite documentation. + int GetLastErrno() const; + // Returns a pointer to a statically allocated string associated with the // last sqlite operation. const char* GetErrorMessage() const; @@ -334,6 +342,9 @@ class Connection { // The return value is the error code reflected back to client code. int OnSqliteError(int err, Statement* stmt); + // Like |Execute()|, but retries if the database is locked. + bool ExecuteWithTimeout(const char* sql, base::TimeDelta ms_timeout); + // The actual sqlite database. Will be NULL before Init has been called or if // Init resulted in an error. sqlite3* db_; diff --git a/app/sql/connection_unittest.cc b/app/sql/connection_unittest.cc index a36fca7..0a14a9a 100644 --- a/app/sql/connection_unittest.cc +++ b/app/sql/connection_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/sqlite/preprocessed/sqlite3.h" +#include "third_party/sqlite/sqlite3.h" class SQLConnectionTest : public testing::Test { public: @@ -91,7 +91,7 @@ TEST_F(SQLConnectionTest, DoesStuffExist) { EXPECT_FALSE(db().DoesColumnExist("foo", "bar")); EXPECT_TRUE(db().DoesColumnExist("foo", "a")); - // Testing for a column on a nonexistant table. + // Testing for a column on a nonexistent table. EXPECT_FALSE(db().DoesColumnExist("bar", "b")); } diff --git a/app/sql/diagnostic_error_delegate.h b/app/sql/diagnostic_error_delegate.h index 0b0cc65..1c2d6e9 100644 --- a/app/sql/diagnostic_error_delegate.h +++ b/app/sql/diagnostic_error_delegate.h @@ -4,6 +4,7 @@ #ifndef APP_SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ #define APP_SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ +#pragma once #include "app/sql/connection.h" #include "base/histogram.h" @@ -26,14 +27,18 @@ class DiagnosticErrorDelegate : public ErrorDelegate { virtual int OnError(int error, Connection* connection, Statement* stmt) { - NOTREACHED() << "sqlite error " << error << ": " << - connection->GetErrorMessage(); + NOTREACHED() << "sqlite error " << error + << ", errno " << connection->GetLastErrno() + << ": " << connection->GetErrorMessage(); RecordErrorInHistogram(error); return error; } private: static void RecordErrorInHistogram(int error) { + // Trim off the extended error codes. + error &= 0xff; + // The histogram values from sqlite result codes go currently from 1 to // 26 currently but 50 gives them room to grow. UMA_HISTOGRAM_ENUMERATION(UniqueT::name(), error, 50); diff --git a/app/sql/init_status.h b/app/sql/init_status.h index ac70c7b..048c5e8 100644 --- a/app/sql/init_status.h +++ b/app/sql/init_status.h @@ -4,6 +4,7 @@ #ifndef APP_SQL_INIT_STATUS_H_ #define APP_SQL_INIT_STATUS_H_ +#pragma once namespace sql { diff --git a/app/sql/meta_table.h b/app/sql/meta_table.h index 26ad079..4b06337 100644 --- a/app/sql/meta_table.h +++ b/app/sql/meta_table.h @@ -4,6 +4,7 @@ #ifndef APP_SQL_META_TABLE_H_ #define APP_SQL_META_TABLE_H_ +#pragma once #include <string> diff --git a/app/sql/statement.cc b/app/sql/statement.cc index 4ac9c2e..3cff490 100644 --- a/app/sql/statement.cc +++ b/app/sql/statement.cc @@ -6,11 +6,15 @@ #include "base/logging.h" #include "base/utf_string_conversions.h" +<<<<<<< HEAD #ifdef ANDROID #include "sqlite3.h" #else #include "third_party/sqlite/preprocessed/sqlite3.h" #endif +======= +#include "third_party/sqlite/sqlite3.h" +>>>>>>> Chromium at release 7.0.540.0 namespace sql { diff --git a/app/sql/statement.h b/app/sql/statement.h index 0fbbfba..eaaac41 100644 --- a/app/sql/statement.h +++ b/app/sql/statement.h @@ -4,6 +4,7 @@ #ifndef APP_SQL_STATEMENT_H_ #define APP_SQL_STATEMENT_H_ +#pragma once #include <string> #include <vector> diff --git a/app/sql/statement_unittest.cc b/app/sql/statement_unittest.cc index 90f421c..f9271a7 100644 --- a/app/sql/statement_unittest.cc +++ b/app/sql/statement_unittest.cc @@ -10,7 +10,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/sqlite/preprocessed/sqlite3.h" +#include "third_party/sqlite/sqlite3.h" class StatementErrorHandler : public sql::ErrorDelegate { public: diff --git a/app/sql/transaction.cc b/app/sql/transaction.cc index 79a198b..10bcfb0 100644 --- a/app/sql/transaction.cc +++ b/app/sql/transaction.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -30,7 +30,7 @@ bool Transaction::Begin() { void Transaction::Rollback() { if (!is_open_) { - NOTREACHED() << "Attempting to roll back a nonexistant transaction. " + NOTREACHED() << "Attempting to roll back a nonexistent transaction. " << "Did you remember to call Begin() and check its return?"; return; } @@ -40,7 +40,7 @@ void Transaction::Rollback() { bool Transaction::Commit() { if (!is_open_) { - NOTREACHED() << "Attempting to commit a nonexistant transaction. " + NOTREACHED() << "Attempting to commit a nonexistent transaction. " << "Did you remember to call Begin() and check its return?"; return false; } diff --git a/app/sql/transaction.h b/app/sql/transaction.h index 70741d1..c65ca8d 100644 --- a/app/sql/transaction.h +++ b/app/sql/transaction.h @@ -4,6 +4,7 @@ #ifndef APP_SQL_TRANSACTION_H_ #define APP_SQL_TRANSACTION_H_ +#pragma once #include "base/basictypes.h" diff --git a/app/sql/transaction_unittest.cc b/app/sql/transaction_unittest.cc index 55b77b9..9ca6bbd 100644 --- a/app/sql/transaction_unittest.cc +++ b/app/sql/transaction_unittest.cc @@ -9,7 +9,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/sqlite/preprocessed/sqlite3.h" +#include "third_party/sqlite/sqlite3.h" class SQLTransactionTest : public testing::Test { public: |