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

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

Issue 16256014: IndexedDB: Convert decoding functions to pass StringPieces vs. pointers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Correct bogus iterator dereference in unit test Created 7 years, 6 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 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/strings/string_piece.h"
15 #include "content/common/indexed_db/indexed_db_key.h" 16 #include "content/common/indexed_db/indexed_db_key.h"
16 #include "content/common/indexed_db/indexed_db_key_path.h" 17 #include "content/common/indexed_db/indexed_db_key_path.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 class LevelDBSlice; 21 class LevelDBSlice;
21 22
22 CONTENT_EXPORT extern const unsigned char kMinimumIndexId; 23 CONTENT_EXPORT extern const unsigned char kMinimumIndexId;
23 24
24 CONTENT_EXPORT void EncodeByte(unsigned char, std::vector<char>*);
25 CONTENT_EXPORT const char* DecodeByte(const char* p,
26 const char* limit,
27 unsigned char& found_char);
28 CONTENT_EXPORT std::vector<char> MaxIDBKey(); 25 CONTENT_EXPORT std::vector<char> MaxIDBKey();
29 CONTENT_EXPORT std::vector<char> MinIDBKey(); 26 CONTENT_EXPORT std::vector<char> MinIDBKey();
30 CONTENT_EXPORT void EncodeBool(bool, std::vector<char>*);
31 CONTENT_EXPORT bool DecodeBool(const char* begin, const char* end);
32 CONTENT_EXPORT void EncodeInt(int64, std::vector<char>*);
33 inline void EncodeIntSafely(int64 nParam,
34 int64 max,
35 std::vector<char>* into) {
36 DCHECK_LE(nParam, max);
37 return EncodeInt(nParam, into);
38 }
39 27
40 template <class T> 28 CONTENT_EXPORT void EncodeByte(unsigned char value, std::vector<char>* into);
41 int64 DecodeInt(T begin, T end) { 29 CONTENT_EXPORT void EncodeBool(bool value, std::vector<char>* into);
42 // TODO(alecflett): Make this a DCHECK_LE(). 30 CONTENT_EXPORT void EncodeInt(int64 value, std::vector<char>* into);
43 DCHECK(begin <= end); 31 CONTENT_EXPORT void EncodeVarInt(int64 value, std::vector<char>* into);
44 int64 ret = 0; 32 CONTENT_EXPORT void EncodeString(const string16& value,
33 std::vector<char>* into);
34 CONTENT_EXPORT void EncodeStringWithLength(const string16& value,
35 std::vector<char>* into);
36 CONTENT_EXPORT void EncodeDouble(double value, std::vector<char>* into);
37 CONTENT_EXPORT void EncodeIDBKey(const IndexedDBKey& value,
38 std::vector<char>* into);
39 CONTENT_EXPORT void EncodeIDBKeyPath(const IndexedDBKeyPath& value,
40 std::vector<char>* into);
45 41
46 int shift = 0; 42 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeByte(base::StringPiece* slice,
47 while (begin < end) { 43 unsigned char* value);
48 unsigned char c = *begin++; 44 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeBool(base::StringPiece* slice,
49 ret |= static_cast<int64>(c) << shift; 45 bool* value);
50 shift += 8; 46 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeInt(base::StringPiece* slice,
51 } 47 int64* value);
48 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeVarInt(base::StringPiece* slice,
49 int64* value);
50 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeString(base::StringPiece* slice,
51 string16* value);
52 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeStringWithLength(
53 base::StringPiece* slice,
54 string16* value);
55 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeDouble(base::StringPiece* slice,
56 double* value);
57 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeIDBKey(
58 base::StringPiece* slice,
59 scoped_ptr<IndexedDBKey>* value);
60 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeIDBKeyPath(
61 base::StringPiece* slice,
62 IndexedDBKeyPath* value);
52 63
53 return ret; 64 CONTENT_EXPORT int CompareEncodedStringsWithLength(base::StringPiece* slice1,
54 } 65 base::StringPiece* slice2,
66 bool& ok);
55 67
56 CONTENT_EXPORT void EncodeVarInt(int64, std::vector<char>*); 68 CONTENT_EXPORT WARN_UNUSED_RESULT bool ExtractEncodedIDBKey(
57 CONTENT_EXPORT const char* DecodeVarInt(const char* p, 69 base::StringPiece* slice,
58 const char* limit, 70 std::vector<char>* result);
59 int64& found_int); 71
60 CONTENT_EXPORT void EncodeString(const string16&, std::vector<char>*);
61 CONTENT_EXPORT string16 DecodeString(const char* p, const char* end);
62 CONTENT_EXPORT void EncodeStringWithLength(const string16&, std::vector<char>*);
63 CONTENT_EXPORT const char* DecodeStringWithLength(const char* p,
64 const char* limit,
65 string16& found_string);
66 CONTENT_EXPORT int CompareEncodedStringsWithLength(const char*& p,
67 const char* limit_p,
68 const char*& q,
69 const char* limit_q,
70 bool& ok);
71 CONTENT_EXPORT void EncodeDouble(double, std::vector<char>*);
72 CONTENT_EXPORT const char* DecodeDouble(const char* p,
73 const char* limit,
74 double*);
75 void EncodeIDBKey(const IndexedDBKey&, std::vector<char>*);
76 CONTENT_EXPORT std::vector<char> EncodeIDBKey(const IndexedDBKey&);
77 CONTENT_EXPORT const char* DecodeIDBKey(const char* p,
78 const char* limit,
79 scoped_ptr<IndexedDBKey>* found_key);
80 CONTENT_EXPORT const char* ExtractEncodedIDBKey(const char* start,
81 const char* limit,
82 std::vector<char>* result);
83 CONTENT_EXPORT int CompareEncodedIDBKeys(const std::vector<char>& a, 72 CONTENT_EXPORT int CompareEncodedIDBKeys(const std::vector<char>& a,
84 const std::vector<char>& b, 73 const std::vector<char>& b,
85 bool& ok); 74 bool& ok);
86 CONTENT_EXPORT void EncodeIDBKeyPath(const IndexedDBKeyPath&,
87 std::vector<char>*);
88 CONTENT_EXPORT IndexedDBKeyPath DecodeIDBKeyPath(const char*, const char*);
89 75
90 CONTENT_EXPORT int Compare(const LevelDBSlice& a, 76 CONTENT_EXPORT int Compare(const LevelDBSlice& a,
91 const LevelDBSlice& b, 77 const LevelDBSlice& b,
92 bool index_keys = false); 78 bool index_keys = false);
93 79
94 class KeyPrefix { 80 class KeyPrefix {
95 public: 81 public:
96 KeyPrefix(); 82 KeyPrefix();
97 explicit KeyPrefix(int64 database_id); 83 explicit KeyPrefix(int64 database_id);
98 KeyPrefix(int64 database_id, int64 object_store_id); 84 KeyPrefix(int64 database_id, int64 object_store_id);
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 std::vector<char> encoded_user_key_; 446 std::vector<char> encoded_user_key_;
461 std::vector<char> encoded_primary_key_; 447 std::vector<char> encoded_primary_key_;
462 int64 sequence_number_; 448 int64 sequence_number_;
463 449
464 DISALLOW_COPY_AND_ASSIGN(IndexDataKey); 450 DISALLOW_COPY_AND_ASSIGN(IndexDataKey);
465 }; 451 };
466 452
467 } // namespace content 453 } // namespace content
468 454
469 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ 455 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698