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/metrics/histogram.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 if (!DatabaseErrorCheck(it->status().ok())) | 514 if (!DatabaseErrorCheck(it->status().ok())) |
515 return false; | 515 return false; |
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 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] = 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 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(string16(data_ptr, len), false); | 533 (*result)[key16] = NullableString16(base::string16(data_ptr, len), false); |
534 } | 534 } |
535 } | 535 } |
536 return true; | 536 return true; |
537 } | 537 } |
538 | 538 |
539 void SessionStorageDatabase::WriteValuesToMap(const std::string& map_id, | 539 void SessionStorageDatabase::WriteValuesToMap(const std::string& map_id, |
540 const ValuesMap& values, | 540 const ValuesMap& values, |
541 leveldb::WriteBatch* batch) { | 541 leveldb::WriteBatch* batch) { |
542 for (ValuesMap::const_iterator it = values.begin(); it != values.end(); | 542 for (ValuesMap::const_iterator it = values.begin(); it != values.end(); |
543 ++it) { | 543 ++it) { |
544 NullableString16 value = it->second; | 544 NullableString16 value = it->second; |
545 std::string key = MapKey(map_id, UTF16ToUTF8(it->first)); | 545 std::string key = MapKey(map_id, UTF16ToUTF8(it->first)); |
546 if (value.is_null()) { | 546 if (value.is_null()) { |
547 batch->Delete(key); | 547 batch->Delete(key); |
548 } else { | 548 } else { |
549 // Convert the raw data stored in string16 to raw data stored in | 549 // Convert the raw data stored in base::string16 to raw data stored in |
550 // std::string. | 550 // std::string. |
551 const char* data = reinterpret_cast<const char*>(value.string().data()); | 551 const char* data = reinterpret_cast<const char*>(value.string().data()); |
552 size_t size = value.string().size() * 2; | 552 size_t size = value.string().size() * 2; |
553 batch->Put(key, leveldb::Slice(data, size)); | 553 batch->Put(key, leveldb::Slice(data, size)); |
554 } | 554 } |
555 } | 555 } |
556 } | 556 } |
557 | 557 |
558 bool SessionStorageDatabase::GetMapRefCount(const std::string& map_id, | 558 bool SessionStorageDatabase::GetMapRefCount(const std::string& map_id, |
559 int64* ref_count) { | 559 int64* ref_count) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 666 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
667 const std::string& key) { | 667 const std::string& key) { |
668 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 668 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
669 } | 669 } |
670 | 670 |
671 const char* SessionStorageDatabase::NextMapIdKey() { | 671 const char* SessionStorageDatabase::NextMapIdKey() { |
672 return "next-map-id"; | 672 return "next-map-id"; |
673 } | 673 } |
674 | 674 |
675 } // namespace dom_storage | 675 } // namespace dom_storage |
OLD | NEW |