Commit d1fd3a07 authored by cmumford's avatar cmumford Committed by Commit bot

IndexedDB: Cleanup to remove iterators and improve variable names

Some cleanup:

* Replaced iterator with range based for loop.
* Renamed a few parameters/local variables to improve clarity:
  * ChromiumEnv::RestoreIfNecessary "result" param -> "dir_entries".
  * "dir_filepath" -> "dir_path"
  * ChromiumEnv::GetChildren "dir_string" -> "dir"
* Accepted some "git cl format" improvements.

Review URL: https://codereview.chromium.org/790913003

Cr-Commit-Position: refs/heads/master@{#308211}
parent 67650d64
...@@ -45,9 +45,8 @@ static base::File::Error LastFileError() { ...@@ -45,9 +45,8 @@ static base::File::Error LastFileError() {
// Making direct platform in lieu of using base::FileEnumerator because the // Making direct platform in lieu of using base::FileEnumerator because the
// latter can fail quietly without return an error result. // latter can fail quietly without return an error result.
static base::File::Error GetDirectoryEntries( static base::File::Error GetDirectoryEntries(const FilePath& dir_param,
const FilePath& dir_param, std::vector<FilePath>* result) {
std::vector<FilePath>* result) {
result->clear(); result->clear();
#if defined(OS_WIN) #if defined(OS_WIN)
FilePath dir_filepath = dir_param.Append(FILE_PATH_LITERAL("*")); FilePath dir_filepath = dir_param.Append(FILE_PATH_LITERAL("*"));
...@@ -600,13 +599,11 @@ FilePath ChromiumEnv::RestoreFromBackup(const FilePath& base_name) { ...@@ -600,13 +599,11 @@ FilePath ChromiumEnv::RestoreFromBackup(const FilePath& base_name) {
} }
void ChromiumEnv::RestoreIfNecessary(const std::string& dir, void ChromiumEnv::RestoreIfNecessary(const std::string& dir,
std::vector<std::string>* result) { std::vector<std::string>* dir_entries) {
std::set<FilePath> tables_found; std::set<FilePath> tables_found;
std::set<FilePath> backups_found; std::set<FilePath> backups_found;
for (std::vector<std::string>::iterator it = result->begin(); for (const std::string& entry : *dir_entries) {
it != result->end(); FilePath current = FilePath::FromUTF8Unsafe(entry);
++it) {
FilePath current = FilePath::FromUTF8Unsafe(*it);
if (current.MatchesExtension(table_extension)) if (current.MatchesExtension(table_extension))
tables_found.insert(current.RemoveExtension()); tables_found.insert(current.RemoveExtension());
if (current.MatchesExtension(backup_table_extension)) if (current.MatchesExtension(backup_table_extension))
...@@ -627,23 +624,22 @@ void ChromiumEnv::RestoreIfNecessary(const std::string& dir, ...@@ -627,23 +624,22 @@ void ChromiumEnv::RestoreIfNecessary(const std::string& dir,
base::Histogram::kUmaTargetedHistogramFlag) base::Histogram::kUmaTargetedHistogramFlag)
->Add(num_missing_files); ->Add(num_missing_files);
} }
FilePath dir_filepath = FilePath::FromUTF8Unsafe(dir); FilePath dir_path = FilePath::FromUTF8Unsafe(dir);
for (std::set<FilePath>::iterator it = backups_only.begin(); for (const FilePath& backup : backups_only) {
it != backups_only.end(); ++it) { FilePath restored_table_name = RestoreFromBackup(dir_path.Append(backup));
FilePath restored_table_name = RestoreFromBackup(dir_filepath.Append(*it)); dir_entries->push_back(restored_table_name.BaseName().AsUTF8Unsafe());
result->push_back(restored_table_name.BaseName().AsUTF8Unsafe());
} }
} }
Status ChromiumEnv::GetChildren(const std::string& dir_string, Status ChromiumEnv::GetChildren(const std::string& dir,
std::vector<std::string>* result) { std::vector<std::string>* result) {
std::vector<FilePath> entries; std::vector<FilePath> entries;
base::File::Error error = base::File::Error error =
GetDirectoryEntries(FilePath::FromUTF8Unsafe(dir_string), &entries); GetDirectoryEntries(FilePath::FromUTF8Unsafe(dir), &entries);
if (error != base::File::FILE_OK) { if (error != base::File::FILE_OK) {
RecordOSError(kGetChildren, error); RecordOSError(kGetChildren, error);
return MakeIOError( return MakeIOError(dir, "Could not open/read directory", kGetChildren,
dir_string, "Could not open/read directory", kGetChildren, error); error);
} }
result->clear(); result->clear();
...@@ -651,7 +647,7 @@ Status ChromiumEnv::GetChildren(const std::string& dir_string, ...@@ -651,7 +647,7 @@ Status ChromiumEnv::GetChildren(const std::string& dir_string,
result->push_back(entry.BaseName().AsUTF8Unsafe()); result->push_back(entry.BaseName().AsUTF8Unsafe());
if (make_backup_) if (make_backup_)
RestoreIfNecessary(dir_string, result); RestoreIfNecessary(dir, result);
return Status::OK(); return Status::OK();
} }
......
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