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

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: Added comments. Created 4 years, 11 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 // Scope the iterator to ensure deleted before database is closed.
849 if (iter->Valid()) { // DB was not empty--we shouldn't have been called. 849 scoped_ptr<leveldb::Iterator> iter(
850 LOG(ERROR) << "File system origin database is corrupt!"; 850 db_->NewIterator(leveldb::ReadOptions()));
851 return false; 851 iter->SeekToFirst();
852 if (iter->Valid()) { // DB was not empty--we shouldn't have been called.
853 LOG(ERROR) << "File system origin database is corrupt!";
854 return false;
855 }
852 } 856 }
853 // This is always the first write into the database. If we ever add a 857 // This is always the first write into the database. If we ever add a
854 // version number, it should go in this transaction too. 858 // version number, it should go in this transaction too.
855 FileInfo root; 859 FileInfo root;
856 root.parent_id = 0; 860 root.parent_id = 0;
857 root.modification_time = base::Time::Now(); 861 root.modification_time = base::Time::Now();
858 leveldb::WriteBatch batch; 862 leveldb::WriteBatch batch;
859 if (!AddFileInfoHelper(root, 0, &batch)) 863 if (!AddFileInfoHelper(root, 0, &batch))
860 return false; 864 return false;
861 batch.Put(LastFileIdKey(), base::Int64ToString(0)); 865 batch.Put(LastFileIdKey(), base::Int64ToString(0));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 947
944 void SandboxDirectoryDatabase::HandleError( 948 void SandboxDirectoryDatabase::HandleError(
945 const tracked_objects::Location& from_here, 949 const tracked_objects::Location& from_here,
946 const leveldb::Status& status) { 950 const leveldb::Status& status) {
947 LOG(ERROR) << "SandboxDirectoryDatabase failed at: " 951 LOG(ERROR) << "SandboxDirectoryDatabase failed at: "
948 << from_here.ToString() << " with error: " << status.ToString(); 952 << from_here.ToString() << " with error: " << status.ToString();
949 db_.reset(); 953 db_.reset();
950 } 954 }
951 955
952 } // namespace storage 956 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/fileapi/sandbox_directory_database.h ('k') | storage/browser/fileapi/sandbox_origin_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698