Migrate //sql from base::Callback to base::RepeatingCallback
This updates //sql to use base::RepeatingCallback instead of legacy
base::Callback. No intended functional change is included.
This reduces the number of 'base::Bind' in //sql from 19 to 1
as tracked at http://goo.gl/LUVhDj
Bug: 714018
Change-Id: I4b6b321e25f2b3db7ab7ac3e09d9ee74761db230
Reviewed-on: https://chromium-review.googlesource.com/952116
Commit-Queue: Victor Costan <[email protected]>
Reviewed-by: Victor Costan <[email protected]>
Cr-Commit-Position: refs/heads/master@{#541388}
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc
index c09106f..3042fd7 100644
--- a/sql/connection_unittest.cc
+++ b/sql/connection_unittest.cc
@@ -90,8 +90,8 @@
sql::Connection& db,
const char* function_name,
int args,
- base::Callback<void(sqlite3_context*,int,sqlite3_value**)> cb)
- : db_(db.db_), function_name_(function_name), cb_(cb) {
+ base::RepeatingCallback<void(sqlite3_context*, int, sqlite3_value**)> cb)
+ : db_(db.db_), function_name_(function_name), cb_(std::move(cb)) {
sqlite3_create_function_v2(db_, function_name, args, SQLITE_UTF8,
this, &Run, NULL, NULL, NULL);
}
@@ -109,7 +109,7 @@
sqlite3* db_;
const char* function_name_;
- base::Callback<void(sqlite3_context*,int,sqlite3_value**)> cb_;
+ base::RepeatingCallback<void(sqlite3_context*, int, sqlite3_value**)> cb_;
DISALLOW_COPY_AND_ASSIGN(ScopedScalarFunction);
};
@@ -117,10 +117,8 @@
// Allow a test to add a SQLite commit hook in a scoped context.
class ScopedCommitHook {
public:
- ScopedCommitHook(sql::Connection& db,
- base::Callback<int(void)> cb)
- : db_(db.db_),
- cb_(cb) {
+ ScopedCommitHook(sql::Connection& db, base::RepeatingCallback<int()> cb)
+ : db_(db.db_), cb_(std::move(cb)) {
sqlite3_commit_hook(db_, &Run, this);
}
~ScopedCommitHook() {
@@ -134,7 +132,7 @@
}
sqlite3* db_;
- base::Callback<int(void)> cb_;
+ base::RepeatingCallback<int(void)> cb_;
DISALLOW_COPY_AND_ASSIGN(ScopedCommitHook);
};
@@ -187,7 +185,7 @@
int error, sql::Statement* stmt) {
// The ref count should not go to zero when changing the callback.
EXPECT_GT(*counter, 0u);
- db->set_error_callback(base::Bind(&IgnoreErrorCallback));
+ db->set_error_callback(base::BindRepeating(&IgnoreErrorCallback));
EXPECT_GT(*counter, 0u);
}
@@ -414,7 +412,7 @@
int error = SQLITE_OK;
{
sql::ScopedErrorCallback sec(
- &db(), base::Bind(&sql::CaptureErrorCallback, &error));
+ &db(), base::BindRepeating(&sql::CaptureErrorCallback, &error));
EXPECT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
// Later versions of SQLite throw SQLITE_CONSTRAINT_UNIQUE. The specific
@@ -432,7 +430,7 @@
EXPECT_EQ(SQLITE_OK, error);
}
- // base::Bind() can curry arguments to be passed by const reference
+ // base::BindRepeating() can curry arguments to be passed by const reference
// to the callback function. If the callback function calls
// re/set_error_callback(), the storage for those arguments can be
// deleted while the callback function is still executing.
@@ -444,8 +442,8 @@
{
size_t count = 0;
sql::ScopedErrorCallback sec(
- &db(), base::Bind(&ErrorCallbackSetHelper,
- &db(), &count, RefCounter(&count)));
+ &db(), base::BindRepeating(&ErrorCallbackSetHelper, &db(), &count,
+ RefCounter(&count)));
EXPECT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
}
@@ -454,8 +452,8 @@
{
size_t count = 0;
sql::ScopedErrorCallback sec(
- &db(), base::Bind(&ErrorCallbackResetHelper,
- &db(), &count, RefCounter(&count)));
+ &db(), base::BindRepeating(&ErrorCallbackResetHelper, &db(), &count,
+ RefCounter(&count)));
EXPECT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
}
@@ -733,9 +731,8 @@
ASSERT_TRUE(expecter.SawExpectedErrors());
}
- db().set_error_callback(base::Bind(&RazeErrorCallback,
- &db(),
- SQLITE_CORRUPT));
+ db().set_error_callback(
+ base::BindRepeating(&RazeErrorCallback, &db(), SQLITE_CORRUPT));
// When the PRAGMA calls in Open() raise SQLITE_CORRUPT, the error
// callback will call RazeAndClose(). Open() will then fail and be
@@ -1014,9 +1011,8 @@
// Test that poisoning the database during a transaction works (with errors).
// RazeErrorCallback() poisons the database, the extra COMMIT causes
// CommitTransaction() to throw an error while commiting.
- db().set_error_callback(base::Bind(&RazeErrorCallback,
- &db(),
- SQLITE_ERROR));
+ db().set_error_callback(
+ base::BindRepeating(&RazeErrorCallback, &db(), SQLITE_ERROR));
db().Close();
ASSERT_TRUE(db().Open(db_path()));
EXPECT_TRUE(db().BeginTransaction());
@@ -1302,7 +1298,8 @@
// Function to inject pauses into statements.
sql::test::ScopedScalarFunction scoper(
- db(), "milliadjust", 1, base::Bind(&sqlite_adjust_millis, &time_mock));
+ db(), "milliadjust", 1,
+ base::BindRepeating(&sqlite_adjust_millis, &time_mock));
base::HistogramTester tester;
@@ -1340,7 +1337,8 @@
// Function to inject pauses into statements.
sql::test::ScopedScalarFunction scoper(
- db(), "milliadjust", 1, base::Bind(&sqlite_adjust_millis, &time_mock));
+ db(), "milliadjust", 1,
+ base::BindRepeating(&sqlite_adjust_millis, &time_mock));
base::HistogramTester tester;
@@ -1382,14 +1380,15 @@
// Function to inject pauses into statements.
sql::test::ScopedScalarFunction scoper(
- db(), "milliadjust", 1, base::Bind(&sqlite_adjust_millis, &time_mock));
+ db(), "milliadjust", 1,
+ base::BindRepeating(&sqlite_adjust_millis, &time_mock));
base::HistogramTester tester;
{
// Make the commit slow.
sql::test::ScopedCommitHook scoped_hook(
- db(), base::Bind(adjust_commit_hook, &time_mock, 100));
+ db(), base::BindRepeating(adjust_commit_hook, &time_mock, 100));
ASSERT_TRUE(db().BeginTransaction());
EXPECT_TRUE(db().Execute(
"INSERT INTO foo VALUES (11, milliadjust(10))"));
@@ -1643,7 +1642,7 @@
// DEATH tests not supported on Android, iOS, or Fuchsia.
#if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_FUCHSIA)
if (DLOG_IS_ON(FATAL)) {
- db().set_error_callback(base::Bind(&IgnoreErrorCallback));
+ db().set_error_callback(base::BindRepeating(&IgnoreErrorCallback));
ASSERT_DEATH({
db().GetUniqueStatement("SELECT x");
}, "SQL compile error no such column: x");