| 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_BACKING_STORE_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 class IndexedDBFactory; | 50 class IndexedDBFactory; |
| 51 class LevelDBComparator; | 51 class LevelDBComparator; |
| 52 class LevelDBDatabase; | 52 class LevelDBDatabase; |
| 53 class LevelDBFactory; | 53 class LevelDBFactory; |
| 54 struct IndexedDBValue; | 54 struct IndexedDBValue; |
| 55 | 55 |
| 56 class CONTENT_EXPORT IndexedDBBackingStore | 56 class CONTENT_EXPORT IndexedDBBackingStore |
| 57 : public base::RefCounted<IndexedDBBackingStore> { | 57 : public base::RefCounted<IndexedDBBackingStore> { |
| 58 public: | 58 public: |
| 59 class CONTENT_EXPORT Transaction; | |
| 60 | |
| 61 class CONTENT_EXPORT Comparator : public LevelDBComparator { | 59 class CONTENT_EXPORT Comparator : public LevelDBComparator { |
| 62 public: | 60 public: |
| 63 virtual int Compare(const base::StringPiece& a, | 61 virtual int Compare(const base::StringPiece& a, |
| 64 const base::StringPiece& b) const OVERRIDE; | 62 const base::StringPiece& b) const OVERRIDE; |
| 65 virtual const char* Name() const OVERRIDE; | 63 virtual const char* Name() const OVERRIDE; |
| 66 }; | 64 }; |
| 67 | 65 |
| 66 class CONTENT_EXPORT RecordIdentifier { |
| 67 public: |
| 68 RecordIdentifier(const std::string& primary_key, int64 version); |
| 69 RecordIdentifier(); |
| 70 ~RecordIdentifier(); |
| 71 |
| 72 const std::string& primary_key() const { return primary_key_; } |
| 73 int64 version() const { return version_; } |
| 74 void Reset(const std::string& primary_key, int64 version) { |
| 75 primary_key_ = primary_key; |
| 76 version_ = version; |
| 77 } |
| 78 |
| 79 private: |
| 80 // TODO(jsbell): Make it more clear that this is the *encoded* version of |
| 81 // the key. |
| 82 std::string primary_key_; |
| 83 int64 version_; |
| 84 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); |
| 85 }; |
| 86 |
| 87 class BlobWriteCallback : public base::RefCounted<BlobWriteCallback> { |
| 88 public: |
| 89 virtual void Run(bool succeeded) = 0; |
| 90 |
| 91 protected: |
| 92 friend class base::RefCounted<BlobWriteCallback>; |
| 93 virtual ~BlobWriteCallback() {} |
| 94 }; |
| 95 |
| 96 class BlobChangeRecord { |
| 97 public: |
| 98 BlobChangeRecord(const std::string& key, int64 object_store_id); |
| 99 ~BlobChangeRecord(); |
| 100 |
| 101 const std::string& key() const { return key_; } |
| 102 int64 object_store_id() const { return object_store_id_; } |
| 103 void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info); |
| 104 std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; } |
| 105 const std::vector<IndexedDBBlobInfo>& blob_info() const { |
| 106 return blob_info_; |
| 107 } |
| 108 void SetHandles(ScopedVector<webkit_blob::BlobDataHandle>* handles); |
| 109 scoped_ptr<BlobChangeRecord> Clone() const; |
| 110 |
| 111 private: |
| 112 std::string key_; |
| 113 int64 object_store_id_; |
| 114 std::vector<IndexedDBBlobInfo> blob_info_; |
| 115 ScopedVector<webkit_blob::BlobDataHandle> handles_; |
| 116 DISALLOW_COPY_AND_ASSIGN(BlobChangeRecord); |
| 117 }; |
| 118 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap; |
| 119 |
| 120 class CONTENT_EXPORT Transaction { |
| 121 public: |
| 122 explicit Transaction(IndexedDBBackingStore* backing_store); |
| 123 virtual ~Transaction(); |
| 124 |
| 125 virtual void Begin(); |
| 126 // The callback will be called eventually on success or failure, or |
| 127 // immediately if phase one is complete due to lack of any blobs to write. |
| 128 virtual leveldb::Status CommitPhaseOne(scoped_refptr<BlobWriteCallback>); |
| 129 virtual leveldb::Status CommitPhaseTwo(); |
| 130 virtual void Rollback(); |
| 131 void Reset() { |
| 132 backing_store_ = NULL; |
| 133 transaction_ = NULL; |
| 134 } |
| 135 leveldb::Status PutBlobInfoIfNeeded( |
| 136 int64 database_id, |
| 137 int64 object_store_id, |
| 138 const std::string& object_store_data_key, |
| 139 std::vector<IndexedDBBlobInfo>*, |
| 140 ScopedVector<webkit_blob::BlobDataHandle>* handles); |
| 141 void PutBlobInfo(int64 database_id, |
| 142 int64 object_store_id, |
| 143 const std::string& object_store_data_key, |
| 144 std::vector<IndexedDBBlobInfo>*, |
| 145 ScopedVector<webkit_blob::BlobDataHandle>* handles); |
| 146 |
| 147 LevelDBTransaction* transaction() { return transaction_; } |
| 148 |
| 149 leveldb::Status GetBlobInfoForRecord( |
| 150 int64 database_id, |
| 151 const std::string& object_store_data_key, |
| 152 IndexedDBValue* value); |
| 153 |
| 154 // This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored |
| 155 // under that key. |
| 156 typedef std::vector<std::pair<BlobEntryKey, std::string> > |
| 157 BlobEntryKeyValuePairVec; |
| 158 |
| 159 class WriteDescriptor { |
| 160 public: |
| 161 WriteDescriptor(const GURL& url, int64_t key, int64_t size); |
| 162 WriteDescriptor(const base::FilePath& path, |
| 163 int64_t key, |
| 164 int64_t size, |
| 165 base::Time last_modified); |
| 166 |
| 167 bool is_file() const { return is_file_; } |
| 168 const GURL& url() const { |
| 169 DCHECK(!is_file_); |
| 170 return url_; |
| 171 } |
| 172 const base::FilePath& file_path() const { |
| 173 DCHECK(is_file_); |
| 174 return file_path_; |
| 175 } |
| 176 int64_t key() const { return key_; } |
| 177 int64_t size() const { return size_; } |
| 178 base::Time last_modified() const { return last_modified_; } |
| 179 |
| 180 private: |
| 181 bool is_file_; |
| 182 GURL url_; |
| 183 base::FilePath file_path_; |
| 184 int64_t key_; |
| 185 int64_t size_; |
| 186 base::Time last_modified_; |
| 187 }; |
| 188 |
| 189 class ChainedBlobWriter |
| 190 : public base::RefCountedThreadSafe<ChainedBlobWriter> { |
| 191 public: |
| 192 virtual void set_delegate( |
| 193 scoped_ptr<fileapi::FileWriterDelegate> delegate) = 0; |
| 194 |
| 195 // TODO(ericu): Add a reason in the event of failure. |
| 196 virtual void ReportWriteCompletion(bool succeeded, |
| 197 int64 bytes_written) = 0; |
| 198 |
| 199 virtual void Abort() = 0; |
| 200 |
| 201 protected: |
| 202 friend class base::RefCountedThreadSafe<ChainedBlobWriter>; |
| 203 virtual ~ChainedBlobWriter() {} |
| 204 }; |
| 205 |
| 206 class ChainedBlobWriterImpl; |
| 207 |
| 208 typedef std::vector<WriteDescriptor> WriteDescriptorVec; |
| 209 |
| 210 private: |
| 211 class BlobWriteCallbackWrapper; |
| 212 |
| 213 leveldb::Status HandleBlobPreTransaction( |
| 214 BlobEntryKeyValuePairVec* new_blob_entries, |
| 215 WriteDescriptorVec* new_files_to_write); |
| 216 // Returns true on success, false on failure. |
| 217 bool CollectBlobFilesToRemove(); |
| 218 // The callback will be called eventually on success or failure. |
| 219 void WriteNewBlobs(BlobEntryKeyValuePairVec* new_blob_entries, |
| 220 WriteDescriptorVec* new_files_to_write, |
| 221 scoped_refptr<BlobWriteCallback> callback); |
| 222 leveldb::Status SortBlobsToRemove(); |
| 223 |
| 224 IndexedDBBackingStore* backing_store_; |
| 225 scoped_refptr<LevelDBTransaction> transaction_; |
| 226 BlobChangeMap blob_change_map_; |
| 227 BlobChangeMap incognito_blob_map_; |
| 228 int64 database_id_; |
| 229 BlobJournalType blobs_to_remove_; |
| 230 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; |
| 231 }; |
| 232 |
| 233 class Cursor { |
| 234 public: |
| 235 enum IteratorState { READY = 0, SEEK }; |
| 236 |
| 237 virtual ~Cursor(); |
| 238 |
| 239 struct CursorOptions { |
| 240 CursorOptions(); |
| 241 ~CursorOptions(); |
| 242 int64 database_id; |
| 243 int64 object_store_id; |
| 244 int64 index_id; |
| 245 std::string low_key; |
| 246 bool low_open; |
| 247 std::string high_key; |
| 248 bool high_open; |
| 249 bool forward; |
| 250 bool unique; |
| 251 }; |
| 252 |
| 253 const IndexedDBKey& key() const { return *current_key_; } |
| 254 bool Continue(leveldb::Status* s) { return Continue(NULL, NULL, SEEK, s); } |
| 255 bool Continue(const IndexedDBKey* key, |
| 256 IteratorState state, |
| 257 leveldb::Status* s) { |
| 258 return Continue(key, NULL, state, s); |
| 259 } |
| 260 bool Continue(const IndexedDBKey* key, |
| 261 const IndexedDBKey* primary_key, |
| 262 IteratorState state, |
| 263 leveldb::Status*); |
| 264 bool Advance(uint32 count, leveldb::Status*); |
| 265 bool FirstSeek(leveldb::Status*); |
| 266 |
| 267 virtual Cursor* Clone() = 0; |
| 268 virtual const IndexedDBKey& primary_key() const; |
| 269 virtual IndexedDBValue* value() = 0; |
| 270 virtual const RecordIdentifier& record_identifier() const; |
| 271 virtual bool LoadCurrentRow() = 0; |
| 272 |
| 273 protected: |
| 274 Cursor(scoped_refptr<IndexedDBBackingStore> backing_store, |
| 275 Transaction* transaction, |
| 276 int64 database_id, |
| 277 const CursorOptions& cursor_options); |
| 278 explicit Cursor(const IndexedDBBackingStore::Cursor* other); |
| 279 |
| 280 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; |
| 281 virtual std::string EncodeKey(const IndexedDBKey& key, |
| 282 const IndexedDBKey& primary_key) = 0; |
| 283 |
| 284 bool IsPastBounds() const; |
| 285 bool HaveEnteredRange() const; |
| 286 |
| 287 IndexedDBBackingStore* backing_store_; |
| 288 Transaction* transaction_; |
| 289 int64 database_id_; |
| 290 const CursorOptions cursor_options_; |
| 291 scoped_ptr<LevelDBIterator> iterator_; |
| 292 scoped_ptr<IndexedDBKey> current_key_; |
| 293 IndexedDBBackingStore::RecordIdentifier record_identifier_; |
| 294 |
| 295 private: |
| 296 DISALLOW_COPY_AND_ASSIGN(Cursor); |
| 297 }; |
| 298 |
| 68 const GURL& origin_url() const { return origin_url_; } | 299 const GURL& origin_url() const { return origin_url_; } |
| 69 IndexedDBFactory* factory() const { return indexed_db_factory_; } | 300 IndexedDBFactory* factory() const { return indexed_db_factory_; } |
| 70 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } | 301 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } |
| 71 base::OneShotTimer<IndexedDBBackingStore>* close_timer() { | 302 base::OneShotTimer<IndexedDBBackingStore>* close_timer() { |
| 72 return &close_timer_; | 303 return &close_timer_; |
| 73 } | 304 } |
| 74 IndexedDBActiveBlobRegistry* active_blob_registry() { | 305 IndexedDBActiveBlobRegistry* active_blob_registry() { |
| 75 return &active_blob_registry_; | 306 return &active_blob_registry_; |
| 76 } | 307 } |
| 77 | 308 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 int64 database_id, | 373 int64 database_id, |
| 143 int64 object_store_id, | 374 int64 object_store_id, |
| 144 const base::string16& name, | 375 const base::string16& name, |
| 145 const IndexedDBKeyPath& key_path, | 376 const IndexedDBKeyPath& key_path, |
| 146 bool auto_increment); | 377 bool auto_increment); |
| 147 virtual leveldb::Status DeleteObjectStore( | 378 virtual leveldb::Status DeleteObjectStore( |
| 148 IndexedDBBackingStore::Transaction* transaction, | 379 IndexedDBBackingStore::Transaction* transaction, |
| 149 int64 database_id, | 380 int64 database_id, |
| 150 int64 object_store_id) WARN_UNUSED_RESULT; | 381 int64 object_store_id) WARN_UNUSED_RESULT; |
| 151 | 382 |
| 152 class CONTENT_EXPORT RecordIdentifier { | |
| 153 public: | |
| 154 RecordIdentifier(const std::string& primary_key, int64 version); | |
| 155 RecordIdentifier(); | |
| 156 ~RecordIdentifier(); | |
| 157 | |
| 158 const std::string& primary_key() const { return primary_key_; } | |
| 159 int64 version() const { return version_; } | |
| 160 void Reset(const std::string& primary_key, int64 version) { | |
| 161 primary_key_ = primary_key; | |
| 162 version_ = version; | |
| 163 } | |
| 164 | |
| 165 private: | |
| 166 // TODO(jsbell): Make it more clear that this is the *encoded* version of | |
| 167 // the key. | |
| 168 std::string primary_key_; | |
| 169 int64 version_; | |
| 170 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); | |
| 171 }; | |
| 172 | |
| 173 class BlobWriteCallback : public base::RefCounted<BlobWriteCallback> { | |
| 174 public: | |
| 175 virtual void Run(bool succeeded) = 0; | |
| 176 | |
| 177 protected: | |
| 178 friend class base::RefCounted<BlobWriteCallback>; | |
| 179 virtual ~BlobWriteCallback() {} | |
| 180 }; | |
| 181 | |
| 182 virtual leveldb::Status GetRecord( | 383 virtual leveldb::Status GetRecord( |
| 183 IndexedDBBackingStore::Transaction* transaction, | 384 IndexedDBBackingStore::Transaction* transaction, |
| 184 int64 database_id, | 385 int64 database_id, |
| 185 int64 object_store_id, | 386 int64 object_store_id, |
| 186 const IndexedDBKey& key, | 387 const IndexedDBKey& key, |
| 187 IndexedDBValue* record) WARN_UNUSED_RESULT; | 388 IndexedDBValue* record) WARN_UNUSED_RESULT; |
| 188 virtual leveldb::Status PutRecord( | 389 virtual leveldb::Status PutRecord( |
| 189 IndexedDBBackingStore::Transaction* transaction, | 390 IndexedDBBackingStore::Transaction* transaction, |
| 190 int64 database_id, | 391 int64 database_id, |
| 191 int64 object_store_id, | 392 int64 object_store_id, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 int64 index_id, | 462 int64 index_id, |
| 262 const IndexedDBKey& key, | 463 const IndexedDBKey& key, |
| 263 scoped_ptr<IndexedDBKey>* found_primary_key, | 464 scoped_ptr<IndexedDBKey>* found_primary_key, |
| 264 bool* exists) WARN_UNUSED_RESULT; | 465 bool* exists) WARN_UNUSED_RESULT; |
| 265 | 466 |
| 266 // Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef. | 467 // Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef. |
| 267 virtual void ReportBlobUnused(int64 database_id, int64 blob_key); | 468 virtual void ReportBlobUnused(int64 database_id, int64 blob_key); |
| 268 | 469 |
| 269 base::FilePath GetBlobFileName(int64 database_id, int64 key); | 470 base::FilePath GetBlobFileName(int64 database_id, int64 key); |
| 270 | 471 |
| 271 class Cursor { | |
| 272 public: | |
| 273 virtual ~Cursor(); | |
| 274 | |
| 275 enum IteratorState { | |
| 276 READY = 0, | |
| 277 SEEK | |
| 278 }; | |
| 279 | |
| 280 struct CursorOptions { | |
| 281 CursorOptions(); | |
| 282 ~CursorOptions(); | |
| 283 int64 database_id; | |
| 284 int64 object_store_id; | |
| 285 int64 index_id; | |
| 286 std::string low_key; | |
| 287 bool low_open; | |
| 288 std::string high_key; | |
| 289 bool high_open; | |
| 290 bool forward; | |
| 291 bool unique; | |
| 292 }; | |
| 293 | |
| 294 const IndexedDBKey& key() const { return *current_key_; } | |
| 295 bool Continue(leveldb::Status* s) { return Continue(NULL, NULL, SEEK, s); } | |
| 296 bool Continue(const IndexedDBKey* key, | |
| 297 IteratorState state, | |
| 298 leveldb::Status* s) { | |
| 299 return Continue(key, NULL, state, s); | |
| 300 } | |
| 301 bool Continue(const IndexedDBKey* key, | |
| 302 const IndexedDBKey* primary_key, | |
| 303 IteratorState state, | |
| 304 leveldb::Status*); | |
| 305 bool Advance(uint32 count, leveldb::Status*); | |
| 306 bool FirstSeek(leveldb::Status*); | |
| 307 | |
| 308 virtual Cursor* Clone() = 0; | |
| 309 virtual const IndexedDBKey& primary_key() const; | |
| 310 virtual IndexedDBValue* value() = 0; | |
| 311 virtual const RecordIdentifier& record_identifier() const; | |
| 312 virtual bool LoadCurrentRow() = 0; | |
| 313 | |
| 314 protected: | |
| 315 Cursor(scoped_refptr<IndexedDBBackingStore> backing_store, | |
| 316 Transaction* transaction, | |
| 317 int64 database_id, | |
| 318 const CursorOptions& cursor_options); | |
| 319 explicit Cursor(const IndexedDBBackingStore::Cursor* other); | |
| 320 | |
| 321 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; | |
| 322 virtual std::string EncodeKey(const IndexedDBKey& key, | |
| 323 const IndexedDBKey& primary_key) = 0; | |
| 324 | |
| 325 bool IsPastBounds() const; | |
| 326 bool HaveEnteredRange() const; | |
| 327 | |
| 328 IndexedDBBackingStore* backing_store_; | |
| 329 Transaction* transaction_; | |
| 330 int64 database_id_; | |
| 331 const CursorOptions cursor_options_; | |
| 332 scoped_ptr<LevelDBIterator> iterator_; | |
| 333 scoped_ptr<IndexedDBKey> current_key_; | |
| 334 IndexedDBBackingStore::RecordIdentifier record_identifier_; | |
| 335 | |
| 336 private: | |
| 337 DISALLOW_COPY_AND_ASSIGN(Cursor); | |
| 338 }; | |
| 339 | |
| 340 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor( | 472 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor( |
| 341 IndexedDBBackingStore::Transaction* transaction, | 473 IndexedDBBackingStore::Transaction* transaction, |
| 342 int64 database_id, | 474 int64 database_id, |
| 343 int64 object_store_id, | 475 int64 object_store_id, |
| 344 const IndexedDBKeyRange& key_range, | 476 const IndexedDBKeyRange& key_range, |
| 345 blink::WebIDBCursorDirection, | 477 blink::WebIDBCursorDirection, |
| 346 leveldb::Status*); | 478 leveldb::Status*); |
| 347 virtual scoped_ptr<Cursor> OpenObjectStoreCursor( | 479 virtual scoped_ptr<Cursor> OpenObjectStoreCursor( |
| 348 IndexedDBBackingStore::Transaction* transaction, | 480 IndexedDBBackingStore::Transaction* transaction, |
| 349 int64 database_id, | 481 int64 database_id, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 361 leveldb::Status*); | 493 leveldb::Status*); |
| 362 virtual scoped_ptr<Cursor> OpenIndexCursor( | 494 virtual scoped_ptr<Cursor> OpenIndexCursor( |
| 363 IndexedDBBackingStore::Transaction* transaction, | 495 IndexedDBBackingStore::Transaction* transaction, |
| 364 int64 database_id, | 496 int64 database_id, |
| 365 int64 object_store_id, | 497 int64 object_store_id, |
| 366 int64 index_id, | 498 int64 index_id, |
| 367 const IndexedDBKeyRange& key_range, | 499 const IndexedDBKeyRange& key_range, |
| 368 blink::WebIDBCursorDirection, | 500 blink::WebIDBCursorDirection, |
| 369 leveldb::Status*); | 501 leveldb::Status*); |
| 370 | 502 |
| 371 class BlobChangeRecord { | |
| 372 public: | |
| 373 BlobChangeRecord(const std::string& key, int64 object_store_id); | |
| 374 ~BlobChangeRecord(); | |
| 375 const std::string& key() const { return key_; } | |
| 376 int64 object_store_id() const { return object_store_id_; } | |
| 377 void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info); | |
| 378 std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; } | |
| 379 const std::vector<IndexedDBBlobInfo>& blob_info() const { | |
| 380 return blob_info_; | |
| 381 } | |
| 382 void SetHandles(ScopedVector<webkit_blob::BlobDataHandle>* handles); | |
| 383 scoped_ptr<BlobChangeRecord> Clone() const; | |
| 384 | |
| 385 private: | |
| 386 std::string key_; | |
| 387 int64 object_store_id_; | |
| 388 std::vector<IndexedDBBlobInfo> blob_info_; | |
| 389 ScopedVector<webkit_blob::BlobDataHandle> handles_; | |
| 390 DISALLOW_COPY_AND_ASSIGN(BlobChangeRecord); | |
| 391 }; | |
| 392 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap; | |
| 393 | |
| 394 class Transaction { | |
| 395 public: | |
| 396 explicit Transaction(IndexedDBBackingStore* backing_store); | |
| 397 virtual ~Transaction(); | |
| 398 virtual void Begin(); | |
| 399 // The callback will be called eventually on success or failure, or | |
| 400 // immediately if phase one is complete due to lack of any blobs to write. | |
| 401 virtual leveldb::Status CommitPhaseOne(scoped_refptr<BlobWriteCallback>); | |
| 402 virtual leveldb::Status CommitPhaseTwo(); | |
| 403 virtual void Rollback(); | |
| 404 void Reset() { | |
| 405 backing_store_ = NULL; | |
| 406 transaction_ = NULL; | |
| 407 } | |
| 408 leveldb::Status PutBlobInfoIfNeeded( | |
| 409 int64 database_id, | |
| 410 int64 object_store_id, | |
| 411 const std::string& object_store_data_key, | |
| 412 std::vector<IndexedDBBlobInfo>*, | |
| 413 ScopedVector<webkit_blob::BlobDataHandle>* handles); | |
| 414 void PutBlobInfo(int64 database_id, | |
| 415 int64 object_store_id, | |
| 416 const std::string& object_store_data_key, | |
| 417 std::vector<IndexedDBBlobInfo>*, | |
| 418 ScopedVector<webkit_blob::BlobDataHandle>* handles); | |
| 419 | |
| 420 LevelDBTransaction* transaction() { return transaction_; } | |
| 421 | |
| 422 leveldb::Status GetBlobInfoForRecord( | |
| 423 int64 database_id, | |
| 424 const std::string& object_store_data_key, | |
| 425 IndexedDBValue* value); | |
| 426 | |
| 427 // This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored | |
| 428 // under that key. | |
| 429 typedef std::vector<std::pair<BlobEntryKey, std::string> > | |
| 430 BlobEntryKeyValuePairVec; | |
| 431 | |
| 432 class WriteDescriptor { | |
| 433 public: | |
| 434 WriteDescriptor(const GURL& url, int64_t key, int64_t size); | |
| 435 WriteDescriptor(const base::FilePath& path, | |
| 436 int64_t key, | |
| 437 int64_t size, | |
| 438 base::Time last_modified); | |
| 439 | |
| 440 bool is_file() const { return is_file_; } | |
| 441 const GURL& url() const { | |
| 442 DCHECK(!is_file_); | |
| 443 return url_; | |
| 444 } | |
| 445 const base::FilePath& file_path() const { | |
| 446 DCHECK(is_file_); | |
| 447 return file_path_; | |
| 448 } | |
| 449 int64_t key() const { return key_; } | |
| 450 int64_t size() const { return size_; } | |
| 451 base::Time last_modified() const { return last_modified_; } | |
| 452 | |
| 453 private: | |
| 454 bool is_file_; | |
| 455 GURL url_; | |
| 456 base::FilePath file_path_; | |
| 457 int64_t key_; | |
| 458 int64_t size_; | |
| 459 base::Time last_modified_; | |
| 460 }; | |
| 461 | |
| 462 class ChainedBlobWriter | |
| 463 : public base::RefCountedThreadSafe<ChainedBlobWriter> { | |
| 464 public: | |
| 465 virtual void set_delegate( | |
| 466 scoped_ptr<fileapi::FileWriterDelegate> delegate) = 0; | |
| 467 | |
| 468 // TODO(ericu): Add a reason in the event of failure. | |
| 469 virtual void ReportWriteCompletion(bool succeeded, | |
| 470 int64 bytes_written) = 0; | |
| 471 | |
| 472 virtual void Abort() = 0; | |
| 473 | |
| 474 protected: | |
| 475 friend class base::RefCountedThreadSafe<ChainedBlobWriter>; | |
| 476 virtual ~ChainedBlobWriter() {} | |
| 477 }; | |
| 478 | |
| 479 class ChainedBlobWriterImpl; | |
| 480 | |
| 481 typedef std::vector<WriteDescriptor> WriteDescriptorVec; | |
| 482 | |
| 483 private: | |
| 484 class BlobWriteCallbackWrapper; | |
| 485 | |
| 486 leveldb::Status HandleBlobPreTransaction( | |
| 487 BlobEntryKeyValuePairVec* new_blob_entries, | |
| 488 WriteDescriptorVec* new_files_to_write); | |
| 489 // Returns true on success, false on failure. | |
| 490 bool CollectBlobFilesToRemove(); | |
| 491 // The callback will be called eventually on success or failure. | |
| 492 void WriteNewBlobs(BlobEntryKeyValuePairVec* new_blob_entries, | |
| 493 WriteDescriptorVec* new_files_to_write, | |
| 494 scoped_refptr<BlobWriteCallback> callback); | |
| 495 leveldb::Status SortBlobsToRemove(); | |
| 496 | |
| 497 IndexedDBBackingStore* backing_store_; | |
| 498 scoped_refptr<LevelDBTransaction> transaction_; | |
| 499 BlobChangeMap blob_change_map_; | |
| 500 BlobChangeMap incognito_blob_map_; | |
| 501 int64 database_id_; | |
| 502 BlobJournalType blobs_to_remove_; | |
| 503 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; | |
| 504 }; | |
| 505 | |
| 506 protected: | 503 protected: |
| 507 friend class base::RefCounted<IndexedDBBackingStore>; | 504 friend class base::RefCounted<IndexedDBBackingStore>; |
| 505 |
| 508 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, | 506 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, |
| 509 const GURL& origin_url, | 507 const GURL& origin_url, |
| 510 const base::FilePath& blob_path, | 508 const base::FilePath& blob_path, |
| 511 net::URLRequestContext* request_context, | 509 net::URLRequestContext* request_context, |
| 512 scoped_ptr<LevelDBDatabase> db, | 510 scoped_ptr<LevelDBDatabase> db, |
| 513 scoped_ptr<LevelDBComparator> comparator, | 511 scoped_ptr<LevelDBComparator> comparator, |
| 514 base::SequencedTaskRunner* task_runner); | 512 base::SequencedTaskRunner* task_runner); |
| 515 virtual ~IndexedDBBackingStore(); | 513 virtual ~IndexedDBBackingStore(); |
| 516 | 514 |
| 517 bool is_incognito() const { return !indexed_db_factory_; } | 515 bool is_incognito() const { return !indexed_db_factory_; } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 // will hold a reference to this backing store. | 578 // will hold a reference to this backing store. |
| 581 IndexedDBActiveBlobRegistry active_blob_registry_; | 579 IndexedDBActiveBlobRegistry active_blob_registry_; |
| 582 base::OneShotTimer<IndexedDBBackingStore> close_timer_; | 580 base::OneShotTimer<IndexedDBBackingStore> close_timer_; |
| 583 | 581 |
| 584 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore); | 582 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore); |
| 585 }; | 583 }; |
| 586 | 584 |
| 587 } // namespace content | 585 } // namespace content |
| 588 | 586 |
| 589 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 587 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
| OLD | NEW |