| 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 <set> |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 16 #include "content/browser/indexed_db/indexed_db.h" | 17 #include "content/browser/indexed_db/indexed_db.h" |
| 18 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" |
| 19 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
| 20 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
| 17 #include "content/browser/indexed_db/indexed_db_metadata.h" | 21 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 18 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 22 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" |
| 19 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 23 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
| 20 #include "content/common/content_export.h" | 24 #include "content/common/content_export.h" |
| 21 #include "content/common/indexed_db/indexed_db_key.h" | 25 #include "content/common/indexed_db/indexed_db_key.h" |
| 22 #include "content/common/indexed_db/indexed_db_key_path.h" | 26 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 23 #include "content/common/indexed_db/indexed_db_key_range.h" | 27 #include "content/common/indexed_db/indexed_db_key_range.h" |
| 24 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 28 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 25 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 30 #include "webkit/browser/blob/blob_data_handle.h" |
| 31 |
| 32 class GURL; |
| 33 |
| 34 namespace base { |
| 35 class TaskRunner; |
| 36 } |
| 37 |
| 38 namespace fileapi { |
| 39 class FileWriterDelegate; |
| 40 } |
| 41 |
| 42 namespace net { |
| 43 class URLRequestContext; |
| 44 } |
| 26 | 45 |
| 27 namespace content { | 46 namespace content { |
| 28 | 47 |
| 48 class IndexedDBFactory; |
| 29 class LevelDBComparator; | 49 class LevelDBComparator; |
| 30 class LevelDBDatabase; | 50 class LevelDBDatabase; |
| 51 struct IndexedDBValue; |
| 31 | 52 |
| 32 class LevelDBFactory { | 53 class LevelDBFactory { |
| 33 public: | 54 public: |
| 34 virtual ~LevelDBFactory() {} | 55 virtual ~LevelDBFactory() {} |
| 35 virtual leveldb::Status OpenLevelDB(const base::FilePath& file_name, | 56 virtual leveldb::Status OpenLevelDB(const base::FilePath& file_name, |
| 36 const LevelDBComparator* comparator, | 57 const LevelDBComparator* comparator, |
| 37 scoped_ptr<LevelDBDatabase>* db, | 58 scoped_ptr<LevelDBDatabase>* db, |
| 38 bool* is_disk_full) = 0; | 59 bool* is_disk_full) = 0; |
| 39 virtual bool DestroyLevelDB(const base::FilePath& file_name) = 0; | 60 virtual bool DestroyLevelDB(const base::FilePath& file_name) = 0; |
| 40 }; | 61 }; |
| 41 | 62 |
| 42 class CONTENT_EXPORT IndexedDBBackingStore | 63 class CONTENT_EXPORT IndexedDBBackingStore |
| 43 : public base::RefCounted<IndexedDBBackingStore> { | 64 : public base::RefCounted<IndexedDBBackingStore> { |
| 44 public: | 65 public: |
| 45 class CONTENT_EXPORT Transaction; | 66 class CONTENT_EXPORT Transaction; |
| 46 | 67 |
| 47 const GURL& origin_url() const { return origin_url_; } | 68 const GURL& origin_url() const { return origin_url_; } |
| 48 base::OneShotTimer<IndexedDBBackingStore>* close_timer() { | 69 base::OneShotTimer<IndexedDBBackingStore>* close_timer() { |
| 49 return &close_timer_; | 70 return &close_timer_; |
| 50 } | 71 } |
| 72 IndexedDBFactory* factory() const { return indexed_db_factory_; } |
| 51 | 73 |
| 52 static scoped_refptr<IndexedDBBackingStore> Open( | 74 static scoped_refptr<IndexedDBBackingStore> Open( |
| 75 IndexedDBFactory* indexed_db_factory, |
| 53 const GURL& origin_url, | 76 const GURL& origin_url, |
| 54 const base::FilePath& path_base, | 77 const base::FilePath& path_base, |
| 55 blink::WebIDBDataLoss* data_loss, | 78 net::URLRequestContext* request_context, |
| 56 std::string* data_loss_message, | |
| 57 bool* disk_full); | |
| 58 | |
| 59 static scoped_refptr<IndexedDBBackingStore> Open( | |
| 60 const GURL& origin_url, | |
| 61 const base::FilePath& path_base, | |
| 62 blink::WebIDBDataLoss* data_loss, | 79 blink::WebIDBDataLoss* data_loss, |
| 63 std::string* data_loss_message, | 80 std::string* data_loss_message, |
| 64 bool* disk_full, | 81 bool* disk_full, |
| 65 LevelDBFactory* factory); | 82 base::TaskRunner* task_runner, |
| 66 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( | 83 bool clean_journal); |
| 67 const GURL& origin_url); | 84 |
| 85 static scoped_refptr<IndexedDBBackingStore> Open( |
| 86 IndexedDBFactory* indexed_db_factory, |
| 87 const GURL& origin_url, |
| 88 const base::FilePath& path_base, |
| 89 net::URLRequestContext* request_context, |
| 90 blink::WebIDBDataLoss* data_loss, |
| 91 std::string* data_loss_message, |
| 92 bool* disk_full, |
| 93 LevelDBFactory* factory, |
| 94 base::TaskRunner* task_runner, |
| 95 bool clean_journal); |
| 68 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( | 96 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( |
| 69 const GURL& origin_url, | 97 const GURL& origin_url, |
| 70 LevelDBFactory* factory); | 98 base::TaskRunner* task_runner); |
| 99 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( |
| 100 const GURL& origin_url, |
| 101 LevelDBFactory* factory, |
| 102 base::TaskRunner* task_runner); |
| 103 |
| 104 void GrantChildProcessPermissions(int child_process_id); |
| 71 | 105 |
| 72 virtual std::vector<string16> GetDatabaseNames(); | 106 virtual std::vector<string16> GetDatabaseNames(); |
| 73 virtual bool GetIDBDatabaseMetaData(const string16& name, | 107 virtual bool GetIDBDatabaseMetaData(const string16& name, |
| 74 IndexedDBDatabaseMetadata* metadata, | 108 IndexedDBDatabaseMetadata* metadata, |
| 75 bool* success) WARN_UNUSED_RESULT; | 109 bool* success) WARN_UNUSED_RESULT; |
| 76 virtual bool CreateIDBDatabaseMetaData(const string16& name, | 110 virtual bool CreateIDBDatabaseMetaData(const string16& name, |
| 77 const string16& version, | 111 const string16& version, |
| 78 int64 int_version, | 112 int64 int_version, |
| 79 int64* row_id); | 113 int64* row_id); |
| 80 virtual bool UpdateIDBDatabaseIntVersion( | 114 virtual bool UpdateIDBDatabaseIntVersion( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 146 } |
| 113 | 147 |
| 114 private: | 148 private: |
| 115 // TODO(jsbell): Make it more clear that this is the *encoded* version of | 149 // TODO(jsbell): Make it more clear that this is the *encoded* version of |
| 116 // the key. | 150 // the key. |
| 117 std::string primary_key_; | 151 std::string primary_key_; |
| 118 int64 version_; | 152 int64 version_; |
| 119 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); | 153 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); |
| 120 }; | 154 }; |
| 121 | 155 |
| 156 class BlobWriteCallback : public RefCounted<BlobWriteCallback> { |
| 157 public: |
| 158 virtual ~BlobWriteCallback() {} |
| 159 virtual void didSucceed() = 0; |
| 160 virtual void didFail() = 0; |
| 161 }; |
| 162 |
| 122 virtual bool GetRecord(IndexedDBBackingStore::Transaction* transaction, | 163 virtual bool GetRecord(IndexedDBBackingStore::Transaction* transaction, |
| 123 int64 database_id, | 164 int64 database_id, |
| 124 int64 object_store_id, | 165 int64 object_store_id, |
| 125 const IndexedDBKey& key, | 166 const IndexedDBKey& key, |
| 126 std::string* record) WARN_UNUSED_RESULT; | 167 IndexedDBValue* record) WARN_UNUSED_RESULT; |
| 127 virtual bool PutRecord(IndexedDBBackingStore::Transaction* transaction, | 168 virtual bool PutRecord(IndexedDBBackingStore::Transaction* transaction, |
| 128 int64 database_id, | 169 int64 database_id, |
| 129 int64 object_store_id, | 170 int64 object_store_id, |
| 130 const IndexedDBKey& key, | 171 const IndexedDBKey& key, |
| 131 const std::string& value, | 172 IndexedDBValue& value, |
| 173 ScopedVector<webkit_blob::BlobDataHandle>* handles, |
| 132 RecordIdentifier* record) WARN_UNUSED_RESULT; | 174 RecordIdentifier* record) WARN_UNUSED_RESULT; |
| 133 virtual bool ClearObjectStore(IndexedDBBackingStore::Transaction* transaction, | 175 virtual bool ClearObjectStore(IndexedDBBackingStore::Transaction* transaction, |
| 134 int64 database_id, | 176 int64 database_id, |
| 135 int64 object_store_id) WARN_UNUSED_RESULT; | 177 int64 object_store_id) WARN_UNUSED_RESULT; |
| 136 virtual bool DeleteRecord(IndexedDBBackingStore::Transaction* transaction, | 178 virtual bool DeleteRecord(IndexedDBBackingStore::Transaction* transaction, |
| 137 int64 database_id, | 179 int64 database_id, |
| 138 int64 object_store_id, | 180 int64 object_store_id, |
| 139 const RecordIdentifier& record) WARN_UNUSED_RESULT; | 181 const RecordIdentifier& record) WARN_UNUSED_RESULT; |
| 182 virtual bool DeleteRange(IndexedDBBackingStore::Transaction* transaction, |
| 183 int64 database_id, |
| 184 int64 object_store_id, |
| 185 const IndexedDBKeyRange&) WARN_UNUSED_RESULT; |
| 140 virtual bool GetKeyGeneratorCurrentNumber( | 186 virtual bool GetKeyGeneratorCurrentNumber( |
| 141 IndexedDBBackingStore::Transaction* transaction, | 187 IndexedDBBackingStore::Transaction* transaction, |
| 142 int64 database_id, | 188 int64 database_id, |
| 143 int64 object_store_id, | 189 int64 object_store_id, |
| 144 int64* current_number) WARN_UNUSED_RESULT; | 190 int64* current_number) WARN_UNUSED_RESULT; |
| 145 virtual bool MaybeUpdateKeyGeneratorCurrentNumber( | 191 virtual bool MaybeUpdateKeyGeneratorCurrentNumber( |
| 146 IndexedDBBackingStore::Transaction* transaction, | 192 IndexedDBBackingStore::Transaction* transaction, |
| 147 int64 database_id, | 193 int64 database_id, |
| 148 int64 object_store_id, | 194 int64 object_store_id, |
| 149 int64 new_state, | 195 int64 new_state, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 const IndexedDBKey& key, | 229 const IndexedDBKey& key, |
| 184 scoped_ptr<IndexedDBKey>* primary_key) WARN_UNUSED_RESULT; | 230 scoped_ptr<IndexedDBKey>* primary_key) WARN_UNUSED_RESULT; |
| 185 virtual bool KeyExistsInIndex(IndexedDBBackingStore::Transaction* transaction, | 231 virtual bool KeyExistsInIndex(IndexedDBBackingStore::Transaction* transaction, |
| 186 int64 database_id, | 232 int64 database_id, |
| 187 int64 object_store_id, | 233 int64 object_store_id, |
| 188 int64 index_id, | 234 int64 index_id, |
| 189 const IndexedDBKey& key, | 235 const IndexedDBKey& key, |
| 190 scoped_ptr<IndexedDBKey>* found_primary_key, | 236 scoped_ptr<IndexedDBKey>* found_primary_key, |
| 191 bool* exists) WARN_UNUSED_RESULT; | 237 bool* exists) WARN_UNUSED_RESULT; |
| 192 | 238 |
| 239 // Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef. |
| 240 void ReportBlobUnused(int64 database_id, int64 blob_key); |
| 241 |
| 242 base::FilePath GetBlobFileName(int64 database_id, int64 key); |
| 243 |
| 193 class Cursor { | 244 class Cursor { |
| 194 public: | 245 public: |
| 195 virtual ~Cursor(); | 246 virtual ~Cursor(); |
| 196 | 247 |
| 197 enum IteratorState { | 248 enum IteratorState { |
| 198 READY = 0, | 249 READY = 0, |
| 199 SEEK | 250 SEEK |
| 200 }; | 251 }; |
| 201 | 252 |
| 202 struct CursorOptions { | 253 struct CursorOptions { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 219 return Continue(key, NULL, state); | 270 return Continue(key, NULL, state); |
| 220 } | 271 } |
| 221 bool Continue(const IndexedDBKey* key, | 272 bool Continue(const IndexedDBKey* key, |
| 222 const IndexedDBKey* primary_key, | 273 const IndexedDBKey* primary_key, |
| 223 IteratorState state); | 274 IteratorState state); |
| 224 bool Advance(uint32 count); | 275 bool Advance(uint32 count); |
| 225 bool FirstSeek(); | 276 bool FirstSeek(); |
| 226 | 277 |
| 227 virtual Cursor* Clone() = 0; | 278 virtual Cursor* Clone() = 0; |
| 228 virtual const IndexedDBKey& primary_key() const; | 279 virtual const IndexedDBKey& primary_key() const; |
| 229 virtual std::string* Value() = 0; | 280 virtual IndexedDBValue* Value() = 0; |
| 230 virtual const RecordIdentifier& record_identifier() const; | 281 virtual const RecordIdentifier& record_identifier() const; |
| 231 virtual bool LoadCurrentRow() = 0; | 282 virtual bool LoadCurrentRow() = 0; |
| 232 | 283 |
| 233 protected: | 284 protected: |
| 234 Cursor(LevelDBTransaction* transaction, | 285 Cursor(scoped_refptr<IndexedDBBackingStore> backing_store, |
| 286 LevelDBTransaction* transaction, |
| 287 int64 database_id, |
| 235 const CursorOptions& cursor_options); | 288 const CursorOptions& cursor_options); |
| 236 explicit Cursor(const IndexedDBBackingStore::Cursor* other); | 289 explicit Cursor(const IndexedDBBackingStore::Cursor* other); |
| 237 | 290 |
| 238 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; | 291 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; |
| 239 virtual std::string EncodeKey(const IndexedDBKey& key, | 292 virtual std::string EncodeKey(const IndexedDBKey& key, |
| 240 const IndexedDBKey& primary_key) = 0; | 293 const IndexedDBKey& primary_key) = 0; |
| 241 | 294 |
| 242 bool IsPastBounds() const; | 295 bool IsPastBounds() const; |
| 243 bool HaveEnteredRange() const; | 296 bool HaveEnteredRange() const; |
| 244 | 297 |
| 298 scoped_refptr<IndexedDBBackingStore> backing_store_; |
| 245 LevelDBTransaction* transaction_; | 299 LevelDBTransaction* transaction_; |
| 300 int64 database_id_; |
| 246 const CursorOptions cursor_options_; | 301 const CursorOptions cursor_options_; |
| 247 scoped_ptr<LevelDBIterator> iterator_; | 302 scoped_ptr<LevelDBIterator> iterator_; |
| 248 scoped_ptr<IndexedDBKey> current_key_; | 303 scoped_ptr<IndexedDBKey> current_key_; |
| 249 IndexedDBBackingStore::RecordIdentifier record_identifier_; | 304 IndexedDBBackingStore::RecordIdentifier record_identifier_; |
| 250 }; | 305 }; |
| 251 | 306 |
| 252 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor( | 307 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor( |
| 253 IndexedDBBackingStore::Transaction* transaction, | 308 IndexedDBBackingStore::Transaction* transaction, |
| 254 int64 database_id, | 309 int64 database_id, |
| 255 int64 object_store_id, | 310 int64 object_store_id, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 274 int64 object_store_id, | 329 int64 object_store_id, |
| 275 int64 index_id, | 330 int64 index_id, |
| 276 const IndexedDBKeyRange& key_range, | 331 const IndexedDBKeyRange& key_range, |
| 277 indexed_db::CursorDirection); | 332 indexed_db::CursorDirection); |
| 278 | 333 |
| 279 class Transaction { | 334 class Transaction { |
| 280 public: | 335 public: |
| 281 explicit Transaction(IndexedDBBackingStore* backing_store); | 336 explicit Transaction(IndexedDBBackingStore* backing_store); |
| 282 ~Transaction(); | 337 ~Transaction(); |
| 283 void Begin(); | 338 void Begin(); |
| 284 bool Commit(); | 339 // The callback will be called eventually on success or failure, or |
| 340 // immediately if phase one is complete due to lack of any blobs to write. |
| 341 bool CommitPhaseOne(scoped_refptr<BlobWriteCallback>); |
| 342 bool CommitPhaseTwo(); |
| 285 void Rollback(); | 343 void Rollback(); |
| 286 void Reset() { | 344 void Reset() { |
| 287 backing_store_ = NULL; | 345 backing_store_ = NULL; |
| 288 transaction_ = NULL; | 346 transaction_ = NULL; |
| 289 } | 347 } |
| 348 void PutBlobInfo(int64 database_id, |
| 349 int64 object_store_id, |
| 350 const std::string& key, |
| 351 std::vector<IndexedDBBlobInfo>*, |
| 352 ScopedVector<webkit_blob::BlobDataHandle>* handles); |
| 290 | 353 |
| 291 LevelDBTransaction* transaction() { return transaction_; } | 354 LevelDBTransaction* transaction() { return transaction_; } |
| 292 | 355 |
| 356 // DatabaseId, BlobKey |
| 357 typedef std::pair<int64_t, int64_t> BlobJournalEntryType; |
| 358 typedef std::vector<BlobJournalEntryType> BlobJournalType; |
| 359 // This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored |
| 360 // under that key. |
| 361 typedef std::vector<std::pair<BlobEntryKey, std::string> > |
| 362 BlobEntryKeyValuePairVec; |
| 363 |
| 364 class WriteDescriptor { |
| 365 public: |
| 366 WriteDescriptor(const GURL& url, int64_t key); |
| 367 WriteDescriptor(const base::FilePath& path, int64_t key); |
| 368 |
| 369 bool is_file() const { return is_file_; } |
| 370 const GURL& url() const { |
| 371 DCHECK(!is_file_); |
| 372 return url_; |
| 373 } |
| 374 const base::FilePath& file_path() const { |
| 375 DCHECK(is_file_); |
| 376 return file_path_; |
| 377 } |
| 378 int64_t key() const { return key_; } |
| 379 |
| 380 private: |
| 381 bool is_file_; |
| 382 GURL url_; |
| 383 base::FilePath file_path_; |
| 384 int64_t key_; |
| 385 }; |
| 386 |
| 387 class ChainedBlobWriter : public base::RefCounted<ChainedBlobWriter> { |
| 388 public: |
| 389 virtual void set_delegate( |
| 390 scoped_ptr<fileapi::FileWriterDelegate> delegate) = 0; |
| 391 |
| 392 virtual void ReportWriteCompletion(bool succeeded, |
| 393 int64 bytes_written) = 0; |
| 394 |
| 395 virtual void Abort() = 0; |
| 396 |
| 397 protected: |
| 398 virtual ~ChainedBlobWriter() {} |
| 399 friend class base::RefCounted<ChainedBlobWriter>; |
| 400 }; |
| 401 class ChainedBlobWriterImpl; |
| 402 |
| 403 typedef std::vector<WriteDescriptor> WriteDescriptorVec; |
| 404 |
| 293 private: | 405 private: |
| 406 class BlobChangeRecord { |
| 407 public: |
| 408 BlobChangeRecord() {} |
| 409 void set_key(const std::string& key) { key_ = key; } |
| 410 const std::string& key() const { return key_; } |
| 411 void set_object_store_id(int64 object_store_id) { |
| 412 object_store_id_ = object_store_id; |
| 413 } |
| 414 int64 object_store_id() const { return object_store_id_; } |
| 415 void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info); |
| 416 std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; } |
| 417 void SetHandles(ScopedVector<webkit_blob::BlobDataHandle>* handles); |
| 418 |
| 419 private: |
| 420 std::string key_; |
| 421 int64 object_store_id_; |
| 422 std::vector<IndexedDBBlobInfo> blob_info_; |
| 423 ScopedVector<webkit_blob::BlobDataHandle> handles_; |
| 424 }; |
| 425 class BlobWriteCallbackWrapper; |
| 426 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap; |
| 427 |
| 428 // These return true on success, false on failure. |
| 429 bool HandleBlobPreTransaction(BlobEntryKeyValuePairVec* new_blob_entries, |
| 430 WriteDescriptorVec* new_files_to_write); |
| 431 bool CollectBlobFilesToRemove(); |
| 432 // The callback will be called eventually on success or failure. |
| 433 void WriteNewBlobs(BlobEntryKeyValuePairVec& new_blob_entries, |
| 434 WriteDescriptorVec& new_files_to_write, |
| 435 scoped_refptr<BlobWriteCallback> callback); |
| 436 bool SortBlobsToRemove(); |
| 437 |
| 294 IndexedDBBackingStore* backing_store_; | 438 IndexedDBBackingStore* backing_store_; |
| 295 scoped_refptr<LevelDBTransaction> transaction_; | 439 scoped_refptr<LevelDBTransaction> transaction_; |
| 440 BlobChangeMap blob_change_map_; |
| 441 int64 database_id_; |
| 442 BlobJournalType blobs_to_remove_; |
| 443 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; |
| 296 }; | 444 }; |
| 297 | 445 |
| 446 LevelDBComparator* comparator() { return comparator_.get(); } |
| 447 IndexedDBActiveBlobRegistry* active_blob_registry() { |
| 448 return &active_blob_registry_; |
| 449 } |
| 450 |
| 451 base::TaskRunner* task_runner() { return task_runner_; } |
| 452 |
| 298 protected: | 453 protected: |
| 299 IndexedDBBackingStore(const GURL& origin_url, | 454 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, |
| 455 const GURL& origin_url, |
| 456 const base::FilePath& blob_path, |
| 457 net::URLRequestContext* request_context, |
| 300 scoped_ptr<LevelDBDatabase> db, | 458 scoped_ptr<LevelDBDatabase> db, |
| 301 scoped_ptr<LevelDBComparator> comparator); | 459 scoped_ptr<LevelDBComparator> comparator, |
| 460 base::TaskRunner* task_runner); |
| 302 virtual ~IndexedDBBackingStore(); | 461 virtual ~IndexedDBBackingStore(); |
| 303 friend class base::RefCounted<IndexedDBBackingStore>; | 462 friend class base::RefCounted<IndexedDBBackingStore>; |
| 304 | 463 |
| 464 bool SetUpMetadata(); |
| 465 |
| 466 virtual bool WriteBlobFile( |
| 467 int64 database_id, |
| 468 const Transaction::WriteDescriptor& descriptor, |
| 469 Transaction::ChainedBlobWriter* chained_blob_writer); |
| 470 virtual bool RemoveBlobFile(int64 database_id, int64 key); |
| 471 virtual void StartJournalCleaningTimer(); |
| 472 void CleanPrimaryJournalIgnoreReturn(); |
| 473 |
| 305 private: | 474 private: |
| 306 static scoped_refptr<IndexedDBBackingStore> Create( | 475 static scoped_refptr<IndexedDBBackingStore> Create( |
| 476 IndexedDBFactory* indexed_db_factory, |
| 307 const GURL& origin_url, | 477 const GURL& origin_url, |
| 478 const base::FilePath& blob_path, |
| 479 net::URLRequestContext* request_context, |
| 308 scoped_ptr<LevelDBDatabase> db, | 480 scoped_ptr<LevelDBDatabase> db, |
| 309 scoped_ptr<LevelDBComparator> comparator); | 481 scoped_ptr<LevelDBComparator> comparator, |
| 482 base::TaskRunner* task_runner); |
| 310 | 483 |
| 311 bool FindKeyInIndex(IndexedDBBackingStore::Transaction* transaction, | 484 bool FindKeyInIndex(IndexedDBBackingStore::Transaction* transaction, |
| 312 int64 database_id, | 485 int64 database_id, |
| 313 int64 object_store_id, | 486 int64 object_store_id, |
| 314 int64 index_id, | 487 int64 index_id, |
| 315 const IndexedDBKey& key, | 488 const IndexedDBKey& key, |
| 316 std::string* found_encoded_primary_key, | 489 std::string* found_encoded_primary_key, |
| 317 bool* found); | 490 bool* found); |
| 318 bool GetIndexes(int64 database_id, | 491 bool GetIndexes(int64 database_id, |
| 319 int64 object_store_id, | 492 int64 object_store_id, |
| 320 IndexedDBObjectStoreMetadata::IndexMap* map) | 493 IndexedDBObjectStoreMetadata::IndexMap* map) |
| 321 WARN_UNUSED_RESULT; | 494 WARN_UNUSED_RESULT; |
| 495 bool RemoveBlobDirectory(int64 database_id); |
| 496 bool CleanUpBlobJournal(const std::string& level_db_key); |
| 322 | 497 |
| 498 IndexedDBFactory* indexed_db_factory_; |
| 323 const GURL origin_url_; | 499 const GURL origin_url_; |
| 324 | 500 |
| 325 // The origin identifier is a key prefix unique to the origin used in the | 501 // The origin identifier is a key prefix unique to the origin used in the |
| 326 // leveldb backing store to partition data by origin. It is a normalized | 502 // leveldb backing store to partition data by origin. It is a normalized |
| 327 // version of the origin URL with a versioning suffix appended, e.g. | 503 // version of the origin URL with a versioning suffix appended, e.g. |
| 328 // "http_localhost_81@1" Since only one origin is stored per backing store | 504 // "http_localhost_81@1" Since only one origin is stored per backing store |
| 329 // this is redundant but necessary for backwards compatibility; the suffix | 505 // this is redundant but necessary for backwards compatibility; the suffix |
| 330 // provides for future flexibility. | 506 // provides for future flexibility. |
| 331 const std::string origin_identifier_; | 507 const std::string origin_identifier_; |
| 332 | 508 |
| 509 base::FilePath blob_path_; |
| 510 net::URLRequestContext* request_context_; |
| 511 base::TaskRunner* task_runner_; |
| 512 std::set<int> child_process_ids_granted_; |
| 513 base::OneShotTimer<IndexedDBBackingStore> journal_cleaning_timer_; |
| 514 |
| 333 scoped_ptr<LevelDBDatabase> db_; | 515 scoped_ptr<LevelDBDatabase> db_; |
| 334 scoped_ptr<LevelDBComparator> comparator_; | 516 scoped_ptr<LevelDBComparator> comparator_; |
| 517 // The active_blob_registry_ will hold a refcount to this backing store |
| 518 // whenever any live blobs are registered with it. |
| 519 IndexedDBActiveBlobRegistry active_blob_registry_; |
| 335 base::OneShotTimer<IndexedDBBackingStore> close_timer_; | 520 base::OneShotTimer<IndexedDBBackingStore> close_timer_; |
| 336 }; | 521 }; |
| 337 | 522 |
| 338 } // namespace content | 523 } // namespace content |
| 339 | 524 |
| 340 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 525 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
| OLD | NEW |