| 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/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/timer/timer.h" |
| 16 #include "content/browser/indexed_db/indexed_db.h" | 18 #include "content/browser/indexed_db/indexed_db.h" |
| 19 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" |
| 20 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
| 21 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
| 17 #include "content/browser/indexed_db/indexed_db_metadata.h" | 22 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 18 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 23 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" |
| 19 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 24 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
| 20 #include "content/common/content_export.h" | 25 #include "content/common/content_export.h" |
| 21 #include "content/common/indexed_db/indexed_db_key.h" | 26 #include "content/common/indexed_db/indexed_db_key.h" |
| 22 #include "content/common/indexed_db/indexed_db_key_path.h" | 27 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 23 #include "content/common/indexed_db/indexed_db_key_range.h" | 28 #include "content/common/indexed_db/indexed_db_key_range.h" |
| 24 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" | 29 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" |
| 25 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 30 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 26 | 31 |
| 32 class GURL; |
| 33 |
| 34 namespace base { |
| 35 class TaskRunner; |
| 36 } |
| 37 |
| 38 namespace net { |
| 39 class URLRequestContext; |
| 40 } |
| 41 |
| 27 namespace content { | 42 namespace content { |
| 28 | 43 |
| 29 class LevelDBComparator; | 44 class LevelDBComparator; |
| 30 class LevelDBDatabase; | 45 class LevelDBDatabase; |
| 46 struct IndexedDBValue; |
| 31 | 47 |
| 32 class LevelDBFactory { | 48 class LevelDBFactory { |
| 33 public: | 49 public: |
| 34 virtual ~LevelDBFactory() {} | 50 virtual ~LevelDBFactory() {} |
| 35 virtual leveldb::Status OpenLevelDB( | 51 virtual leveldb::Status OpenLevelDB( |
| 36 const base::FilePath& file_name, | 52 const base::FilePath& file_name, |
| 37 const LevelDBComparator* comparator, | 53 const LevelDBComparator* comparator, |
| 38 scoped_ptr<LevelDBDatabase>* db, | 54 scoped_ptr<LevelDBDatabase>* db, |
| 39 bool* is_disk_full) = 0; | 55 bool* is_disk_full) = 0; |
| 40 virtual bool DestroyLevelDB(const base::FilePath& file_name) = 0; | 56 virtual bool DestroyLevelDB(const base::FilePath& file_name) = 0; |
| 41 }; | 57 }; |
| 42 | 58 |
| 43 class CONTENT_EXPORT IndexedDBBackingStore | 59 class CONTENT_EXPORT IndexedDBBackingStore |
| 44 : public base::RefCounted<IndexedDBBackingStore> { | 60 : public base::RefCounted<IndexedDBBackingStore> { |
| 45 public: | 61 public: |
| 46 class CONTENT_EXPORT Transaction; | 62 class CONTENT_EXPORT Transaction; |
| 47 | 63 |
| 48 static scoped_refptr<IndexedDBBackingStore> Open( | 64 static scoped_refptr<IndexedDBBackingStore> Open( |
| 49 const std::string& origin_identifier, | 65 const std::string& origin_identifier, |
| 50 const base::FilePath& path_base, | 66 const base::FilePath& path_base, |
| 51 const std::string& file_identifier, | 67 const std::string& file_identifier, |
| 52 WebKit::WebIDBCallbacks::DataLoss* data_loss); | 68 net::URLRequestContext* request_context, |
| 69 WebKit::WebIDBCallbacks::DataLoss* data_loss, |
| 70 base::TaskRunner* task_runner, |
| 71 bool clean_journal); |
| 53 | 72 |
| 54 static scoped_refptr<IndexedDBBackingStore> Open( | 73 static scoped_refptr<IndexedDBBackingStore> Open( |
| 55 const std::string& origin_identifier, | 74 const std::string& origin_identifier, |
| 56 const base::FilePath& path_base, | 75 const base::FilePath& path_base, |
| 57 const std::string& file_identifier, | 76 const std::string& file_identifier, |
| 77 net::URLRequestContext* request_context, |
| 58 WebKit::WebIDBCallbacks::DataLoss* data_loss, | 78 WebKit::WebIDBCallbacks::DataLoss* data_loss, |
| 59 LevelDBFactory* factory); | 79 LevelDBFactory* factory, |
| 80 base::TaskRunner* task_runner, |
| 81 bool clean_journal); |
| 60 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( | 82 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( |
| 61 const std::string& file_identifier); | 83 const std::string& file_identifier); |
| 62 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( | 84 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( |
| 63 const std::string& file_identifier, | 85 const std::string& file_identifier, |
| 64 LevelDBFactory* factory); | 86 LevelDBFactory* factory); |
| 65 base::WeakPtr<IndexedDBBackingStore> GetWeakPtr() { | 87 base::WeakPtr<IndexedDBBackingStore> GetWeakPtr() { |
| 66 return weak_factory_.GetWeakPtr(); | 88 return weak_factory_.GetWeakPtr(); |
| 67 } | 89 } |
| 68 | 90 |
| 91 void GrantChildProcessPermissions(int child_process_id); |
| 92 |
| 69 virtual std::vector<string16> GetDatabaseNames(); | 93 virtual std::vector<string16> GetDatabaseNames(); |
| 70 virtual bool GetIDBDatabaseMetaData(const string16& name, | 94 virtual bool GetIDBDatabaseMetaData(const string16& name, |
| 71 IndexedDBDatabaseMetadata* metadata, | 95 IndexedDBDatabaseMetadata* metadata, |
| 72 bool* success) WARN_UNUSED_RESULT; | 96 bool* success) WARN_UNUSED_RESULT; |
| 73 virtual bool CreateIDBDatabaseMetaData(const string16& name, | 97 virtual bool CreateIDBDatabaseMetaData(const string16& name, |
| 74 const string16& version, | 98 const string16& version, |
| 75 int64 int_version, | 99 int64 int_version, |
| 76 int64* row_id); | 100 int64* row_id); |
| 77 virtual bool UpdateIDBDatabaseMetaData( | 101 virtual bool UpdateIDBDatabaseMetaData( |
| 78 IndexedDBBackingStore::Transaction* transaction, | 102 IndexedDBBackingStore::Transaction* transaction, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 137 } |
| 114 | 138 |
| 115 private: | 139 private: |
| 116 // TODO(jsbell): Make it more clear that this is the *encoded* version of | 140 // TODO(jsbell): Make it more clear that this is the *encoded* version of |
| 117 // the key. | 141 // the key. |
| 118 std::string primary_key_; | 142 std::string primary_key_; |
| 119 int64 version_; | 143 int64 version_; |
| 120 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); | 144 DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); |
| 121 }; | 145 }; |
| 122 | 146 |
| 147 class BlobWriteCallback : public RefCounted<BlobWriteCallback> { |
| 148 public: |
| 149 virtual ~BlobWriteCallback() { } |
| 150 virtual void didSucceed() = 0; |
| 151 virtual void didFail() = 0; |
| 152 }; |
| 153 |
| 123 virtual bool GetRecord(IndexedDBBackingStore::Transaction* transaction, | 154 virtual bool GetRecord(IndexedDBBackingStore::Transaction* transaction, |
| 124 int64 database_id, | 155 int64 database_id, |
| 125 int64 object_store_id, | 156 int64 object_store_id, |
| 126 const IndexedDBKey& key, | 157 const IndexedDBKey& key, |
| 127 std::string* record) WARN_UNUSED_RESULT; | 158 IndexedDBValue* record) WARN_UNUSED_RESULT; |
| 128 virtual bool PutRecord(IndexedDBBackingStore::Transaction* transaction, | 159 virtual bool PutRecord(IndexedDBBackingStore::Transaction* transaction, |
| 129 int64 database_id, | 160 int64 database_id, |
| 130 int64 object_store_id, | 161 int64 object_store_id, |
| 131 const IndexedDBKey& key, | 162 const IndexedDBKey& key, |
| 132 const std::string& value, | 163 IndexedDBValue& value, |
| 133 RecordIdentifier* record) WARN_UNUSED_RESULT; | 164 RecordIdentifier* record) WARN_UNUSED_RESULT; |
| 134 virtual bool ClearObjectStore(IndexedDBBackingStore::Transaction* transaction, | 165 virtual bool ClearObjectStore(IndexedDBBackingStore::Transaction* transaction, |
| 135 int64 database_id, | 166 int64 database_id, |
| 136 int64 object_store_id) WARN_UNUSED_RESULT; | 167 int64 object_store_id) WARN_UNUSED_RESULT; |
| 137 virtual bool DeleteRecord(IndexedDBBackingStore::Transaction* transaction, | 168 virtual bool DeleteRecord(IndexedDBBackingStore::Transaction* transaction, |
| 138 int64 database_id, | 169 int64 database_id, |
| 139 int64 object_store_id, | 170 int64 object_store_id, |
| 140 const RecordIdentifier& record) WARN_UNUSED_RESULT; | 171 const RecordIdentifier& record) WARN_UNUSED_RESULT; |
| 172 virtual bool DeleteRange(IndexedDBBackingStore::Transaction* transaction, |
| 173 int64 database_id, |
| 174 int64 object_store_id, |
| 175 const IndexedDBKeyRange&) WARN_UNUSED_RESULT; |
| 141 virtual bool GetKeyGeneratorCurrentNumber( | 176 virtual bool GetKeyGeneratorCurrentNumber( |
| 142 IndexedDBBackingStore::Transaction* transaction, | 177 IndexedDBBackingStore::Transaction* transaction, |
| 143 int64 database_id, | 178 int64 database_id, |
| 144 int64 object_store_id, | 179 int64 object_store_id, |
| 145 int64* current_number) WARN_UNUSED_RESULT; | 180 int64* current_number) WARN_UNUSED_RESULT; |
| 146 virtual bool MaybeUpdateKeyGeneratorCurrentNumber( | 181 virtual bool MaybeUpdateKeyGeneratorCurrentNumber( |
| 147 IndexedDBBackingStore::Transaction* transaction, | 182 IndexedDBBackingStore::Transaction* transaction, |
| 148 int64 database_id, | 183 int64 database_id, |
| 149 int64 object_store_id, | 184 int64 object_store_id, |
| 150 int64 new_state, | 185 int64 new_state, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 const IndexedDBKey& key, | 219 const IndexedDBKey& key, |
| 185 scoped_ptr<IndexedDBKey>* primary_key) WARN_UNUSED_RESULT; | 220 scoped_ptr<IndexedDBKey>* primary_key) WARN_UNUSED_RESULT; |
| 186 virtual bool KeyExistsInIndex(IndexedDBBackingStore::Transaction* transaction, | 221 virtual bool KeyExistsInIndex(IndexedDBBackingStore::Transaction* transaction, |
| 187 int64 database_id, | 222 int64 database_id, |
| 188 int64 object_store_id, | 223 int64 object_store_id, |
| 189 int64 index_id, | 224 int64 index_id, |
| 190 const IndexedDBKey& key, | 225 const IndexedDBKey& key, |
| 191 scoped_ptr<IndexedDBKey>* found_primary_key, | 226 scoped_ptr<IndexedDBKey>* found_primary_key, |
| 192 bool* exists) WARN_UNUSED_RESULT; | 227 bool* exists) WARN_UNUSED_RESULT; |
| 193 | 228 |
| 229 // Public for IndexedDBBlobRegistryCallback. |
| 230 void ReportBlobUnused(int64 database_id, int64 blob_key); |
| 231 |
| 232 base::FilePath GetIDBBlobFileName(int64 database_id, int64 key); |
| 233 |
| 194 class Cursor { | 234 class Cursor { |
| 195 public: | 235 public: |
| 196 virtual ~Cursor(); | 236 virtual ~Cursor(); |
| 197 | 237 |
| 198 enum IteratorState { | 238 enum IteratorState { |
| 199 READY = 0, | 239 READY = 0, |
| 200 SEEK | 240 SEEK |
| 201 }; | 241 }; |
| 202 | 242 |
| 203 struct CursorOptions { | 243 struct CursorOptions { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 215 }; | 255 }; |
| 216 | 256 |
| 217 const IndexedDBKey& key() const { return *current_key_; } | 257 const IndexedDBKey& key() const { return *current_key_; } |
| 218 bool Continue() { return Continue(NULL, SEEK); } | 258 bool Continue() { return Continue(NULL, SEEK); } |
| 219 bool Continue(const IndexedDBKey* key, IteratorState state); | 259 bool Continue(const IndexedDBKey* key, IteratorState state); |
| 220 bool Advance(uint32 count); | 260 bool Advance(uint32 count); |
| 221 bool FirstSeek(); | 261 bool FirstSeek(); |
| 222 | 262 |
| 223 virtual Cursor* Clone() = 0; | 263 virtual Cursor* Clone() = 0; |
| 224 virtual const IndexedDBKey& primary_key() const; | 264 virtual const IndexedDBKey& primary_key() const; |
| 225 virtual std::string* Value() = 0; | 265 virtual IndexedDBValue* Value() = 0; |
| 226 virtual const RecordIdentifier& record_identifier() const; | 266 virtual const RecordIdentifier& record_identifier() const; |
| 227 virtual bool LoadCurrentRow() = 0; | 267 virtual bool LoadCurrentRow() = 0; |
| 228 | 268 |
| 229 protected: | 269 protected: |
| 230 Cursor(LevelDBTransaction* transaction, | 270 Cursor(scoped_refptr<IndexedDBBackingStore> backing_store, |
| 271 LevelDBTransaction* transaction, |
| 272 int64 database_id, |
| 231 const CursorOptions& cursor_options); | 273 const CursorOptions& cursor_options); |
| 232 explicit Cursor(const IndexedDBBackingStore::Cursor* other); | 274 explicit Cursor(const IndexedDBBackingStore::Cursor* other); |
| 233 | 275 |
| 234 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; | 276 virtual std::string EncodeKey(const IndexedDBKey& key) = 0; |
| 235 | 277 |
| 236 bool IsPastBounds() const; | 278 bool IsPastBounds() const; |
| 237 bool HaveEnteredRange() const; | 279 bool HaveEnteredRange() const; |
| 238 | 280 |
| 281 scoped_refptr<IndexedDBBackingStore> backing_store_; |
| 239 LevelDBTransaction* transaction_; | 282 LevelDBTransaction* transaction_; |
| 283 int64 database_id_; |
| 240 const CursorOptions cursor_options_; | 284 const CursorOptions cursor_options_; |
| 241 scoped_ptr<LevelDBIterator> iterator_; | 285 scoped_ptr<LevelDBIterator> iterator_; |
| 242 scoped_ptr<IndexedDBKey> current_key_; | 286 scoped_ptr<IndexedDBKey> current_key_; |
| 243 IndexedDBBackingStore::RecordIdentifier record_identifier_; | 287 IndexedDBBackingStore::RecordIdentifier record_identifier_; |
| 244 }; | 288 }; |
| 245 | 289 |
| 246 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor( | 290 virtual scoped_ptr<Cursor> OpenObjectStoreKeyCursor( |
| 247 IndexedDBBackingStore::Transaction* transaction, | 291 IndexedDBBackingStore::Transaction* transaction, |
| 248 int64 database_id, | 292 int64 database_id, |
| 249 int64 object_store_id, | 293 int64 object_store_id, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 268 int64 object_store_id, | 312 int64 object_store_id, |
| 269 int64 index_id, | 313 int64 index_id, |
| 270 const IndexedDBKeyRange& key_range, | 314 const IndexedDBKeyRange& key_range, |
| 271 indexed_db::CursorDirection); | 315 indexed_db::CursorDirection); |
| 272 | 316 |
| 273 class Transaction { | 317 class Transaction { |
| 274 public: | 318 public: |
| 275 explicit Transaction(IndexedDBBackingStore* backing_store); | 319 explicit Transaction(IndexedDBBackingStore* backing_store); |
| 276 ~Transaction(); | 320 ~Transaction(); |
| 277 void Begin(); | 321 void Begin(); |
| 278 bool Commit(); | 322 // The callback will be called eventually on success or failure, or |
| 323 // immediately if phase one is complete due to lack of any blobs to write. |
| 324 bool CommitPhaseOne(scoped_refptr<BlobWriteCallback>); |
| 325 bool CommitPhaseTwo(); |
| 279 void Rollback(); | 326 void Rollback(); |
| 280 void Reset() { | 327 void Reset() { |
| 281 backing_store_ = NULL; | 328 backing_store_ = NULL; |
| 282 transaction_ = NULL; | 329 transaction_ = NULL; |
| 283 } | 330 } |
| 331 void PutBlobInfo(int64 database_id, int64 object_store_id, const |
| 332 std::string& key, std::vector<IndexedDBBlobInfo>*); |
| 284 | 333 |
| 285 static LevelDBTransaction* LevelDBTransactionFrom( | 334 static LevelDBTransaction* LevelDBTransactionFrom( |
| 286 Transaction* transaction) { | 335 Transaction* transaction) { |
| 287 return transaction->transaction_; | 336 return transaction->transaction_; |
| 288 } | 337 } |
| 289 | 338 |
| 339 // DatabaseId, BlobKey |
| 340 typedef std::pair<int64_t, int64_t> BlobJournalEntryType; |
| 341 typedef std::vector<BlobJournalEntryType> BlobJournalType; |
| 342 // This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored |
| 343 // under that key. |
| 344 typedef std::vector< std::pair<BlobEntryKey, std::string> > |
| 345 BlobEntryKeyValuePairVec; |
| 346 |
| 347 class WriteDescriptor { |
| 348 public: |
| 349 WriteDescriptor(const GURL& url, int64_t key); |
| 350 WriteDescriptor(const base::FilePath& path, int64_t key); |
| 351 |
| 352 bool is_file() const { return is_file_; } |
| 353 const GURL& url() const { |
| 354 DCHECK(!is_file_); |
| 355 return url_; |
| 356 } |
| 357 const base::FilePath& file_path() const { |
| 358 DCHECK(is_file_); |
| 359 return file_path_; |
| 360 } |
| 361 int64_t key() const { return key_; } |
| 362 private: |
| 363 bool is_file_; |
| 364 GURL url_; |
| 365 base::FilePath file_path_; |
| 366 int64_t key_; |
| 367 }; |
| 368 |
| 369 class ChainedBlobWriter; |
| 370 |
| 371 typedef std::vector<WriteDescriptor> WriteDescriptorVec; |
| 372 |
| 290 private: | 373 private: |
| 374 struct AVLTreeNode { |
| 375 AVLTreeNode() {} |
| 376 ~AVLTreeNode() {} |
| 377 std::string key; |
| 378 int64 object_store_id; |
| 379 std::vector<IndexedDBBlobInfo> blob_info; |
| 380 |
| 381 AVLTreeNode* less; |
| 382 AVLTreeNode* greater; |
| 383 int balance_factor; |
| 384 DISALLOW_COPY_AND_ASSIGN(AVLTreeNode); |
| 385 }; |
| 386 struct AVLTreeAbstractor { |
| 387 typedef AVLTreeNode* handle; |
| 388 typedef size_t size; |
| 389 typedef std::string key; // TODO(ericu): base::StringPiece? |
| 390 |
| 391 handle GetLess(handle h) { return h->less; } |
| 392 void SetLess(handle h, handle less) { h->less = less; } |
| 393 handle GetGreater(handle h) { return h->greater; } |
| 394 void SetGreater(handle h, handle greater) { h->greater = greater; } |
| 395 |
| 396 int GetBalanceFactor(handle h) { return h->balance_factor; } |
| 397 void SetBalanceFactor(handle h, int bf) { h->balance_factor = bf; } |
| 398 |
| 399 int CompareKeyKey(const key& ka, const key& kb) { |
| 400 return comparator_->Compare(ka, kb); |
| 401 } |
| 402 int CompareKeyNode(const key& k, handle h) { |
| 403 return CompareKeyKey(k, key(h->key)); |
| 404 } |
| 405 int CompareNodeNode(handle ha, handle hb) { |
| 406 return CompareKeyKey(key(ha->key), key(hb->key)); |
| 407 } |
| 408 |
| 409 static handle Null() { return 0; } |
| 410 |
| 411 const LevelDBComparator* comparator_; |
| 412 }; |
| 413 typedef AVLTree<AVLTreeAbstractor> TreeType; |
| 414 |
| 415 // These return true on success, false on failure. |
| 416 bool HandleBlobPreTransaction(BlobEntryKeyValuePairVec* new_blob_entries, |
| 417 WriteDescriptorVec* new_files_to_write); |
| 418 bool CollectBlobFilesToRemove(); |
| 419 // The callback will be called eventually on success or failure. |
| 420 void WriteNewBlobs(BlobEntryKeyValuePairVec& new_blob_entries, |
| 421 WriteDescriptorVec& new_files_to_write, |
| 422 scoped_refptr<BlobWriteCallback> callback); |
| 423 bool SortBlobsToRemove(); |
| 424 |
| 291 IndexedDBBackingStore* backing_store_; | 425 IndexedDBBackingStore* backing_store_; |
| 292 scoped_refptr<LevelDBTransaction> transaction_; | 426 scoped_refptr<LevelDBTransaction> transaction_; |
| 427 TreeType blob_info_tree_; |
| 428 int64 database_id_; |
| 429 BlobJournalType blobs_to_remove_; |
| 430 scoped_refptr<ChainedBlobWriter> chained_blob_writer_; |
| 293 }; | 431 }; |
| 294 | 432 |
| 433 LevelDBComparator* comparator() { return comparator_.get(); } |
| 434 IndexedDBActiveBlobRegistry* active_blob_registry() { |
| 435 return &active_blob_registry_; |
| 436 } |
| 437 |
| 438 base::TaskRunner* task_runner() { return task_runner_; } |
| 439 |
| 295 protected: | 440 protected: |
| 296 IndexedDBBackingStore(const std::string& identifier, | 441 IndexedDBBackingStore(const std::string& identifier, |
| 442 const base::FilePath& blob_path, |
| 443 net::URLRequestContext* request_context, |
| 297 scoped_ptr<LevelDBDatabase> db, | 444 scoped_ptr<LevelDBDatabase> db, |
| 298 scoped_ptr<LevelDBComparator> comparator); | 445 scoped_ptr<LevelDBComparator> comparator, |
| 446 base::TaskRunner* task_runner); |
| 299 virtual ~IndexedDBBackingStore(); | 447 virtual ~IndexedDBBackingStore(); |
| 300 friend class base::RefCounted<IndexedDBBackingStore>; | 448 friend class base::RefCounted<IndexedDBBackingStore>; |
| 301 | 449 |
| 450 bool WriteBlobFile(int64 database_id, |
| 451 const Transaction::WriteDescriptor& descriptor, |
| 452 Transaction::ChainedBlobWriter* chained_blob_writer); |
| 453 |
| 302 private: | 454 private: |
| 303 static scoped_refptr<IndexedDBBackingStore> Create( | 455 static scoped_refptr<IndexedDBBackingStore> Create( |
| 304 const std::string& identifier, | 456 const std::string& identifier, |
| 457 const base::FilePath& blob_path, |
| 458 net::URLRequestContext* request_context, |
| 305 scoped_ptr<LevelDBDatabase> db, | 459 scoped_ptr<LevelDBDatabase> db, |
| 306 scoped_ptr<LevelDBComparator> comparator); | 460 scoped_ptr<LevelDBComparator> comparator, |
| 461 base::TaskRunner* task_runner); |
| 307 | 462 |
| 308 bool FindKeyInIndex(IndexedDBBackingStore::Transaction* transaction, | 463 bool FindKeyInIndex(IndexedDBBackingStore::Transaction* transaction, |
| 309 int64 database_id, | 464 int64 database_id, |
| 310 int64 object_store_id, | 465 int64 object_store_id, |
| 311 int64 index_id, | 466 int64 index_id, |
| 312 const IndexedDBKey& key, | 467 const IndexedDBKey& key, |
| 313 std::string* found_encoded_primary_key, | 468 std::string* found_encoded_primary_key, |
| 314 bool* found); | 469 bool* found); |
| 315 bool GetIndexes(int64 database_id, | 470 bool GetIndexes(int64 database_id, |
| 316 int64 object_store_id, | 471 int64 object_store_id, |
| 317 IndexedDBObjectStoreMetadata::IndexMap* map) | 472 IndexedDBObjectStoreMetadata::IndexMap* map) |
| 318 WARN_UNUSED_RESULT; | 473 WARN_UNUSED_RESULT; |
| 474 bool RemoveBlobFile(int64 database_id, int64 key); |
| 475 bool RemoveBlobDirectory(int64 database_id); |
| 476 bool CleanUpBlobJournal(const std::string& level_db_key); |
| 477 void CleanPrimaryJournalIgnoreReturn(); |
| 319 | 478 |
| 320 std::string identifier_; | 479 std::string identifier_; |
| 480 base::FilePath blob_path_; |
| 481 net::URLRequestContext* request_context_; |
| 482 base::TaskRunner* task_runner_; |
| 483 std::set<int> child_process_ids_granted_; |
| 484 base::OneShotTimer<IndexedDBBackingStore> journal_cleaning_timer_; |
| 321 | 485 |
| 322 scoped_ptr<LevelDBDatabase> db_; | 486 scoped_ptr<LevelDBDatabase> db_; |
| 323 scoped_ptr<LevelDBComparator> comparator_; | 487 scoped_ptr<LevelDBComparator> comparator_; |
| 488 // The active_blob_registry_ will hold a refcount to this backing store |
| 489 // whenever any live blobs are registered with it. |
| 490 IndexedDBActiveBlobRegistry active_blob_registry_; |
| 324 base::WeakPtrFactory<IndexedDBBackingStore> weak_factory_; | 491 base::WeakPtrFactory<IndexedDBBackingStore> weak_factory_; |
| 325 }; | 492 }; |
| 326 | 493 |
| 327 } // namespace content | 494 } // namespace content |
| 328 | 495 |
| 329 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 496 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
| OLD | NEW |