Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(998)

Side by Side Diff: content/browser/dom_storage/session_storage_database.cc

Issue 2137503002: Revert of Replace string::find(prefix) == 0 pattern with base::StartsWith(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 (!base::StartsWith(key, namespace_prefix, 301 if (key.find(namespace_prefix) != 0) {
302 base::CompareCase::SENSITIVE)) {
303 // Iterated past the "namespace-" keys. 302 // Iterated past the "namespace-" keys.
304 break; 303 break;
305 } 304 }
306 // For each namespace, the first key is "namespace-<namespaceid>-", and the 305 // For each namespace, the first key is "namespace-<namespaceid>-", and the
307 // subsequent keys are "namespace-<namespaceid>-<origin>". Read the unique 306 // subsequent keys are "namespace-<namespaceid>-<origin>". Read the unique
308 // "<namespaceid>" parts from the keys. 307 // "<namespaceid>" parts from the keys.
309 if (current_namespace_start_key.empty() || 308 if (current_namespace_start_key.empty() ||
310 key.substr(0, current_namespace_start_key.length()) != 309 key.substr(0, current_namespace_start_key.length()) !=
311 current_namespace_start_key) { 310 current_namespace_start_key) {
312 // The key is of the form "namespace-<namespaceid>-" for a new 311 // The key is of the form "namespace-<namespaceid>-" for a new
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 // The namespace_start_key is not found when the namespace doesn't contain 490 // The namespace_start_key is not found when the namespace doesn't contain
492 // any areas. We don't need to do anything. 491 // any areas. We don't need to do anything.
493 return true; 492 return true;
494 } 493 }
495 if (!DatabaseErrorCheck(it->status().ok())) 494 if (!DatabaseErrorCheck(it->status().ok()))
496 return false; 495 return false;
497 496
498 // Skip the dummy entry "namespace-<namespaceid>-" and iterate the origins. 497 // Skip the dummy entry "namespace-<namespaceid>-" and iterate the origins.
499 for (it->Next(); it->Valid(); it->Next()) { 498 for (it->Next(); it->Valid(); it->Next()) {
500 std::string key = it->key().ToString(); 499 std::string key = it->key().ToString();
501 if (!base::StartsWith(key, namespace_start_key, 500 if (key.find(namespace_start_key) != 0) {
502 base::CompareCase::SENSITIVE)) {
503 // Iterated past the origins for this namespace. 501 // Iterated past the origins for this namespace.
504 break; 502 break;
505 } 503 }
506 std::string origin = key.substr(namespace_start_key.length()); 504 std::string origin = key.substr(namespace_start_key.length());
507 std::string map_id = it->value().ToString(); 505 std::string map_id = it->value().ToString();
508 (*areas)[origin] = map_id; 506 (*areas)[origin] = map_id;
509 } 507 }
510 return true; 508 return true;
511 } 509 }
512 510
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 return false; 542 return false;
545 // Advance the iterator 2 times (we still haven't really deleted 543 // Advance the iterator 2 times (we still haven't really deleted
546 // namespace_key). 544 // namespace_key).
547 it->Next(); 545 it->Next();
548 if (!ConsistencyCheck(it->Valid())) 546 if (!ConsistencyCheck(it->Valid()))
549 return false; 547 return false;
550 it->Next(); 548 it->Next();
551 if (!it->Valid()) 549 if (!it->Valid())
552 return true; 550 return true;
553 std::string key = it->key().ToString(); 551 std::string key = it->key().ToString();
554 if (!base::StartsWith(key, namespace_start_key, base::CompareCase::SENSITIVE)) 552 if (key.find(namespace_start_key) != 0)
555 batch->Delete(namespace_start_key); 553 batch->Delete(namespace_start_key);
556 return true; 554 return true;
557 } 555 }
558 556
559 bool SessionStorageDatabase::GetMapForArea(const std::string& namespace_id, 557 bool SessionStorageDatabase::GetMapForArea(const std::string& namespace_id,
560 const std::string& origin, 558 const std::string& origin,
561 const leveldb::ReadOptions& options, 559 const leveldb::ReadOptions& options,
562 bool* exists, std::string* map_id) { 560 bool* exists, std::string* map_id) {
563 std::string namespace_key = NamespaceKey(namespace_id, origin); 561 std::string namespace_key = NamespaceKey(namespace_id, origin);
564 leveldb::Status s = db_->Get(options, namespace_key, map_id); 562 leveldb::Status s = db_->Get(options, namespace_key, map_id);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 // If the key is not found, the status of the iterator won't be IsNotFound(), 601 // If the key is not found, the status of the iterator won't be IsNotFound(),
604 // but the iterator will be invalid. The map needs to exist, otherwise we have 602 // but the iterator will be invalid. The map needs to exist, otherwise we have
605 // a stale map_id in the database. 603 // a stale map_id in the database.
606 if (!ConsistencyCheck(it->Valid())) 604 if (!ConsistencyCheck(it->Valid()))
607 return false; 605 return false;
608 if (!DatabaseErrorCheck(it->status().ok())) 606 if (!DatabaseErrorCheck(it->status().ok()))
609 return false; 607 return false;
610 // Skip the dummy entry "map-<mapid>-". 608 // Skip the dummy entry "map-<mapid>-".
611 for (it->Next(); it->Valid(); it->Next()) { 609 for (it->Next(); it->Valid(); it->Next()) {
612 std::string key = it->key().ToString(); 610 std::string key = it->key().ToString();
613 if (!base::StartsWith(key, map_start_key, base::CompareCase::SENSITIVE)) { 611 if (key.find(map_start_key) != 0) {
614 // Iterated past the keys in this map. 612 // Iterated past the keys in this map.
615 break; 613 break;
616 } 614 }
617 // Key is of the form "map-<mapid>-<key>". 615 // Key is of the form "map-<mapid>-<key>".
618 base::string16 key16 = 616 base::string16 key16 =
619 base::UTF8ToUTF16(key.substr(map_start_key.length())); 617 base::UTF8ToUTF16(key.substr(map_start_key.length()));
620 if (only_keys) { 618 if (only_keys) {
621 (*result)[key16] = base::NullableString16(); 619 (*result)[key16] = base::NullableString16();
622 } else { 620 } else {
623 // Convert the raw data stored in std::string (it->value()) to raw data 621 // 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
764 std::string SessionStorageDatabase::MapKey(const std::string& map_id, 762 std::string SessionStorageDatabase::MapKey(const std::string& map_id,
765 const std::string& key) { 763 const std::string& key) {
766 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); 764 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str());
767 } 765 }
768 766
769 const char* SessionStorageDatabase::NextMapIdKey() { 767 const char* SessionStorageDatabase::NextMapIdKey() {
770 return "next-map-id"; 768 return "next-map-id";
771 } 769 }
772 770
773 } // namespace content 771 } // namespace content
OLDNEW
« no previous file with comments | « components/sync_sessions/favicon_cache_unittest.cc ('k') | content/browser/dom_storage/session_storage_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698