| 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 "webkit/browser/dom_storage/session_storage_database.h" | 5 #include "webkit/browser/dom_storage/session_storage_database.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { | 272 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { |
| 273 base::AutoLock auto_lock(db_lock_); | 273 base::AutoLock auto_lock(db_lock_); |
| 274 if (db_error_ || is_inconsistent_) { | 274 if (db_error_ || is_inconsistent_) { |
| 275 // Don't try to open a database that we know has failed already. | 275 // Don't try to open a database that we know has failed already. |
| 276 return false; | 276 return false; |
| 277 } | 277 } |
| 278 if (IsOpen()) | 278 if (IsOpen()) |
| 279 return true; | 279 return true; |
| 280 | 280 |
| 281 if (!create_if_needed && | 281 if (!create_if_needed && |
| 282 (!file_util::PathExists(file_path_) || | 282 (!base::PathExists(file_path_) || |
| 283 file_util::IsDirectoryEmpty(file_path_))) { | 283 file_util::IsDirectoryEmpty(file_path_))) { |
| 284 // If the directory doesn't exist already and we haven't been asked to | 284 // If the directory doesn't exist already and we haven't been asked to |
| 285 // create a file on disk, then we don't bother opening the database. This | 285 // create a file on disk, then we don't bother opening the database. This |
| 286 // means we wait until we absolutely need to put something onto disk before | 286 // means we wait until we absolutely need to put something onto disk before |
| 287 // we do so. | 287 // we do so. |
| 288 return false; | 288 return false; |
| 289 } | 289 } |
| 290 | 290 |
| 291 leveldb::DB* db; | 291 leveldb::DB* db; |
| 292 leveldb::Status s = TryToOpen(&db); | 292 leveldb::Status s = TryToOpen(&db); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 667 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
| 668 const std::string& key) { | 668 const std::string& key) { |
| 669 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 669 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
| 670 } | 670 } |
| 671 | 671 |
| 672 const char* SessionStorageDatabase::NextMapIdKey() { | 672 const char* SessionStorageDatabase::NextMapIdKey() { |
| 673 return "next-map-id"; | 673 return "next-map-id"; |
| 674 } | 674 } |
| 675 | 675 |
| 676 } // namespace dom_storage | 676 } // namespace dom_storage |
| OLD | NEW |