| 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/dom_storage/session_storage_database.h" | 5 #include "webkit/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/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 13 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 14 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 14 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" | 15 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" |
| 15 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 16 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 16 #include "third_party/leveldatabase/src/include/leveldb/options.h" | 17 #include "third_party/leveldatabase/src/include/leveldb/options.h" |
| 17 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 18 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
| 18 | 19 |
| 20 #define SESSION_STORAGE_UMA_NAME "SessionStorageDatabase.Open" |
| 21 |
| 22 namespace { |
| 23 |
| 24 enum SessionStorageUMA { |
| 25 SESSION_STORAGE_UMA_SUCCESS, |
| 26 SESSION_STORAGE_UMA_RECREATED, |
| 27 SESSION_STORAGE_UMA_FAIL, |
| 28 SESSION_STORAGE_UMA_MAX |
| 29 }; |
| 30 |
| 31 } // namespace |
| 32 |
| 19 // Layout of the database: | 33 // Layout of the database: |
| 20 // | key | value | | 34 // | key | value | |
| 21 // ----------------------------------------------------------------------- | 35 // ----------------------------------------------------------------------- |
| 22 // | map-1- | 2 (refcount, start of map-1-* keys)| | 36 // | map-1- | 2 (refcount, start of map-1-* keys)| |
| 23 // | map-1-a | b (a = b in map 1) | | 37 // | map-1-a | b (a = b in map 1) | |
| 24 // | ... | | | 38 // | ... | | |
| 25 // | namespace- | dummy (start of namespace-* keys) | | 39 // | namespace- | dummy (start of namespace-* keys) | |
| 26 // | namespace-1- (1 = namespace id)| dummy (start of namespace-1-* keys)| | 40 // | namespace-1- (1 = namespace id)| dummy (start of namespace-1-* keys)| |
| 27 // | namespace-1-origin1 | 1 (mapid) | | 41 // | namespace-1-origin1 | 1 (mapid) | |
| 28 // | namespace-1-origin2 | 2 | | 42 // | namespace-1-origin2 | 2 | |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 LOG(WARNING) << "Failed to open leveldb in " << file_path_.value() | 293 LOG(WARNING) << "Failed to open leveldb in " << file_path_.value() |
| 280 << ", error: " << s.ToString(); | 294 << ", error: " << s.ToString(); |
| 281 DCHECK(db == NULL); | 295 DCHECK(db == NULL); |
| 282 | 296 |
| 283 // Clear the directory and try again. | 297 // Clear the directory and try again. |
| 284 file_util::Delete(file_path_, true); | 298 file_util::Delete(file_path_, true); |
| 285 s = TryToOpen(&db); | 299 s = TryToOpen(&db); |
| 286 if (!s.ok()) { | 300 if (!s.ok()) { |
| 287 LOG(WARNING) << "Failed to open leveldb in " << file_path_.value() | 301 LOG(WARNING) << "Failed to open leveldb in " << file_path_.value() |
| 288 << ", error: " << s.ToString(); | 302 << ", error: " << s.ToString(); |
| 303 UMA_HISTOGRAM_ENUMERATION(SESSION_STORAGE_UMA_NAME, |
| 304 SESSION_STORAGE_UMA_FAIL, |
| 305 SESSION_STORAGE_UMA_MAX); |
| 289 DCHECK(db == NULL); | 306 DCHECK(db == NULL); |
| 290 db_error_ = true; | 307 db_error_ = true; |
| 291 return false; | 308 return false; |
| 292 } | 309 } |
| 310 UMA_HISTOGRAM_ENUMERATION(SESSION_STORAGE_UMA_NAME, |
| 311 SESSION_STORAGE_UMA_RECREATED, |
| 312 SESSION_STORAGE_UMA_MAX); |
| 313 } else { |
| 314 UMA_HISTOGRAM_ENUMERATION(SESSION_STORAGE_UMA_NAME, |
| 315 SESSION_STORAGE_UMA_SUCCESS, |
| 316 SESSION_STORAGE_UMA_MAX); |
| 293 } | 317 } |
| 294 db_.reset(db); | 318 db_.reset(db); |
| 295 return true; | 319 return true; |
| 296 } | 320 } |
| 297 | 321 |
| 298 leveldb::Status SessionStorageDatabase::TryToOpen(leveldb::DB** db) { | 322 leveldb::Status SessionStorageDatabase::TryToOpen(leveldb::DB** db) { |
| 299 leveldb::Options options; | 323 leveldb::Options options; |
| 300 // The directory exists but a valid leveldb database might not exist inside it | 324 // The directory exists but a valid leveldb database might not exist inside it |
| 301 // (e.g., a subset of the needed files might be missing). Handle this | 325 // (e.g., a subset of the needed files might be missing). Handle this |
| 302 // situation gracefully by creating the database now. | 326 // situation gracefully by creating the database now. |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 665 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
| 642 const std::string& key) { | 666 const std::string& key) { |
| 643 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 667 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
| 644 } | 668 } |
| 645 | 669 |
| 646 const char* SessionStorageDatabase::NextMapIdKey() { | 670 const char* SessionStorageDatabase::NextMapIdKey() { |
| 647 return "next-map-id"; | 671 return "next-map-id"; |
| 648 } | 672 } |
| 649 | 673 |
| 650 } // namespace dom_storage | 674 } // namespace dom_storage |
| OLD | NEW |