OLD | NEW |
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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 static bool Decode(base::StringPiece* slice, KeyPrefix* result); | 89 static bool Decode(base::StringPiece* slice, KeyPrefix* result); |
90 std::string Encode() const; | 90 std::string Encode() const; |
91 static std::string EncodeEmpty(); | 91 static std::string EncodeEmpty(); |
92 int Compare(const KeyPrefix& other) const; | 92 int Compare(const KeyPrefix& other) const; |
93 | 93 |
94 enum Type { | 94 enum Type { |
95 GLOBAL_METADATA, | 95 GLOBAL_METADATA, |
96 DATABASE_METADATA, | 96 DATABASE_METADATA, |
97 OBJECT_STORE_DATA, | 97 OBJECT_STORE_DATA, |
98 EXISTS_ENTRY, | 98 EXISTS_ENTRY, |
| 99 BLOB_ENTRY, |
99 INDEX_DATA, | 100 INDEX_DATA, |
100 INVALID_TYPE | 101 INVALID_TYPE |
101 }; | 102 }; |
102 | 103 |
103 static const size_t kMaxDatabaseIdSizeBits = 3; | 104 static const size_t kMaxDatabaseIdSizeBits = 3; |
104 static const size_t kMaxObjectStoreIdSizeBits = 3; | 105 static const size_t kMaxObjectStoreIdSizeBits = 3; |
105 static const size_t kMaxIndexIdSizeBits = 2; | 106 static const size_t kMaxIndexIdSizeBits = 2; |
106 | 107 |
107 static const size_t kMaxDatabaseIdSizeBytes = | 108 static const size_t kMaxDatabaseIdSizeBytes = |
108 1ULL << kMaxDatabaseIdSizeBits; // 8 | 109 1ULL << kMaxDatabaseIdSizeBits; // 8 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 class MaxDatabaseIdKey { | 165 class MaxDatabaseIdKey { |
165 public: | 166 public: |
166 CONTENT_EXPORT static std::string Encode(); | 167 CONTENT_EXPORT static std::string Encode(); |
167 }; | 168 }; |
168 | 169 |
169 class DataVersionKey { | 170 class DataVersionKey { |
170 public: | 171 public: |
171 static std::string Encode(); | 172 static std::string Encode(); |
172 }; | 173 }; |
173 | 174 |
| 175 class BlobJournalKey { |
| 176 public: |
| 177 static std::string Encode(); |
| 178 }; |
| 179 |
| 180 class LiveBlobJournalKey { |
| 181 public: |
| 182 static std::string Encode(); |
| 183 }; |
| 184 |
174 class DatabaseFreeListKey { | 185 class DatabaseFreeListKey { |
175 public: | 186 public: |
176 DatabaseFreeListKey(); | 187 DatabaseFreeListKey(); |
177 static bool Decode(base::StringPiece* slice, DatabaseFreeListKey* result); | 188 static bool Decode(base::StringPiece* slice, DatabaseFreeListKey* result); |
178 CONTENT_EXPORT static std::string Encode(int64 database_id); | 189 CONTENT_EXPORT static std::string Encode(int64 database_id); |
179 static CONTENT_EXPORT std::string EncodeMaxKey(); | 190 static CONTENT_EXPORT std::string EncodeMaxKey(); |
180 int64 DatabaseId() const; | 191 int64 DatabaseId() const; |
181 int Compare(const DatabaseFreeListKey& other) const; | 192 int Compare(const DatabaseFreeListKey& other) const; |
182 | 193 |
183 private: | 194 private: |
(...skipping 19 matching lines...) Expand all Loading... |
203 }; | 214 }; |
204 | 215 |
205 class DatabaseMetaDataKey { | 216 class DatabaseMetaDataKey { |
206 public: | 217 public: |
207 enum MetaDataType { | 218 enum MetaDataType { |
208 ORIGIN_NAME = 0, | 219 ORIGIN_NAME = 0, |
209 DATABASE_NAME = 1, | 220 DATABASE_NAME = 1, |
210 USER_VERSION = 2, | 221 USER_VERSION = 2, |
211 MAX_OBJECT_STORE_ID = 3, | 222 MAX_OBJECT_STORE_ID = 3, |
212 USER_INT_VERSION = 4, | 223 USER_INT_VERSION = 4, |
213 MAX_SIMPLE_METADATA_TYPE = 5 | 224 BLOB_KEY_GENERATOR_CURRENT_NUMBER = 5, |
| 225 MAX_SIMPLE_METADATA_TYPE = 6 |
214 }; | 226 }; |
215 | 227 |
| 228 static const int64 kAllBlobsKey = 1; |
| 229 static const int64 kBlobKeyGeneratorInitialNumber = 2; |
| 230 static const int64 kInvalidBlobKey = -1; // All keys <= 0 are invalid. |
| 231 |
| 232 static bool IsValidBlobKey(int64 blobKey); |
216 CONTENT_EXPORT static std::string Encode(int64 database_id, | 233 CONTENT_EXPORT static std::string Encode(int64 database_id, |
217 MetaDataType type); | 234 MetaDataType type); |
218 }; | 235 }; |
219 | 236 |
220 class ObjectStoreMetaDataKey { | 237 class ObjectStoreMetaDataKey { |
221 public: | 238 public: |
222 enum MetaDataType { | 239 enum MetaDataType { |
223 NAME = 0, | 240 NAME = 0, |
224 KEY_PATH = 1, | 241 KEY_PATH = 1, |
225 AUTO_INCREMENT = 2, | 242 AUTO_INCREMENT = 2, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 int Compare(const ExistsEntryKey& other, bool* ok); | 393 int Compare(const ExistsEntryKey& other, bool* ok); |
377 scoped_ptr<IndexedDBKey> user_key() const; | 394 scoped_ptr<IndexedDBKey> user_key() const; |
378 | 395 |
379 static const int64 kSpecialIndexNumber; | 396 static const int64 kSpecialIndexNumber; |
380 | 397 |
381 private: | 398 private: |
382 std::string encoded_user_key_; | 399 std::string encoded_user_key_; |
383 DISALLOW_COPY_AND_ASSIGN(ExistsEntryKey); | 400 DISALLOW_COPY_AND_ASSIGN(ExistsEntryKey); |
384 }; | 401 }; |
385 | 402 |
| 403 class BlobEntryKey { |
| 404 public: |
| 405 BlobEntryKey() |
| 406 : database_id_(0), |
| 407 object_store_id_(0) |
| 408 { |
| 409 } |
| 410 static bool Decode(base::StringPiece* slice, BlobEntryKey* result); |
| 411 static bool FromObjectStoreDataKey(base::StringPiece* slice, |
| 412 BlobEntryKey* result); |
| 413 static std::string ReencodeToObjectStoreDataKey(base::StringPiece* slice); |
| 414 static std::string EncodeMinForObjectStore(int64 database_id, |
| 415 int64 object_store_id); |
| 416 static std::string EncodeMaxForObjectStore(int64 database_id, |
| 417 int64 object_store_id); |
| 418 static std::string Encode(int64 database_id, |
| 419 int64 object_store_id, |
| 420 const IndexedDBKey& user_key); |
| 421 std::string Encode() const; |
| 422 int64 database_id() const { return database_id_; } |
| 423 int64 object_store_id() const { return object_store_id_; } |
| 424 int Compare(const BlobEntryKey& other, bool* ok); |
| 425 |
| 426 static const int64 kSpecialIndexNumber; |
| 427 |
| 428 private: |
| 429 static std::string Encode(int64 database_id, |
| 430 int64 object_store_id, |
| 431 const std::string& encoded_user_key); |
| 432 int64 database_id_; |
| 433 int64 object_store_id_; |
| 434 // This is the user's ObjectStoreDataKey, not the BlobEntryKey itself. |
| 435 std::string encoded_user_key_; |
| 436 }; |
| 437 |
386 class IndexDataKey { | 438 class IndexDataKey { |
387 public: | 439 public: |
388 IndexDataKey(); | 440 IndexDataKey(); |
389 ~IndexDataKey(); | 441 ~IndexDataKey(); |
390 static bool Decode(base::StringPiece* slice, IndexDataKey* result); | 442 static bool Decode(base::StringPiece* slice, IndexDataKey* result); |
391 CONTENT_EXPORT static std::string Encode( | 443 CONTENT_EXPORT static std::string Encode( |
392 int64 database_id, | 444 int64 database_id, |
393 int64 object_store_id, | 445 int64 object_store_id, |
394 int64 index_id, | 446 int64 index_id, |
395 const std::string& encoded_user_key, | 447 const std::string& encoded_user_key, |
(...skipping 30 matching lines...) Expand all Loading... |
426 std::string encoded_user_key_; | 478 std::string encoded_user_key_; |
427 std::string encoded_primary_key_; | 479 std::string encoded_primary_key_; |
428 int64 sequence_number_; | 480 int64 sequence_number_; |
429 | 481 |
430 DISALLOW_COPY_AND_ASSIGN(IndexDataKey); | 482 DISALLOW_COPY_AND_ASSIGN(IndexDataKey); |
431 }; | 483 }; |
432 | 484 |
433 } // namespace content | 485 } // namespace content |
434 | 486 |
435 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ | 487 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ |
OLD | NEW |