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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 // Skip the dummy entry "map-<mapid>-". | 516 // Skip the dummy entry "map-<mapid>-". |
517 for (it->Next(); it->Valid(); it->Next()) { | 517 for (it->Next(); it->Valid(); it->Next()) { |
518 std::string key = it->key().ToString(); | 518 std::string key = it->key().ToString(); |
519 if (key.find(map_start_key) != 0) { | 519 if (key.find(map_start_key) != 0) { |
520 // Iterated past the keys in this map. | 520 // Iterated past the keys in this map. |
521 break; | 521 break; |
522 } | 522 } |
523 // Key is of the form "map-<mapid>-<key>". | 523 // Key is of the form "map-<mapid>-<key>". |
524 base::string16 key16 = UTF8ToUTF16(key.substr(map_start_key.length())); | 524 base::string16 key16 = UTF8ToUTF16(key.substr(map_start_key.length())); |
525 if (only_keys) { | 525 if (only_keys) { |
526 (*result)[key16] = NullableString16(true); | 526 (*result)[key16] = base::NullableString16(true); |
527 } else { | 527 } else { |
528 // Convert the raw data stored in std::string (it->value()) to raw data | 528 // Convert the raw data stored in std::string (it->value()) to raw data |
529 // stored in base::string16. | 529 // stored in base::string16. |
530 size_t len = it->value().size() / sizeof(char16); | 530 size_t len = it->value().size() / sizeof(char16); |
531 const char16* data_ptr = | 531 const char16* data_ptr = |
532 reinterpret_cast<const char16*>(it->value().data()); | 532 reinterpret_cast<const char16*>(it->value().data()); |
533 (*result)[key16] = NullableString16(base::string16(data_ptr, len), false); | 533 (*result)[key16] = |
| 534 base::NullableString16(base::string16(data_ptr, len), false); |
534 } | 535 } |
535 } | 536 } |
536 return true; | 537 return true; |
537 } | 538 } |
538 | 539 |
539 void SessionStorageDatabase::WriteValuesToMap(const std::string& map_id, | 540 void SessionStorageDatabase::WriteValuesToMap(const std::string& map_id, |
540 const ValuesMap& values, | 541 const ValuesMap& values, |
541 leveldb::WriteBatch* batch) { | 542 leveldb::WriteBatch* batch) { |
542 for (ValuesMap::const_iterator it = values.begin(); it != values.end(); | 543 for (ValuesMap::const_iterator it = values.begin(); it != values.end(); |
543 ++it) { | 544 ++it) { |
544 NullableString16 value = it->second; | 545 base::NullableString16 value = it->second; |
545 std::string key = MapKey(map_id, UTF16ToUTF8(it->first)); | 546 std::string key = MapKey(map_id, UTF16ToUTF8(it->first)); |
546 if (value.is_null()) { | 547 if (value.is_null()) { |
547 batch->Delete(key); | 548 batch->Delete(key); |
548 } else { | 549 } else { |
549 // Convert the raw data stored in base::string16 to raw data stored in | 550 // Convert the raw data stored in base::string16 to raw data stored in |
550 // std::string. | 551 // std::string. |
551 const char* data = reinterpret_cast<const char*>(value.string().data()); | 552 const char* data = reinterpret_cast<const char*>(value.string().data()); |
552 size_t size = value.string().size() * 2; | 553 size_t size = value.string().size() * 2; |
553 batch->Put(key, leveldb::Slice(data, size)); | 554 batch->Put(key, leveldb::Slice(data, size)); |
554 } | 555 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 667 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
667 const std::string& key) { | 668 const std::string& key) { |
668 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()); |
669 } | 670 } |
670 | 671 |
671 const char* SessionStorageDatabase::NextMapIdKey() { | 672 const char* SessionStorageDatabase::NextMapIdKey() { |
672 return "next-map-id"; | 673 return "next-map-id"; |
673 } | 674 } |
674 | 675 |
675 } // namespace dom_storage | 676 } // namespace dom_storage |
OLD | NEW |