summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsbell <jsbell@chromium.org>2014-10-03 10:34:38 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-03 17:34:54 +0000
commit1869ef4461ac76041a5bc269bb13c0adc22ec3cf (patch)
tree31fe5c3dc17a7fd5209adb993a7a6c4deec09229
parent1784cc3cd030e41f35e74a6268bcbf8fd50aa4fe (diff)
downloadchromium_src-1869ef4461ac76041a5bc269bb13c0adc22ec3cf.zip
chromium_src-1869ef4461ac76041a5bc269bb13c0adc22ec3cf.tar.gz
chromium_src-1869ef4461ac76041a5bc269bb13c0adc22ec3cf.tar.bz2
IndexedDB back-end: Use C++11 range-based-for and auto for iteration
No functional changes, just making the code more readable. R=cmumford@chromium.org Review URL: https://codereview.chromium.org/624653002 Cr-Commit-Position: refs/heads/master@{#298055}
-rw-r--r--content/browser/indexed_db/indexed_db_backing_store.cc185
-rw-r--r--content/browser/indexed_db/indexed_db_callbacks.cc36
-rw-r--r--content/browser/indexed_db/indexed_db_connection.h4
-rw-r--r--content/browser/indexed_db/indexed_db_context_impl.cc40
-rw-r--r--content/browser/indexed_db/indexed_db_database.cc32
-rw-r--r--content/browser/indexed_db/indexed_db_dispatcher_host.cc27
-rw-r--r--content/browser/indexed_db/indexed_db_factory_impl.cc6
-rw-r--r--content/browser/indexed_db/indexed_db_index_writer.cc9
-rw-r--r--content/browser/indexed_db/indexed_db_leveldb_coding.cc7
-rw-r--r--content/browser/indexed_db/indexed_db_leveldb_coding_unittest.cc13
-rw-r--r--content/browser/indexed_db/indexed_db_quota_client.cc8
-rw-r--r--content/browser/indexed_db/indexed_db_transaction.cc6
-rw-r--r--content/browser/indexed_db/indexed_db_transaction_coordinator.cc19
-rw-r--r--content/browser/indexed_db/leveldb/leveldb_transaction.cc20
14 files changed, 151 insertions, 261 deletions
diff --git a/content/browser/indexed_db/indexed_db_backing_store.cc b/content/browser/indexed_db/indexed_db_backing_store.cc
index 00c3bb5..6c7ac84 100644
--- a/content/browser/indexed_db/indexed_db_backing_store.cc
+++ b/content/browser/indexed_db/indexed_db_backing_store.cc
@@ -653,16 +653,14 @@ static leveldb::Status MergeDatabaseIntoLiveBlobJournal(
static std::string EncodeBlobData(
const std::vector<IndexedDBBlobInfo*>& blob_info) {
std::string ret;
- std::vector<IndexedDBBlobInfo*>::const_iterator iter;
- for (iter = blob_info.begin(); iter != blob_info.end(); ++iter) {
- const IndexedDBBlobInfo& info = **iter;
- EncodeBool(info.is_file(), &ret);
- EncodeVarInt(info.key(), &ret);
- EncodeStringWithLength(info.type(), &ret);
- if (info.is_file())
- EncodeStringWithLength(info.file_name(), &ret);
+ for (const auto* info : blob_info) {
+ EncodeBool(info->is_file(), &ret);
+ EncodeVarInt(info->key(), &ret);
+ EncodeStringWithLength(info->type(), &ret);
+ if (info->is_file())
+ EncodeStringWithLength(info->file_name(), &ret);
else
- EncodeVarInt(info.size(), &ret);
+ EncodeVarInt(info->size(), &ret);
}
return ret;
}
@@ -724,12 +722,8 @@ IndexedDBBackingStore::~IndexedDBBackingStore() {
if (!blob_path_.empty() && !child_process_ids_granted_.empty()) {
ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
- std::set<int>::const_iterator iter;
- for (iter = child_process_ids_granted_.begin();
- iter != child_process_ids_granted_.end();
- ++iter) {
- policy->RevokeAllPermissionsForFile(*iter, blob_path_);
- }
+ for (const auto& pid : child_process_ids_granted_)
+ policy->RevokeAllPermissionsForFile(pid, blob_path_);
}
STLDeleteContainerPairSecondPointers(incognito_blob_map_.begin(),
incognito_blob_map_.end());
@@ -2630,11 +2624,9 @@ leveldb::Status IndexedDBBackingStore::CleanUpBlobJournal(
return s;
if (!journal.size())
return leveldb::Status::OK();
- BlobJournalType::iterator journal_iter;
- for (journal_iter = journal.begin(); journal_iter != journal.end();
- ++journal_iter) {
- int64 database_id = journal_iter->first;
- int64 blob_key = journal_iter->second;
+ for (const auto& entry : journal) {
+ int64 database_id = entry.first;
+ int64 blob_key = entry.second;
DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
if (blob_key == DatabaseMetaDataKey::kAllBlobsKey) {
if (!RemoveBlobDirectory(database_id))
@@ -2689,24 +2681,22 @@ leveldb::Status IndexedDBBackingStore::Transaction::GetBlobInfoForRecord(
INTERNAL_READ_ERROR(GET_BLOB_INFO_FOR_RECORD);
return InternalInconsistencyStatus();
}
- std::vector<IndexedDBBlobInfo>::iterator iter;
- for (iter = value->blob_info.begin(); iter != value->blob_info.end();
- ++iter) {
- iter->set_file_path(
- backing_store_->GetBlobFileName(database_id, iter->key()));
- iter->set_mark_used_callback(
+ for (auto& entry : value->blob_info) {
+ entry.set_file_path(
+ backing_store_->GetBlobFileName(database_id, entry.key()));
+ entry.set_mark_used_callback(
backing_store_->active_blob_registry()->GetAddBlobRefCallback(
- database_id, iter->key()));
- iter->set_release_callback(
+ database_id, entry.key()));
+ entry.set_release_callback(
backing_store_->active_blob_registry()->GetFinalReleaseCallback(
- database_id, iter->key()));
- if (iter->is_file()) {
+ database_id, entry.key()));
+ if (entry.is_file()) {
base::File::Info info;
- if (base::GetFileInfo(iter->file_path(), &info)) {
+ if (base::GetFileInfo(entry.file_path(), &info)) {
// This should always work, but it isn't fatal if it doesn't; it just
// means a potential slow synchronous call from the renderer later.
- iter->set_last_modified(info.last_modified);
- iter->set_size(info.size);
+ entry.set_last_modified(info.last_modified);
+ entry.set_size(info.size);
}
}
}
@@ -3898,11 +3888,8 @@ void IndexedDBBackingStore::Transaction::Begin() {
// If incognito, this snapshots blobs just as the above transaction_
// constructor snapshots the leveldb.
- BlobChangeMap::const_iterator iter;
- for (iter = backing_store_->incognito_blob_map_.begin();
- iter != backing_store_->incognito_blob_map_.end();
- ++iter)
- incognito_blob_map_[iter->first] = iter->second->Clone().release();
+ for (const auto& iter : backing_store_->incognito_blob_map_)
+ incognito_blob_map_[iter.first] = iter.second->Clone().release();
}
static GURL getURLFromUUID(const string& uuid) {
@@ -3915,21 +3902,17 @@ leveldb::Status IndexedDBBackingStore::Transaction::HandleBlobPreTransaction(
if (backing_store_->is_incognito())
return leveldb::Status::OK();
- BlobChangeMap::iterator iter = blob_change_map_.begin();
new_blob_entries->clear();
new_files_to_write->clear();
- if (iter != blob_change_map_.end()) {
+ if (!blob_change_map_.empty()) {
// Create LevelDBTransaction for the name generator seed and add-journal.
scoped_refptr<LevelDBTransaction> pre_transaction =
IndexedDBClassFactory::Get()->CreateLevelDBTransaction(
backing_store_->db_.get());
BlobJournalType journal;
- for (; iter != blob_change_map_.end(); ++iter) {
- std::vector<IndexedDBBlobInfo>::iterator info_iter;
+ for (auto& iter : blob_change_map_) {
std::vector<IndexedDBBlobInfo*> new_blob_keys;
- for (info_iter = iter->second->mutable_blob_info().begin();
- info_iter != iter->second->mutable_blob_info().end();
- ++info_iter) {
+ for (auto& entry : iter.second->mutable_blob_info()) {
int64 next_blob_key = -1;
bool result = GetBlobKeyGeneratorCurrentNumber(
pre_transaction.get(), database_id_, &next_blob_key);
@@ -3938,27 +3921,27 @@ leveldb::Status IndexedDBBackingStore::Transaction::HandleBlobPreTransaction(
BlobJournalEntryType journal_entry =
std::make_pair(database_id_, next_blob_key);
journal.push_back(journal_entry);
- if (info_iter->is_file()) {
+ if (entry.is_file()) {
new_files_to_write->push_back(
- WriteDescriptor(info_iter->file_path(),
+ WriteDescriptor(entry.file_path(),
next_blob_key,
- info_iter->size(),
- info_iter->last_modified()));
+ entry.size(),
+ entry.last_modified()));
} else {
new_files_to_write->push_back(
- WriteDescriptor(getURLFromUUID(info_iter->uuid()),
+ WriteDescriptor(getURLFromUUID(entry.uuid()),
next_blob_key,
- info_iter->size()));
+ entry.size()));
}
- info_iter->set_key(next_blob_key);
- new_blob_keys.push_back(&*info_iter);
+ entry.set_key(next_blob_key);
+ new_blob_keys.push_back(&entry);
result = UpdateBlobKeyGeneratorCurrentNumber(
pre_transaction.get(), database_id_, next_blob_key + 1);
if (!result)
return InternalInconsistencyStatus();
}
BlobEntryKey blob_entry_key;
- StringPiece key_piece(iter->second->key());
+ StringPiece key_piece(iter.second->key());
if (!BlobEntryKey::FromObjectStoreDataKey(&key_piece, &blob_entry_key)) {
NOTREACHED();
return InternalInconsistencyStatus();
@@ -3978,41 +3961,35 @@ bool IndexedDBBackingStore::Transaction::CollectBlobFilesToRemove() {
if (backing_store_->is_incognito())
return true;
- BlobChangeMap::const_iterator iter = blob_change_map_.begin();
// Look up all old files to remove as part of the transaction, store their
// names in blobs_to_remove_, and remove their old blob data entries.
- if (iter != blob_change_map_.end()) {
- for (; iter != blob_change_map_.end(); ++iter) {
- BlobEntryKey blob_entry_key;
- StringPiece key_piece(iter->second->key());
- if (!BlobEntryKey::FromObjectStoreDataKey(&key_piece, &blob_entry_key)) {
- NOTREACHED();
- INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD);
+ for (const auto& iter : blob_change_map_) {
+ BlobEntryKey blob_entry_key;
+ StringPiece key_piece(iter.second->key());
+ if (!BlobEntryKey::FromObjectStoreDataKey(&key_piece, &blob_entry_key)) {
+ NOTREACHED();
+ INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD);
+ transaction_ = NULL;
+ return false;
+ }
+ if (database_id_ < 0)
+ database_id_ = blob_entry_key.database_id();
+ else
+ DCHECK_EQ(database_id_, blob_entry_key.database_id());
+ std::string blob_entry_key_bytes = blob_entry_key.Encode();
+ bool found;
+ std::string blob_entry_value_bytes;
+ leveldb::Status s = transaction_->Get(
+ blob_entry_key_bytes, &blob_entry_value_bytes, &found);
+ if (s.ok() && found) {
+ std::vector<IndexedDBBlobInfo> blob_info;
+ if (!DecodeBlobData(blob_entry_value_bytes, &blob_info)) {
+ INTERNAL_READ_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD);
transaction_ = NULL;
return false;
}
- if (database_id_ < 0)
- database_id_ = blob_entry_key.database_id();
- else
- DCHECK_EQ(database_id_, blob_entry_key.database_id());
- std::string blob_entry_key_bytes = blob_entry_key.Encode();
- bool found;
- std::string blob_entry_value_bytes;
- leveldb::Status s = transaction_->Get(
- blob_entry_key_bytes, &blob_entry_value_bytes, &found);
- if (s.ok() && found) {
- std::vector<IndexedDBBlobInfo> blob_info;
- if (!DecodeBlobData(blob_entry_value_bytes, &blob_info)) {
- INTERNAL_READ_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD);
- transaction_ = NULL;
- return false;
- }
- std::vector<IndexedDBBlobInfo>::iterator blob_info_iter;
- for (blob_info_iter = blob_info.begin();
- blob_info_iter != blob_info.end();
- ++blob_info_iter)
- blobs_to_remove_.push_back(
- std::make_pair(database_id_, blob_info_iter->key()));
+ for (const auto& blob : blob_info) {
+ blobs_to_remove_.push_back(std::make_pair(database_id_, blob.key()));
transaction_->Remove(blob_entry_key_bytes);
}
}
@@ -4023,14 +4000,12 @@ bool IndexedDBBackingStore::Transaction::CollectBlobFilesToRemove() {
leveldb::Status IndexedDBBackingStore::Transaction::SortBlobsToRemove() {
IndexedDBActiveBlobRegistry* registry =
backing_store_->active_blob_registry();
- BlobJournalType::iterator iter;
BlobJournalType primary_journal, live_blob_journal;
- for (iter = blobs_to_remove_.begin(); iter != blobs_to_remove_.end();
- ++iter) {
- if (registry->MarkDeletedCheckIfUsed(iter->first, iter->second))
- live_blob_journal.push_back(*iter);
+ for (const auto& iter : blobs_to_remove_) {
+ if (registry->MarkDeletedCheckIfUsed(iter.first, iter.second))
+ live_blob_journal.push_back(iter);
else
- primary_journal.push_back(*iter);
+ primary_journal.push_back(iter);
}
UpdatePrimaryJournalWithBlobList(transaction_.get(), primary_journal);
leveldb::Status s =
@@ -4105,17 +4080,15 @@ leveldb::Status IndexedDBBackingStore::Transaction::CommitPhaseTwo() {
if (s.ok() && backing_store_->is_incognito() && !blob_change_map_.empty()) {
BlobChangeMap& target_map = backing_store_->incognito_blob_map_;
- BlobChangeMap::iterator iter;
- for (iter = blob_change_map_.begin(); iter != blob_change_map_.end();
- ++iter) {
- BlobChangeMap::iterator target_record = target_map.find(iter->first);
+ for (auto& iter : blob_change_map_) {
+ BlobChangeMap::iterator target_record = target_map.find(iter.first);
if (target_record != target_map.end()) {
delete target_record->second;
target_map.erase(target_record);
}
- if (iter->second) {
- target_map[iter->first] = iter->second;
- iter->second = NULL;
+ if (iter.second) {
+ target_map[iter.first] = iter.second;
+ iter.second = NULL;
}
}
}
@@ -4156,17 +4129,14 @@ void IndexedDBBackingStore::Transaction::WriteNewBlobs(
scoped_refptr<BlobWriteCallback> callback) {
DCHECK_GT(new_files_to_write->size(), 0UL);
DCHECK_GT(database_id_, 0);
- BlobEntryKeyValuePairVec::iterator blob_entry_iter;
- for (blob_entry_iter = new_blob_entries->begin();
- blob_entry_iter != new_blob_entries->end();
- ++blob_entry_iter) {
+ for (auto& blob_entry_iter : *new_blob_entries) {
// Add the new blob-table entry for each blob to the main transaction, or
// remove any entry that may exist if there's no new one.
- if (!blob_entry_iter->second.size())
- transaction_->Remove(blob_entry_iter->first.Encode());
+ if (!blob_entry_iter.second.size())
+ transaction_->Remove(blob_entry_iter.first.Encode());
else
- transaction_->Put(blob_entry_iter->first.Encode(),
- &blob_entry_iter->second);
+ transaction_->Put(blob_entry_iter.first.Encode(),
+ &blob_entry_iter.second);
}
// Creating the writer will start it going asynchronously.
chained_blob_writer_ =
@@ -4217,9 +4187,8 @@ IndexedDBBackingStore::BlobChangeRecord::Clone() const {
new BlobChangeRecord(key_, object_store_id_));
record->blob_info_ = blob_info_;
- ScopedVector<storage::BlobDataHandle>::const_iterator iter;
- for (iter = handles_.begin(); iter != handles_.end(); ++iter)
- record->handles_.push_back(new storage::BlobDataHandle(**iter));
+ for (const auto* handle : handles_)
+ record->handles_.push_back(new storage::BlobDataHandle(*handle));
return record.Pass();
}
diff --git a/content/browser/indexed_db/indexed_db_callbacks.cc b/content/browser/indexed_db/indexed_db_callbacks.cc
index 44b2a4e..a5aafdd 100644
--- a/content/browser/indexed_db/indexed_db_callbacks.cc
+++ b/content/browser/indexed_db/indexed_db_callbacks.cc
@@ -307,22 +307,20 @@ static void BlobLookupForCursorPrefetch(
static void FillInBlobData(
const std::vector<IndexedDBBlobInfo>& blob_info,
std::vector<IndexedDBMsg_BlobOrFileInfo>* blob_or_file_info) {
- for (std::vector<IndexedDBBlobInfo>::const_iterator iter = blob_info.begin();
- iter != blob_info.end();
- ++iter) {
- if (iter->is_file()) {
+ for (const auto& iter : blob_info) {
+ if (iter.is_file()) {
IndexedDBMsg_BlobOrFileInfo info;
info.is_file = true;
- info.mime_type = iter->type();
- info.file_name = iter->file_name();
- info.file_path = iter->file_path().AsUTF16Unsafe();
- info.size = iter->size();
- info.last_modified = iter->last_modified().ToDoubleT();
+ info.mime_type = iter.type();
+ info.file_name = iter.file_name();
+ info.file_path = iter.file_path().AsUTF16Unsafe();
+ info.size = iter.size();
+ info.last_modified = iter.last_modified().ToDoubleT();
blob_or_file_info->push_back(info);
} else {
IndexedDBMsg_BlobOrFileInfo info;
- info.mime_type = iter->type();
- info.size = iter->size();
+ info.mime_type = iter.type();
+ info.size = iter.size();
blob_or_file_info->push_back(info);
}
}
@@ -331,10 +329,9 @@ static void FillInBlobData(
void IndexedDBCallbacks::RegisterBlobsAndSend(
const std::vector<IndexedDBBlobInfo>& blob_info,
const base::Closure& callback) {
- std::vector<IndexedDBBlobInfo>::const_iterator iter;
- for (iter = blob_info.begin(); iter != blob_info.end(); ++iter) {
- if (!iter->mark_used_callback().is_null())
- iter->mark_used_callback().Run();
+ for (const auto& iter : blob_info) {
+ if (!iter.mark_used_callback().is_null())
+ iter.mark_used_callback().Run();
}
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback);
@@ -473,12 +470,9 @@ void IndexedDBCallbacks::OnSuccessWithPrefetch(
if (iter->blob_info.size()) {
found_blob_info = true;
FillInBlobData(iter->blob_info, &values_blob_infos[i]);
- std::vector<IndexedDBBlobInfo>::const_iterator blob_iter;
- for (blob_iter = iter->blob_info.begin();
- blob_iter != iter->blob_info.end();
- ++blob_iter) {
- if (!blob_iter->mark_used_callback().is_null())
- blob_iter->mark_used_callback().Run();
+ for (const auto& blob_iter : iter->blob_info) {
+ if (!blob_iter.mark_used_callback().is_null())
+ blob_iter.mark_used_callback().Run();
}
}
}
diff --git a/content/browser/indexed_db/indexed_db_connection.h b/content/browser/indexed_db/indexed_db_connection.h
index c983b65..096323d 100644
--- a/content/browser/indexed_db/indexed_db_connection.h
+++ b/content/browser/indexed_db/indexed_db_connection.h
@@ -26,8 +26,8 @@ class CONTENT_EXPORT IndexedDBConnection {
void VersionChangeIgnored();
- IndexedDBDatabase* database() { return database_.get(); }
- IndexedDBDatabaseCallbacks* callbacks() { return callbacks_.get(); }
+ IndexedDBDatabase* database() const { return database_.get(); }
+ IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); }
private:
// NULL in some unit tests, and after the connection is closed.
diff --git a/content/browser/indexed_db/indexed_db_context_impl.cc b/content/browser/indexed_db/indexed_db_context_impl.cc
index 3dd6b5a..b54d59a 100644
--- a/content/browser/indexed_db/indexed_db_context_impl.cc
+++ b/content/browser/indexed_db/indexed_db_context_impl.cc
@@ -130,25 +130,15 @@ IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() {
std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() {
DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
- std::vector<GURL> origins;
std::set<GURL>* origins_set = GetOriginSet();
- for (std::set<GURL>::const_iterator iter = origins_set->begin();
- iter != origins_set->end();
- ++iter) {
- origins.push_back(*iter);
- }
- return origins;
+ return std::vector<GURL>(origins_set->begin(), origins_set->end());
}
std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() {
DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
std::vector<GURL> origins = GetAllOrigins();
std::vector<IndexedDBInfo> result;
- for (std::vector<GURL>::const_iterator iter = origins.begin();
- iter != origins.end();
- ++iter) {
- const GURL& origin_url = *iter;
-
+ for (const auto& origin_url : origins) {
base::FilePath idb_directory = GetFilePath(origin_url);
size_t connection_count = GetConnectionCount(origin_url);
result.push_back(IndexedDBInfo(origin_url,
@@ -171,11 +161,7 @@ base::ListValue* IndexedDBContextImpl::GetAllOriginsDetails() {
std::sort(origins.begin(), origins.end(), HostNameComparator);
scoped_ptr<base::ListValue> list(new base::ListValue());
- for (std::vector<GURL>::const_iterator iter = origins.begin();
- iter != origins.end();
- ++iter) {
- const GURL& origin_url = *iter;
-
+ for (const auto& origin_url : origins) {
scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue());
info->SetString("url", origin_url.spec());
info->SetString("size", ui::FormatBytes(GetOriginDiskUsage(origin_url)));
@@ -214,11 +200,7 @@ base::ListValue* IndexedDBContextImpl::GetAllOriginsDetails() {
scoped_ptr<base::ListValue> transaction_list(new base::ListValue());
std::vector<const IndexedDBTransaction*> transactions =
db->transaction_coordinator().GetTransactions();
- for (std::vector<const IndexedDBTransaction*>::iterator trans_it =
- transactions.begin();
- trans_it != transactions.end();
- ++trans_it) {
- const IndexedDBTransaction* transaction = *trans_it;
+ for (const auto* transaction : transactions) {
scoped_ptr<base::DictionaryValue> transaction_info(
new base::DictionaryValue());
@@ -264,12 +246,9 @@ base::ListValue* IndexedDBContextImpl::GetAllOriginsDetails() {
"tasks_completed", transaction->diagnostics().tasks_completed);
scoped_ptr<base::ListValue> scope(new base::ListValue());
- for (std::set<int64>::const_iterator scope_it =
- transaction->scope().begin();
- scope_it != transaction->scope().end();
- ++scope_it) {
+ for (const auto& id : transaction->scope()) {
IndexedDBDatabaseMetadata::ObjectStoreMap::const_iterator it =
- db->metadata().object_stores.find(*scope_it);
+ db->metadata().object_stores.find(id);
if (it != db->metadata().object_stores.end())
scope->AppendString(it->second.name);
}
@@ -555,14 +534,9 @@ void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) {
std::set<GURL>* IndexedDBContextImpl::GetOriginSet() {
if (!origin_set_) {
- origin_set_.reset(new std::set<GURL>);
std::vector<GURL> origins;
GetAllOriginsAndPaths(data_path_, &origins, NULL);
- for (std::vector<GURL>::const_iterator iter = origins.begin();
- iter != origins.end();
- ++iter) {
- origin_set_->insert(*iter);
- }
+ origin_set_.reset(new std::set<GURL>(origins.begin(), origins.end()));
}
return origin_set_.get();
}
diff --git a/content/browser/indexed_db/indexed_db_database.cc b/content/browser/indexed_db/indexed_db_database.cc
index 3e6f2e5..905cf06 100644
--- a/content/browser/indexed_db/indexed_db_database.cc
+++ b/content/browser/indexed_db/indexed_db_database.cc
@@ -1592,12 +1592,10 @@ void IndexedDBDatabase::RunVersionChangeTransaction(
DCHECK_NE(blink::WebIDBDataLossTotal, callbacks->data_loss());
// Front end ensures the event is not fired at connections that have
// close_pending set.
- for (ConnectionSet::const_iterator it = connections_.begin();
- it != connections_.end();
- ++it) {
- if (*it != connection.get()) {
- (*it)->callbacks()->OnVersionChange(metadata_.int_version,
- requested_version);
+ for (const auto* iter : connections_) {
+ if (iter != connection.get()) {
+ iter->callbacks()->OnVersionChange(metadata_.int_version,
+ requested_version);
}
}
// OnBlocked will be fired at the request when one of the other
@@ -1637,12 +1635,10 @@ void IndexedDBDatabase::DeleteDatabase(
scoped_refptr<IndexedDBCallbacks> callbacks) {
if (IsDeleteDatabaseBlocked()) {
- for (ConnectionSet::const_iterator it = connections_.begin();
- it != connections_.end();
- ++it) {
+ for (const auto* connection : connections_) {
// Front end ensures the event is not fired at connections that have
// close_pending set.
- (*it)->callbacks()->OnVersionChange(
+ connection->callbacks()->OnVersionChange(
metadata_.int_version, IndexedDBDatabaseMetadata::NO_INT_VERSION);
}
// OnBlocked will be fired at the request when one of the other
@@ -1699,11 +1695,8 @@ void IndexedDBDatabase::VersionChangeIgnored() {
pending_run_version_change_transaction_call_->callbacks()->OnBlocked(
metadata_.int_version);
- for (PendingDeleteCallList::iterator it = pending_delete_calls_.begin();
- it != pending_delete_calls_.end();
- ++it) {
- (*it)->callbacks()->OnBlocked(metadata_.int_version);
- }
+ for (const auto& pending_delete_call : pending_delete_calls_)
+ pending_delete_call->callbacks()->OnBlocked(metadata_.int_version);
}
@@ -1719,12 +1712,9 @@ void IndexedDBDatabase::Close(IndexedDBConnection* connection, bool forced) {
// complete, but can occur on process termination or forced close.
{
TransactionMap transactions(transactions_);
- for (TransactionMap::const_iterator it = transactions.begin(),
- end = transactions.end();
- it != end;
- ++it) {
- if (it->second->connection() == connection->callbacks())
- it->second->Abort(
+ for (const auto& it : transactions) {
+ if (it.second->connection() == connection->callbacks())
+ it.second->Abort(
IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
"Connection is closing."));
}
diff --git a/content/browser/indexed_db/indexed_db_dispatcher_host.cc b/content/browser/indexed_db/indexed_db_dispatcher_host.cc
index e0d5729d..3584f03 100644
--- a/content/browser/indexed_db/indexed_db_dispatcher_host.cc
+++ b/content/browser/indexed_db/indexed_db_dispatcher_host.cc
@@ -240,12 +240,9 @@ IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) {
metadata.int_version = web_metadata.int_version;
metadata.max_object_store_id = web_metadata.max_object_store_id;
- for (content::IndexedDBDatabaseMetadata::ObjectStoreMap::const_iterator iter =
- web_metadata.object_stores.begin();
- iter != web_metadata.object_stores.end();
- ++iter) {
+ for (const auto& iter : web_metadata.object_stores) {
const content::IndexedDBObjectStoreMetadata& web_store_metadata =
- iter->second;
+ iter.second;
::IndexedDBObjectStoreMetadata idb_store_metadata;
idb_store_metadata.id = web_store_metadata.id;
idb_store_metadata.name = web_store_metadata.name;
@@ -253,12 +250,9 @@ IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) {
idb_store_metadata.autoIncrement = web_store_metadata.auto_increment;
idb_store_metadata.max_index_id = web_store_metadata.max_index_id;
- for (content::IndexedDBObjectStoreMetadata::IndexMap::const_iterator
- index_iter = web_store_metadata.indexes.begin();
- index_iter != web_store_metadata.indexes.end();
- ++index_iter) {
+ for (const auto& index_iter : web_store_metadata.indexes) {
const content::IndexedDBIndexMetadata& web_index_metadata =
- index_iter->second;
+ index_iter.second;
::IndexedDBIndexMetadata idb_index_metadata;
idb_index_metadata.id = web_index_metadata.id;
idb_index_metadata.name = web_index_metadata.name;
@@ -349,9 +343,8 @@ void IndexedDBDispatcherHost::OnPutHelper(
void IndexedDBDispatcherHost::OnAckReceivedBlobs(
const std::vector<std::string>& uuids) {
DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
- std::vector<std::string>::const_iterator iter;
- for (iter = uuids.begin(); iter != uuids.end(); ++iter)
- DropBlobDataHandle(*iter);
+ for (const auto& uuid : uuids)
+ DropBlobDataHandle(uuid);
}
void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id,
@@ -449,13 +442,11 @@ void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() {
}
DCHECK(transaction_database_map_.empty());
- for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin();
- iter != database_url_map_.end();
- iter++) {
- IndexedDBConnection* connection = map_.Lookup(iter->first);
+ for (const auto& iter : database_url_map_) {
+ IndexedDBConnection* connection = map_.Lookup(iter.first);
if (connection && connection->IsConnected()) {
connection->Close();
- parent_->Context()->ConnectionClosed(iter->second, connection);
+ parent_->Context()->ConnectionClosed(iter.second, connection);
}
}
}
diff --git a/content/browser/indexed_db/indexed_db_factory_impl.cc b/content/browser/indexed_db/indexed_db_factory_impl.cc
index bc3e6eb..9a62b78 100644
--- a/content/browser/indexed_db/indexed_db_factory_impl.cc
+++ b/content/browser/indexed_db/indexed_db_factory_impl.cc
@@ -143,10 +143,8 @@ void IndexedDBFactoryImpl::ContextDestroyed() {
// context (which nominally owns this factory) is destroyed during thread
// termination the timers must be stopped so that this factory and the
// stores can be disposed of.
- for (IndexedDBBackingStoreMap::iterator it = backing_store_map_.begin();
- it != backing_store_map_.end();
- ++it)
- it->second->close_timer()->Stop();
+ for (const auto& it : backing_store_map_)
+ it.second->close_timer()->Stop();
backing_store_map_.clear();
backing_stores_with_active_blobs_.clear();
context_ = NULL;
diff --git a/content/browser/indexed_db/indexed_db_index_writer.cc b/content/browser/indexed_db/indexed_db_index_writer.cc
index 0f5a254..c9de8a3 100644
--- a/content/browser/indexed_db/indexed_db_index_writer.cc
+++ b/content/browser/indexed_db/indexed_db_index_writer.cc
@@ -131,16 +131,13 @@ bool MakeIndexWriters(
bool* completed) {
*completed = false;
- for (std::vector<IndexedDBDatabase::IndexKeys>::const_iterator it =
- index_keys.begin();
- it != index_keys.end();
- ++it) {
+ for (const auto& it : index_keys) {
IndexedDBObjectStoreMetadata::IndexMap::const_iterator found =
- object_store.indexes.find(it->first);
+ object_store.indexes.find(it.first);
if (found == object_store.indexes.end())
continue;
const IndexedDBIndexMetadata& index = found->second;
- IndexedDBDatabase::IndexKeys keys = *it;
+ IndexedDBDatabase::IndexKeys keys = it;
// If the object_store is using auto_increment, then any indexes with an
// identical key_path need to also use the primary (generated) key as a key.
diff --git a/content/browser/indexed_db/indexed_db_leveldb_coding.cc b/content/browser/indexed_db/indexed_db_leveldb_coding.cc
index 1f516c8..f8a3a1e 100644
--- a/content/browser/indexed_db/indexed_db_leveldb_coding.cc
+++ b/content/browser/indexed_db/indexed_db_leveldb_coding.cc
@@ -380,10 +380,9 @@ void EncodeIDBKeyPath(const IndexedDBKeyPath& value, std::string* into) {
}
void EncodeBlobJournal(const BlobJournalType& journal, std::string* into) {
- BlobJournalType::const_iterator iter;
- for (iter = journal.begin(); iter != journal.end(); ++iter) {
- EncodeVarInt(iter->first, into);
- EncodeVarInt(iter->second, into);
+ for (const auto& iter : journal) {
+ EncodeVarInt(iter.first, into);
+ EncodeVarInt(iter.second, into);
}
}
diff --git a/content/browser/indexed_db/indexed_db_leveldb_coding_unittest.cc b/content/browser/indexed_db/indexed_db_leveldb_coding_unittest.cc
index 0bd647c..5f9edf1 100644
--- a/content/browser/indexed_db/indexed_db_leveldb_coding_unittest.cc
+++ b/content/browser/indexed_db/indexed_db_leveldb_coding_unittest.cc
@@ -726,15 +726,13 @@ TEST(IndexedDBLevelDBCodingTest, EncodeDecodeBlobJournal) {
journals.push_back(journal);
}
- std::vector<BlobJournalType>::const_iterator journal_iter;
- for (journal_iter = journals.begin(); journal_iter != journals.end();
- ++journal_iter) {
+ for (const auto& journal_iter : journals) {
std::string encoding;
- EncodeBlobJournal(*journal_iter, &encoding);
+ EncodeBlobJournal(journal_iter, &encoding);
StringPiece slice(encoding);
BlobJournalType journal_out;
EXPECT_TRUE(DecodeBlobJournal(&slice, &journal_out));
- EXPECT_EQ(*journal_iter, journal_out);
+ EXPECT_EQ(journal_iter, journal_out);
}
journals.clear();
@@ -751,10 +749,9 @@ TEST(IndexedDBLevelDBCodingTest, EncodeDecodeBlobJournal) {
journals.push_back(journal);
}
- for (journal_iter = journals.begin(); journal_iter != journals.end();
- ++journal_iter) {
+ for (const auto& journal_iter : journals) {
std::string encoding;
- EncodeBlobJournal(*journal_iter, &encoding);
+ EncodeBlobJournal(journal_iter, &encoding);
StringPiece slice(encoding);
BlobJournalType journal_out;
EXPECT_FALSE(DecodeBlobJournal(&slice, &journal_out));
diff --git a/content/browser/indexed_db/indexed_db_quota_client.cc b/content/browser/indexed_db/indexed_db_quota_client.cc
index 0d9e8b4..d8af36c 100644
--- a/content/browser/indexed_db/indexed_db_quota_client.cc
+++ b/content/browser/indexed_db/indexed_db_quota_client.cc
@@ -49,11 +49,9 @@ void GetOriginsForHostOnIndexedDBThread(IndexedDBContextImpl* context,
std::set<GURL>* origins_to_return) {
DCHECK(context->TaskRunner()->RunsTasksOnCurrentThread());
std::vector<GURL> all_origins = context->GetAllOrigins();
- for (std::vector<GURL>::const_iterator iter = all_origins.begin();
- iter != all_origins.end();
- ++iter) {
- if (host == net::GetHostOrSpecFromURL(*iter))
- origins_to_return->insert(*iter);
+ for (const auto& origin_url : all_origins) {
+ if (host == net::GetHostOrSpecFromURL(origin_url))
+ origins_to_return->insert(origin_url);
}
}
diff --git a/content/browser/indexed_db/indexed_db_transaction.cc b/content/browser/indexed_db/indexed_db_transaction.cc
index 61ca274..8c144f7 100644
--- a/content/browser/indexed_db/indexed_db_transaction.cc
+++ b/content/browser/indexed_db/indexed_db_transaction.cc
@@ -397,10 +397,8 @@ void IndexedDBTransaction::Timeout() {
}
void IndexedDBTransaction::CloseOpenCursors() {
- for (std::set<IndexedDBCursor*>::iterator i = open_cursors_.begin();
- i != open_cursors_.end();
- ++i)
- (*i)->Close();
+ for (auto* cursor : open_cursors_)
+ cursor->Close();
open_cursors_.clear();
}
diff --git a/content/browser/indexed_db/indexed_db_transaction_coordinator.cc b/content/browser/indexed_db/indexed_db_transaction_coordinator.cc
index fe1f545..ca7f383 100644
--- a/content/browser/indexed_db/indexed_db_transaction_coordinator.cc
+++ b/content/browser/indexed_db/indexed_db_transaction_coordinator.cc
@@ -67,16 +67,10 @@ std::vector<const IndexedDBTransaction*>
IndexedDBTransactionCoordinator::GetTransactions() const {
std::vector<const IndexedDBTransaction*> result;
- for (TransactionSet::const_iterator it = started_transactions_.begin();
- it != started_transactions_.end();
- ++it) {
- result.push_back(it->get());
- }
- for (TransactionSet::const_iterator it = queued_transactions_.begin();
- it != queued_transactions_.end();
- ++it) {
- result.push_back(it->get());
- }
+ for (const auto& transaction : started_transactions_)
+ result.push_back(transaction.get());
+ for (const auto& transaction : queued_transactions_)
+ result.push_back(transaction.get());
return result;
}
@@ -94,10 +88,7 @@ void IndexedDBTransactionCoordinator::ProcessQueuedTransactions() {
// data. ("Version change" transactions are exclusive, but handled by the
// connection sequencing in IndexedDBDatabase.)
std::set<int64> locked_scope;
- for (TransactionSet::const_iterator it = started_transactions_.begin();
- it != started_transactions_.end();
- ++it) {
- IndexedDBTransaction* transaction = it->get();
+ for (const auto& transaction : started_transactions_) {
if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) {
// Started read/write transactions have exclusive access to the object
// stores within their scopes.
diff --git a/content/browser/indexed_db/leveldb/leveldb_transaction.cc b/content/browser/indexed_db/leveldb/leveldb_transaction.cc
index 40e7a50..26e2b94 100644
--- a/content/browser/indexed_db/leveldb/leveldb_transaction.cc
+++ b/content/browser/indexed_db/leveldb/leveldb_transaction.cc
@@ -27,9 +27,8 @@ LevelDBTransaction::Record::Record() : deleted(false) {}
LevelDBTransaction::Record::~Record() {}
void LevelDBTransaction::Clear() {
- for (DataType::iterator it = data_.begin(); it != data_.end(); ++it) {
- delete it->second;
- }
+ for (const auto& it : data_)
+ delete it.second;
data_.clear();
}
@@ -98,12 +97,11 @@ leveldb::Status LevelDBTransaction::Commit() {
base::TimeTicks begin_time = base::TimeTicks::Now();
scoped_ptr<LevelDBWriteBatch> write_batch = LevelDBWriteBatch::Create();
- for (DataType::iterator iterator = data_.begin(); iterator != data_.end();
- ++iterator) {
- if (!iterator->second->deleted)
- write_batch->Put(iterator->first, iterator->second->value);
+ for (const auto& iterator : data_) {
+ if (!iterator.second->deleted)
+ write_batch->Put(iterator.first, iterator.second->value);
else
- write_batch->Remove(iterator->first);
+ write_batch->Remove(iterator.first);
}
leveldb::Status s = db_->Write(*write_batch);
@@ -444,12 +442,8 @@ void LevelDBTransaction::UnregisterIterator(TransactionIterator* iterator) {
}
void LevelDBTransaction::NotifyIterators() {
- for (std::set<TransactionIterator*>::iterator i = iterators_.begin();
- i != iterators_.end();
- ++i) {
- TransactionIterator* transaction_iterator = *i;
+ for (auto* transaction_iterator : iterators_)
transaction_iterator->DataChanged();
- }
}
scoped_ptr<LevelDBDirectTransaction> LevelDBDirectTransaction::Create(