| 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 <inttypes.h> | 7 #include <inttypes.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 if (!DatabaseErrorCheck(it->status().ok())) { | 291 if (!DatabaseErrorCheck(it->status().ok())) { |
| 292 db_->ReleaseSnapshot(options.snapshot); | 292 db_->ReleaseSnapshot(options.snapshot); |
| 293 return false; | 293 return false; |
| 294 } | 294 } |
| 295 | 295 |
| 296 // Skip the dummy entry "namespace-" and iterate the namespaces. | 296 // Skip the dummy entry "namespace-" and iterate the namespaces. |
| 297 std::string current_namespace_start_key; | 297 std::string current_namespace_start_key; |
| 298 std::string current_namespace_id; | 298 std::string current_namespace_id; |
| 299 for (it->Next(); it->Valid(); it->Next()) { | 299 for (it->Next(); it->Valid(); it->Next()) { |
| 300 std::string key = it->key().ToString(); | 300 std::string key = it->key().ToString(); |
| 301 if (key.find(namespace_prefix) != 0) { | 301 if (!base::StartsWith(key, namespace_prefix, |
| 302 base::CompareCase::SENSITIVE)) { |
| 302 // Iterated past the "namespace-" keys. | 303 // Iterated past the "namespace-" keys. |
| 303 break; | 304 break; |
| 304 } | 305 } |
| 305 // For each namespace, the first key is "namespace-<namespaceid>-", and the | 306 // For each namespace, the first key is "namespace-<namespaceid>-", and the |
| 306 // subsequent keys are "namespace-<namespaceid>-<origin>". Read the unique | 307 // subsequent keys are "namespace-<namespaceid>-<origin>". Read the unique |
| 307 // "<namespaceid>" parts from the keys. | 308 // "<namespaceid>" parts from the keys. |
| 308 if (current_namespace_start_key.empty() || | 309 if (current_namespace_start_key.empty() || |
| 309 key.substr(0, current_namespace_start_key.length()) != | 310 key.substr(0, current_namespace_start_key.length()) != |
| 310 current_namespace_start_key) { | 311 current_namespace_start_key) { |
| 311 // The key is of the form "namespace-<namespaceid>-" for a new | 312 // The key is of the form "namespace-<namespaceid>-" for a new |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // The namespace_start_key is not found when the namespace doesn't contain | 491 // The namespace_start_key is not found when the namespace doesn't contain |
| 491 // any areas. We don't need to do anything. | 492 // any areas. We don't need to do anything. |
| 492 return true; | 493 return true; |
| 493 } | 494 } |
| 494 if (!DatabaseErrorCheck(it->status().ok())) | 495 if (!DatabaseErrorCheck(it->status().ok())) |
| 495 return false; | 496 return false; |
| 496 | 497 |
| 497 // Skip the dummy entry "namespace-<namespaceid>-" and iterate the origins. | 498 // Skip the dummy entry "namespace-<namespaceid>-" and iterate the origins. |
| 498 for (it->Next(); it->Valid(); it->Next()) { | 499 for (it->Next(); it->Valid(); it->Next()) { |
| 499 std::string key = it->key().ToString(); | 500 std::string key = it->key().ToString(); |
| 500 if (key.find(namespace_start_key) != 0) { | 501 if (!base::StartsWith(key, namespace_start_key, |
| 502 base::CompareCase::SENSITIVE)) { |
| 501 // Iterated past the origins for this namespace. | 503 // Iterated past the origins for this namespace. |
| 502 break; | 504 break; |
| 503 } | 505 } |
| 504 std::string origin = key.substr(namespace_start_key.length()); | 506 std::string origin = key.substr(namespace_start_key.length()); |
| 505 std::string map_id = it->value().ToString(); | 507 std::string map_id = it->value().ToString(); |
| 506 (*areas)[origin] = map_id; | 508 (*areas)[origin] = map_id; |
| 507 } | 509 } |
| 508 return true; | 510 return true; |
| 509 } | 511 } |
| 510 | 512 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 return false; | 544 return false; |
| 543 // Advance the iterator 2 times (we still haven't really deleted | 545 // Advance the iterator 2 times (we still haven't really deleted |
| 544 // namespace_key). | 546 // namespace_key). |
| 545 it->Next(); | 547 it->Next(); |
| 546 if (!ConsistencyCheck(it->Valid())) | 548 if (!ConsistencyCheck(it->Valid())) |
| 547 return false; | 549 return false; |
| 548 it->Next(); | 550 it->Next(); |
| 549 if (!it->Valid()) | 551 if (!it->Valid()) |
| 550 return true; | 552 return true; |
| 551 std::string key = it->key().ToString(); | 553 std::string key = it->key().ToString(); |
| 552 if (key.find(namespace_start_key) != 0) | 554 if (!base::StartsWith(key, namespace_start_key, base::CompareCase::SENSITIVE)) |
| 553 batch->Delete(namespace_start_key); | 555 batch->Delete(namespace_start_key); |
| 554 return true; | 556 return true; |
| 555 } | 557 } |
| 556 | 558 |
| 557 bool SessionStorageDatabase::GetMapForArea(const std::string& namespace_id, | 559 bool SessionStorageDatabase::GetMapForArea(const std::string& namespace_id, |
| 558 const std::string& origin, | 560 const std::string& origin, |
| 559 const leveldb::ReadOptions& options, | 561 const leveldb::ReadOptions& options, |
| 560 bool* exists, std::string* map_id) { | 562 bool* exists, std::string* map_id) { |
| 561 std::string namespace_key = NamespaceKey(namespace_id, origin); | 563 std::string namespace_key = NamespaceKey(namespace_id, origin); |
| 562 leveldb::Status s = db_->Get(options, namespace_key, map_id); | 564 leveldb::Status s = db_->Get(options, namespace_key, map_id); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 // If the key is not found, the status of the iterator won't be IsNotFound(), | 603 // If the key is not found, the status of the iterator won't be IsNotFound(), |
| 602 // but the iterator will be invalid. The map needs to exist, otherwise we have | 604 // but the iterator will be invalid. The map needs to exist, otherwise we have |
| 603 // a stale map_id in the database. | 605 // a stale map_id in the database. |
| 604 if (!ConsistencyCheck(it->Valid())) | 606 if (!ConsistencyCheck(it->Valid())) |
| 605 return false; | 607 return false; |
| 606 if (!DatabaseErrorCheck(it->status().ok())) | 608 if (!DatabaseErrorCheck(it->status().ok())) |
| 607 return false; | 609 return false; |
| 608 // Skip the dummy entry "map-<mapid>-". | 610 // Skip the dummy entry "map-<mapid>-". |
| 609 for (it->Next(); it->Valid(); it->Next()) { | 611 for (it->Next(); it->Valid(); it->Next()) { |
| 610 std::string key = it->key().ToString(); | 612 std::string key = it->key().ToString(); |
| 611 if (key.find(map_start_key) != 0) { | 613 if (!base::StartsWith(key, map_start_key, base::CompareCase::SENSITIVE)) { |
| 612 // Iterated past the keys in this map. | 614 // Iterated past the keys in this map. |
| 613 break; | 615 break; |
| 614 } | 616 } |
| 615 // Key is of the form "map-<mapid>-<key>". | 617 // Key is of the form "map-<mapid>-<key>". |
| 616 base::string16 key16 = | 618 base::string16 key16 = |
| 617 base::UTF8ToUTF16(key.substr(map_start_key.length())); | 619 base::UTF8ToUTF16(key.substr(map_start_key.length())); |
| 618 if (only_keys) { | 620 if (only_keys) { |
| 619 (*result)[key16] = base::NullableString16(); | 621 (*result)[key16] = base::NullableString16(); |
| 620 } else { | 622 } else { |
| 621 // Convert the raw data stored in std::string (it->value()) to raw data | 623 // Convert the raw data stored in std::string (it->value()) to raw data |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 764 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
| 763 const std::string& key) { | 765 const std::string& key) { |
| 764 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 766 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
| 765 } | 767 } |
| 766 | 768 |
| 767 const char* SessionStorageDatabase::NextMapIdKey() { | 769 const char* SessionStorageDatabase::NextMapIdKey() { |
| 768 return "next-map-id"; | 770 return "next-map-id"; |
| 769 } | 771 } |
| 770 | 772 |
| 771 } // namespace content | 773 } // namespace content |
| OLD | NEW |