Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: third_party/leveldatabase/env_chromium.cc

Issue 790913003: IndexedDB: Cleanup to remove iterators and improve variable names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: auto -> std::string Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors. 3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 4
5 #include "third_party/leveldatabase/env_chromium.h" 5 #include "third_party/leveldatabase/env_chromium.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <dirent.h> 8 #include <dirent.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #endif 10 #endif
(...skipping 27 matching lines...) Expand all
38 static base::File::Error LastFileError() { 38 static base::File::Error LastFileError() {
39 #if defined(OS_WIN) 39 #if defined(OS_WIN)
40 return base::File::OSErrorToFileError(GetLastError()); 40 return base::File::OSErrorToFileError(GetLastError());
41 #else 41 #else
42 return base::File::OSErrorToFileError(errno); 42 return base::File::OSErrorToFileError(errno);
43 #endif 43 #endif
44 } 44 }
45 45
46 // Making direct platform in lieu of using base::FileEnumerator because the 46 // Making direct platform in lieu of using base::FileEnumerator because the
47 // latter can fail quietly without return an error result. 47 // latter can fail quietly without return an error result.
48 static base::File::Error GetDirectoryEntries( 48 static base::File::Error GetDirectoryEntries(const FilePath& dir_param,
49 const FilePath& dir_param, 49 std::vector<FilePath>* result) {
50 std::vector<FilePath>* result) {
51 result->clear(); 50 result->clear();
52 #if defined(OS_WIN) 51 #if defined(OS_WIN)
53 FilePath dir_filepath = dir_param.Append(FILE_PATH_LITERAL("*")); 52 FilePath dir_filepath = dir_param.Append(FILE_PATH_LITERAL("*"));
54 WIN32_FIND_DATA find_data; 53 WIN32_FIND_DATA find_data;
55 HANDLE find_handle = FindFirstFile(dir_filepath.value().c_str(), &find_data); 54 HANDLE find_handle = FindFirstFile(dir_filepath.value().c_str(), &find_data);
56 if (find_handle == INVALID_HANDLE_VALUE) { 55 if (find_handle == INVALID_HANDLE_VALUE) {
57 DWORD last_error = GetLastError(); 56 DWORD last_error = GetLastError();
58 if (last_error == ERROR_FILE_NOT_FOUND) 57 if (last_error == ERROR_FILE_NOT_FOUND)
59 return base::File::FILE_OK; 58 return base::File::FILE_OK;
60 return base::File::OSErrorToFileError(last_error); 59 return base::File::OSErrorToFileError(last_error);
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 bool result = base::CopyFile(base_name.AddExtension(backup_table_extension), 592 bool result = base::CopyFile(base_name.AddExtension(backup_table_extension),
594 table_name); 593 table_name);
595 std::string uma_name(name_); 594 std::string uma_name(name_);
596 uma_name.append(".TableRestore"); 595 uma_name.append(".TableRestore");
597 base::BooleanHistogram::FactoryGet( 596 base::BooleanHistogram::FactoryGet(
598 uma_name, base::Histogram::kUmaTargetedHistogramFlag)->AddBoolean(result); 597 uma_name, base::Histogram::kUmaTargetedHistogramFlag)->AddBoolean(result);
599 return table_name; 598 return table_name;
600 } 599 }
601 600
602 void ChromiumEnv::RestoreIfNecessary(const std::string& dir, 601 void ChromiumEnv::RestoreIfNecessary(const std::string& dir,
603 std::vector<std::string>* result) { 602 std::vector<std::string>* dir_entries) {
604 std::set<FilePath> tables_found; 603 std::set<FilePath> tables_found;
605 std::set<FilePath> backups_found; 604 std::set<FilePath> backups_found;
606 for (std::vector<std::string>::iterator it = result->begin(); 605 for (const std::string& entry : *dir_entries) {
607 it != result->end(); 606 FilePath current = FilePath::FromUTF8Unsafe(entry);
608 ++it) {
609 FilePath current = FilePath::FromUTF8Unsafe(*it);
610 if (current.MatchesExtension(table_extension)) 607 if (current.MatchesExtension(table_extension))
611 tables_found.insert(current.RemoveExtension()); 608 tables_found.insert(current.RemoveExtension());
612 if (current.MatchesExtension(backup_table_extension)) 609 if (current.MatchesExtension(backup_table_extension))
613 backups_found.insert(current.RemoveExtension()); 610 backups_found.insert(current.RemoveExtension());
614 } 611 }
615 std::set<FilePath> backups_only = 612 std::set<FilePath> backups_only =
616 base::STLSetDifference<std::set<FilePath>>(backups_found, tables_found); 613 base::STLSetDifference<std::set<FilePath>>(backups_found, tables_found);
617 614
618 if (backups_only.size()) { 615 if (backups_only.size()) {
619 std::string uma_name(name_); 616 std::string uma_name(name_);
620 uma_name.append(".MissingFiles"); 617 uma_name.append(".MissingFiles");
621 int num_missing_files = 618 int num_missing_files =
622 backups_only.size() > INT_MAX ? INT_MAX : backups_only.size(); 619 backups_only.size() > INT_MAX ? INT_MAX : backups_only.size();
623 base::Histogram::FactoryGet(uma_name, 620 base::Histogram::FactoryGet(uma_name,
624 1 /*min*/, 621 1 /*min*/,
625 100 /*max*/, 622 100 /*max*/,
626 8 /*num_buckets*/, 623 8 /*num_buckets*/,
627 base::Histogram::kUmaTargetedHistogramFlag) 624 base::Histogram::kUmaTargetedHistogramFlag)
628 ->Add(num_missing_files); 625 ->Add(num_missing_files);
629 } 626 }
630 FilePath dir_filepath = FilePath::FromUTF8Unsafe(dir); 627 FilePath dir_path = FilePath::FromUTF8Unsafe(dir);
631 for (std::set<FilePath>::iterator it = backups_only.begin(); 628 for (const FilePath& backup : backups_only) {
632 it != backups_only.end(); ++it) { 629 FilePath restored_table_name = RestoreFromBackup(dir_path.Append(backup));
633 FilePath restored_table_name = RestoreFromBackup(dir_filepath.Append(*it)); 630 dir_entries->push_back(restored_table_name.BaseName().AsUTF8Unsafe());
634 result->push_back(restored_table_name.BaseName().AsUTF8Unsafe());
635 } 631 }
636 } 632 }
637 633
638 Status ChromiumEnv::GetChildren(const std::string& dir_string, 634 Status ChromiumEnv::GetChildren(const std::string& dir,
639 std::vector<std::string>* result) { 635 std::vector<std::string>* result) {
640 std::vector<FilePath> entries; 636 std::vector<FilePath> entries;
641 base::File::Error error = 637 base::File::Error error =
642 GetDirectoryEntries(FilePath::FromUTF8Unsafe(dir_string), &entries); 638 GetDirectoryEntries(FilePath::FromUTF8Unsafe(dir), &entries);
643 if (error != base::File::FILE_OK) { 639 if (error != base::File::FILE_OK) {
644 RecordOSError(kGetChildren, error); 640 RecordOSError(kGetChildren, error);
645 return MakeIOError( 641 return MakeIOError(dir, "Could not open/read directory", kGetChildren,
646 dir_string, "Could not open/read directory", kGetChildren, error); 642 error);
647 } 643 }
648 644
649 result->clear(); 645 result->clear();
650 for (const auto& entry : entries) 646 for (const auto& entry : entries)
651 result->push_back(entry.BaseName().AsUTF8Unsafe()); 647 result->push_back(entry.BaseName().AsUTF8Unsafe());
652 648
653 if (make_backup_) 649 if (make_backup_)
654 RestoreIfNecessary(dir_string, result); 650 RestoreIfNecessary(dir, result);
655 651
656 return Status::OK(); 652 return Status::OK();
657 } 653 }
658 654
659 Status ChromiumEnv::DeleteFile(const std::string& fname) { 655 Status ChromiumEnv::DeleteFile(const std::string& fname) {
660 Status result; 656 Status result;
661 FilePath fname_filepath = FilePath::FromUTF8Unsafe(fname); 657 FilePath fname_filepath = FilePath::FromUTF8Unsafe(fname);
662 // TODO(jorlow): Should we assert this is a file? 658 // TODO(jorlow): Should we assert this is a file?
663 if (!::base::DeleteFile(fname_filepath, false)) { 659 if (!::base::DeleteFile(fname_filepath, false)) {
664 result = MakeIOError(fname, "Could not delete file.", kDeleteFile); 660 result = MakeIOError(fname, "Could not delete file.", kDeleteFile);
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 1087
1092 Env* IDBEnv() { 1088 Env* IDBEnv() {
1093 return leveldb_env::idb_env.Pointer(); 1089 return leveldb_env::idb_env.Pointer();
1094 } 1090 }
1095 1091
1096 Env* Env::Default() { 1092 Env* Env::Default() {
1097 return leveldb_env::default_env.Pointer(); 1093 return leveldb_env::default_env.Pointer();
1098 } 1094 }
1099 1095
1100 } // namespace leveldb 1096 } // namespace leveldb
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698