OLD | NEW |
---|---|
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_origin_database.h" | 5 #include "storage/browser/fileapi/sandbox_origin_database.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 std::string number_string; | 324 std::string number_string; |
325 leveldb::Status status = | 325 leveldb::Status status = |
326 db_->Get(leveldb::ReadOptions(), LastPathKey(), &number_string); | 326 db_->Get(leveldb::ReadOptions(), LastPathKey(), &number_string); |
327 if (status.ok()) | 327 if (status.ok()) |
328 return base::StringToInt(number_string, number); | 328 return base::StringToInt(number_string, number); |
329 if (!status.IsNotFound()) { | 329 if (!status.IsNotFound()) { |
330 HandleError(FROM_HERE, status); | 330 HandleError(FROM_HERE, status); |
331 return false; | 331 return false; |
332 } | 332 } |
333 // Verify that this is a totally new database, and initialize it. | 333 // Verify that this is a totally new database, and initialize it. |
334 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(leveldb::ReadOptions())); | 334 { |
335 iter->SeekToFirst(); | 335 scoped_ptr<leveldb::Iterator> iter( |
nhiroki
2016/01/27 00:48:00
ditto.
cmumford
2016/01/27 16:33:56
Done.
| |
336 if (iter->Valid()) { // DB was not empty, but had no last path number! | 336 db_->NewIterator(leveldb::ReadOptions())); |
337 LOG(ERROR) << "File system origin database is corrupt!"; | 337 iter->SeekToFirst(); |
338 return false; | 338 if (iter->Valid()) { // DB was not empty, but had no last path number! |
339 LOG(ERROR) << "File system origin database is corrupt!"; | |
340 return false; | |
341 } | |
339 } | 342 } |
340 // This is always the first write into the database. If we ever add a | 343 // This is always the first write into the database. If we ever add a |
341 // version number, they should go in in a single transaction. | 344 // version number, they should go in in a single transaction. |
342 status = | 345 status = db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); |
343 db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); | |
344 if (!status.ok()) { | 346 if (!status.ok()) { |
345 HandleError(FROM_HERE, status); | 347 HandleError(FROM_HERE, status); |
346 return false; | 348 return false; |
347 } | 349 } |
348 *number = -1; | 350 *number = -1; |
349 return true; | 351 return true; |
350 } | 352 } |
351 | 353 |
352 } // namespace storage | 354 } // namespace storage |
OLD | NEW |