OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/dom_storage/session_storage_database.h" | 5 #include "content/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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { | 273 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { |
274 base::AutoLock auto_lock(db_lock_); | 274 base::AutoLock auto_lock(db_lock_); |
275 if (db_error_ || is_inconsistent_) { | 275 if (db_error_ || is_inconsistent_) { |
276 // Don't try to open a database that we know has failed already. | 276 // Don't try to open a database that we know has failed already. |
277 return false; | 277 return false; |
278 } | 278 } |
279 if (IsOpen()) | 279 if (IsOpen()) |
280 return true; | 280 return true; |
281 | 281 |
282 if (!create_if_needed && | 282 if (!create_if_needed && |
283 (!base::PathExists(file_path_) || | 283 (!base::PathExists(file_path_) || base::IsDirectoryEmpty(file_path_))) { |
284 file_util::IsDirectoryEmpty(file_path_))) { | |
285 // 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 |
286 // 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 |
287 // 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 |
288 // we do so. | 287 // we do so. |
289 return false; | 288 return false; |
290 } | 289 } |
291 | 290 |
292 leveldb::DB* db; | 291 leveldb::DB* db; |
293 leveldb::Status s = TryToOpen(&db); | 292 leveldb::Status s = TryToOpen(&db); |
294 if (!s.ok()) { | 293 if (!s.ok()) { |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 670 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
672 const std::string& key) { | 671 const std::string& key) { |
673 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 672 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
674 } | 673 } |
675 | 674 |
676 const char* SessionStorageDatabase::NextMapIdKey() { | 675 const char* SessionStorageDatabase::NextMapIdKey() { |
677 return "next-map-id"; | 676 return "next-map-id"; |
678 } | 677 } |
679 | 678 |
680 } // namespace content | 679 } // namespace content |
OLD | NEW |