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

Side by Side Diff: content/browser/indexed_db/indexed_db_leveldb_coding.cc

Issue 264483002: This is the implementation of the primary and secondary blob journals for (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Export kAllBlobsKey Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/indexed_db/indexed_db_leveldb_coding.h" 5 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 size_t count = array.size(); 368 size_t count = array.size();
369 EncodeVarInt(count, into); 369 EncodeVarInt(count, into);
370 for (size_t i = 0; i < count; ++i) { 370 for (size_t i = 0; i < count; ++i) {
371 EncodeStringWithLength(array[i], into); 371 EncodeStringWithLength(array[i], into);
372 } 372 }
373 break; 373 break;
374 } 374 }
375 } 375 }
376 } 376 }
377 377
378 void EncodeBlobJournal(const BlobJournalType& journal, std::string* into) {
379 BlobJournalType::const_iterator iter;
380 for (iter = journal.begin(); iter != journal.end(); ++iter) {
381 EncodeVarInt(iter->first, into);
382 EncodeVarInt(iter->second, into);
383 }
384 }
385
378 bool DecodeByte(StringPiece* slice, unsigned char* value) { 386 bool DecodeByte(StringPiece* slice, unsigned char* value) {
379 if (slice->empty()) 387 if (slice->empty())
380 return false; 388 return false;
381 389
382 *value = (*slice)[0]; 390 *value = (*slice)[0];
383 slice->remove_prefix(1); 391 slice->remove_prefix(1);
384 return true; 392 return true;
385 } 393 }
386 394
387 bool DecodeBool(StringPiece* slice, bool* value) { 395 bool DecodeBool(StringPiece* slice, bool* value) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 608 }
601 DCHECK(slice->empty()); 609 DCHECK(slice->empty());
602 *value = IndexedDBKeyPath(array); 610 *value = IndexedDBKeyPath(array);
603 return true; 611 return true;
604 } 612 }
605 } 613 }
606 NOTREACHED(); 614 NOTREACHED();
607 return false; 615 return false;
608 } 616 }
609 617
618 bool DecodeBlobJournal(StringPiece* slice, BlobJournalType* journal) {
619 BlobJournalType output;
620 while (!slice->empty()) {
621 int64 database_id = -1;
622 int64 blob_key = -1;
623 if (!DecodeVarInt(slice, &database_id))
624 return false;
625 if (!KeyPrefix::IsValidDatabaseId(database_id))
626 return false;
627 if (!DecodeVarInt(slice, &blob_key))
628 return false;
629 if (!DatabaseMetaDataKey::IsValidBlobKey(blob_key) &&
630 (blob_key != DatabaseMetaDataKey::kAllBlobsKey)) {
631 return false;
632 }
633 output.push_back(std::make_pair(database_id, blob_key));
634 }
635 journal->swap(output);
636 return true;
637 }
638
610 bool ConsumeEncodedIDBKey(StringPiece* slice) { 639 bool ConsumeEncodedIDBKey(StringPiece* slice) {
611 unsigned char type = (*slice)[0]; 640 unsigned char type = (*slice)[0];
612 slice->remove_prefix(1); 641 slice->remove_prefix(1);
613 642
614 switch (type) { 643 switch (type) {
615 case kIndexedDBKeyNullTypeByte: 644 case kIndexedDBKeyNullTypeByte:
616 case kIndexedDBKeyMinKeyTypeByte: 645 case kIndexedDBKeyMinKeyTypeByte:
617 return true; 646 return true;
618 case kIndexedDBKeyArrayTypeByte: { 647 case kIndexedDBKeyArrayTypeByte: {
619 int64 length; 648 int64 length;
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { 2029 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const {
2001 scoped_ptr<IndexedDBKey> key; 2030 scoped_ptr<IndexedDBKey> key;
2002 StringPiece slice(encoded_primary_key_); 2031 StringPiece slice(encoded_primary_key_);
2003 if (!DecodeIDBKey(&slice, &key)) { 2032 if (!DecodeIDBKey(&slice, &key)) {
2004 // TODO(jsbell): Return error. 2033 // TODO(jsbell): Return error.
2005 } 2034 }
2006 return key.Pass(); 2035 return key.Pass();
2007 } 2036 }
2008 2037
2009 } // namespace content 2038 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698