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

Side by Side Diff: storage/browser/fileapi/sandbox_directory_database.cc

Issue 1639973002: FileSystem: Prevent iterator from being deleted after database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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. 3 // found in the LICENSE file.
4 4
5 #include "storage/browser/fileapi/sandbox_directory_database.h" 5 #include "storage/browser/fileapi/sandbox_directory_database.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <algorithm> 10 #include <algorithm>
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel, 837 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel,
838 INIT_STATUS_IO_ERROR, INIT_STATUS_MAX); 838 INIT_STATUS_IO_ERROR, INIT_STATUS_MAX);
839 } else { 839 } else {
840 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel, 840 UMA_HISTOGRAM_ENUMERATION(kInitStatusHistogramLabel,
841 INIT_STATUS_UNKNOWN_ERROR, INIT_STATUS_MAX); 841 INIT_STATUS_UNKNOWN_ERROR, INIT_STATUS_MAX);
842 } 842 }
843 } 843 }
844 844
845 bool SandboxDirectoryDatabase::StoreDefaultValues() { 845 bool SandboxDirectoryDatabase::StoreDefaultValues() {
846 // Verify that this is a totally new database, and initialize it. 846 // Verify that this is a totally new database, and initialize it.
847 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(leveldb::ReadOptions())); 847 {
848 iter->SeekToFirst(); 848 scoped_ptr<leveldb::Iterator> iter(
nhiroki 2016/01/27 00:48:00 Can you add a comment about why we need to wrap th
cmumford 2016/01/27 16:33:56 Done.
849 if (iter->Valid()) { // DB was not empty--we shouldn't have been called. 849 db_->NewIterator(leveldb::ReadOptions()));
850 LOG(ERROR) << "File system origin database is corrupt!"; 850 iter->SeekToFirst();
851 return false; 851 if (iter->Valid()) { // DB was not empty--we shouldn't have been called.
852 LOG(ERROR) << "File system origin database is corrupt!";
853 return false;
854 }
852 } 855 }
853 // This is always the first write into the database. If we ever add a 856 // This is always the first write into the database. If we ever add a
854 // version number, it should go in this transaction too. 857 // version number, it should go in this transaction too.
855 FileInfo root; 858 FileInfo root;
856 root.parent_id = 0; 859 root.parent_id = 0;
857 root.modification_time = base::Time::Now(); 860 root.modification_time = base::Time::Now();
858 leveldb::WriteBatch batch; 861 leveldb::WriteBatch batch;
859 if (!AddFileInfoHelper(root, 0, &batch)) 862 if (!AddFileInfoHelper(root, 0, &batch))
860 return false; 863 return false;
861 batch.Put(LastFileIdKey(), base::Int64ToString(0)); 864 batch.Put(LastFileIdKey(), base::Int64ToString(0));
862 batch.Put(LastIntegerKey(), base::Int64ToString(-1)); 865 batch.Put(LastIntegerKey(), base::Int64ToString(-1));
863 leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch); 866 leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch);
864 if (!status.ok()) { 867 if (!status.ok()) {
865 HandleError(FROM_HERE, status); 868 HandleError(FROM_HERE, status);
nhiroki 2016/01/27 00:48:00 Can you add a comment in the header file like this
cmumford 2016/01/27 16:33:56 Done.
866 return false; 869 return false;
867 } 870 }
868 return true; 871 return true;
869 } 872 }
870 873
871 bool SandboxDirectoryDatabase::GetLastFileId(FileId* file_id) { 874 bool SandboxDirectoryDatabase::GetLastFileId(FileId* file_id) {
872 if (!Init(REPAIR_ON_CORRUPTION)) 875 if (!Init(REPAIR_ON_CORRUPTION))
873 return false; 876 return false;
874 DCHECK(file_id); 877 DCHECK(file_id);
875 std::string id_string; 878 std::string id_string;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 946
944 void SandboxDirectoryDatabase::HandleError( 947 void SandboxDirectoryDatabase::HandleError(
945 const tracked_objects::Location& from_here, 948 const tracked_objects::Location& from_here,
946 const leveldb::Status& status) { 949 const leveldb::Status& status) {
947 LOG(ERROR) << "SandboxDirectoryDatabase failed at: " 950 LOG(ERROR) << "SandboxDirectoryDatabase failed at: "
948 << from_here.ToString() << " with error: " << status.ToString(); 951 << from_here.ToString() << " with error: " << status.ToString();
949 db_.reset(); 952 db_.reset();
950 } 953 }
951 954
952 } // namespace storage 955 } // namespace storage
OLDNEW
« no previous file with comments | « no previous file | storage/browser/fileapi/sandbox_origin_database.cc » ('j') | storage/browser/fileapi/sandbox_origin_database.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698