Commit c7e7f2e1 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

sql: Replace typedef with using.

Change-Id: Ia275f1610f1e654937fec6eb2dca93928e203107
Reviewed-on: https://chromium-review.googlesource.com/1137847Reviewed-by: default avatarChris Mumford <cmumford@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576179}
parent 46e3139c
......@@ -378,9 +378,8 @@ void Connection::CloseInternal(bool forced) {
DCHECK(forced || open_statements_.empty());
// Deactivate any outstanding statements so sqlite3_close() works.
for (StatementRefSet::iterator i = open_statements_.begin();
i != open_statements_.end(); ++i)
(*i)->Close(forced);
for (StatementRef* statement_ref : open_statements_)
statement_ref->Close(forced);
open_statements_.clear();
if (db_) {
......@@ -1404,15 +1403,15 @@ bool Connection::HasCachedStatement(const StatementID& id) const {
scoped_refptr<Connection::StatementRef> Connection::GetCachedStatement(
const StatementID& id,
const char* sql) {
CachedStatementMap::iterator i = statement_cache_.find(id);
if (i != statement_cache_.end()) {
auto it = statement_cache_.find(id);
if (it != statement_cache_.end()) {
// Statement is in the cache. It should still be active (we're the only
// one invalidating cached statements, and we'll remove it from the cache
// if we do that. Make sure we reset it before giving out the cached one in
// case it still has some stuff bound.
DCHECK(i->second->is_valid());
sqlite3_reset(i->second->stmt());
return i->second;
DCHECK(it->second->is_valid());
sqlite3_reset(it->second->stmt());
return it->second;
}
scoped_refptr<StatementRef> statement = GetUniqueStatement(sql);
......@@ -1837,16 +1836,15 @@ void Connection::DoRollback() {
}
void Connection::StatementRefCreated(StatementRef* ref) {
DCHECK(open_statements_.find(ref) == open_statements_.end());
DCHECK(!open_statements_.count(ref))
<< __func__ << " already called with this statement";
open_statements_.insert(ref);
}
void Connection::StatementRefDeleted(StatementRef* ref) {
StatementRefSet::iterator i = open_statements_.find(ref);
if (i == open_statements_.end())
DLOG(DCHECK) << "Could not find statement";
else
open_statements_.erase(i);
DCHECK(open_statements_.count(ref))
<< __func__ << " called with non-existing statement";
open_statements_.erase(ref);
}
void Connection::set_histogram_tag(const std::string& tag) {
......
......@@ -166,7 +166,7 @@ class SQL_EXPORT Connection {
//
// If no callback is set, the default action is to crash in debug
// mode or return failure in release mode.
typedef base::RepeatingCallback<void(int, Statement*)> ErrorCallback;
using ErrorCallback = base::RepeatingCallback<void(int, Statement*)>;
void set_error_callback(const ErrorCallback& callback) {
error_callback_ = callback;
}
......@@ -563,7 +563,7 @@ class SQL_EXPORT Connection {
// Accessors for global error-expecter, for injecting behavior during tests.
// See test/scoped_error_expecter.h.
typedef base::RepeatingCallback<bool(int)> ErrorExpecterCallback;
using ErrorExpecterCallback = base::RepeatingCallback<bool(int)>;
static ErrorExpecterCallback* current_expecter_cb_;
static void SetErrorExpecter(ErrorExpecterCallback* expecter);
static void ResetErrorExpecter();
......@@ -619,7 +619,10 @@ class SQL_EXPORT Connection {
// Check whether the current thread is allowed to make IO calls, but only
// if database wasn't open in memory.
void AssertIOAllowed() { if (connection_) connection_->AssertIOAllowed(); }
void AssertIOAllowed() const {
if (connection_)
connection_->AssertIOAllowed();
}
private:
friend class base::RefCounted<StatementRef>;
......@@ -764,18 +767,17 @@ class SQL_EXPORT Connection {
bool exclusive_locking_;
bool restrict_to_user_;
// All cached statements. Keeping a reference to these statements means that
// they'll remain active. Using flat_map here because number of cached
// statements is expected to be small, see //base/containers/README.md.
typedef base::flat_map<StatementID, scoped_refptr<StatementRef>>
CachedStatementMap;
CachedStatementMap statement_cache_;
// Holds references to all cached statements so they remain active.
//
// flat_map is appropriate here because the codebase has ~400 cached
// statements, and each statement is at most one insertion in the map
// throughout a process' lifetime.
base::flat_map<StatementID, scoped_refptr<StatementRef>> statement_cache_;
// A list of all StatementRefs we've given out. Each ref must register with
// us when it's created or destroyed. This allows us to potentially close
// any open statements when we encounter an error.
typedef std::set<StatementRef*> StatementRefSet;
StatementRefSet open_statements_;
std::set<StatementRef*> open_statements_;
// Number of currently-nested transactions.
int transaction_nesting_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment