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 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 return s; | 478 return s; |
479 if (!found) | 479 if (!found) |
480 *max_object_store_id = 0; | 480 *max_object_store_id = 0; |
481 | 481 |
482 DCHECK_GE(*max_object_store_id, 0); | 482 DCHECK_GE(*max_object_store_id, 0); |
483 return s; | 483 return s; |
484 } | 484 } |
485 | 485 |
486 class DefaultLevelDBFactory : public LevelDBFactory { | 486 class DefaultLevelDBFactory : public LevelDBFactory { |
487 public: | 487 public: |
| 488 DefaultLevelDBFactory() {} |
488 virtual leveldb::Status OpenLevelDB(const base::FilePath& file_name, | 489 virtual leveldb::Status OpenLevelDB(const base::FilePath& file_name, |
489 const LevelDBComparator* comparator, | 490 const LevelDBComparator* comparator, |
490 scoped_ptr<LevelDBDatabase>* db, | 491 scoped_ptr<LevelDBDatabase>* db, |
491 bool* is_disk_full) OVERRIDE { | 492 bool* is_disk_full) OVERRIDE { |
492 return LevelDBDatabase::Open(file_name, comparator, db, is_disk_full); | 493 return LevelDBDatabase::Open(file_name, comparator, db, is_disk_full); |
493 } | 494 } |
494 virtual leveldb::Status DestroyLevelDB(const base::FilePath& file_name) | 495 virtual leveldb::Status DestroyLevelDB(const base::FilePath& file_name) |
495 OVERRIDE { | 496 OVERRIDE { |
496 return LevelDBDatabase::Destroy(file_name); | 497 return LevelDBDatabase::Destroy(file_name); |
497 } | 498 } |
| 499 |
| 500 private: |
| 501 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory); |
498 }; | 502 }; |
499 | 503 |
500 static bool GetBlobKeyGeneratorCurrentNumber( | 504 static bool GetBlobKeyGeneratorCurrentNumber( |
501 LevelDBTransaction* leveldb_transaction, | 505 LevelDBTransaction* leveldb_transaction, |
502 int64 database_id, | 506 int64 database_id, |
503 int64* blob_key_generator_current_number) { | 507 int64* blob_key_generator_current_number) { |
504 const std::string key_gen_key = DatabaseMetaDataKey::Encode( | 508 const std::string key_gen_key = DatabaseMetaDataKey::Encode( |
505 database_id, DatabaseMetaDataKey::BLOB_KEY_GENERATOR_CURRENT_NUMBER); | 509 database_id, DatabaseMetaDataKey::BLOB_KEY_GENERATOR_CURRENT_NUMBER); |
506 | 510 |
507 // Default to initial number if not found. | 511 // Default to initial number if not found. |
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2217 | 2221 |
2218 bool waiting_for_callback_; | 2222 bool waiting_for_callback_; |
2219 scoped_refptr<ChainedBlobWriterImpl> self_ref_; | 2223 scoped_refptr<ChainedBlobWriterImpl> self_ref_; |
2220 WriteDescriptorVec blobs_; | 2224 WriteDescriptorVec blobs_; |
2221 WriteDescriptorVec::const_iterator iter_; | 2225 WriteDescriptorVec::const_iterator iter_; |
2222 int64 database_id_; | 2226 int64 database_id_; |
2223 IndexedDBBackingStore* backing_store_; | 2227 IndexedDBBackingStore* backing_store_; |
2224 scoped_refptr<IndexedDBBackingStore::BlobWriteCallback> callback_; | 2228 scoped_refptr<IndexedDBBackingStore::BlobWriteCallback> callback_; |
2225 scoped_ptr<FileWriterDelegate> delegate_; | 2229 scoped_ptr<FileWriterDelegate> delegate_; |
2226 bool aborted_; | 2230 bool aborted_; |
| 2231 |
| 2232 DISALLOW_COPY_AND_ASSIGN(ChainedBlobWriterImpl); |
2227 }; | 2233 }; |
2228 | 2234 |
2229 class LocalWriteClosure : public FileWriterDelegate::DelegateWriteCallback, | 2235 class LocalWriteClosure : public FileWriterDelegate::DelegateWriteCallback, |
2230 public base::RefCounted<LocalWriteClosure> { | 2236 public base::RefCounted<LocalWriteClosure> { |
2231 public: | 2237 public: |
2232 LocalWriteClosure(IndexedDBBackingStore::Transaction::ChainedBlobWriter* | 2238 LocalWriteClosure(IndexedDBBackingStore::Transaction::ChainedBlobWriter* |
2233 chained_blob_writer_, | 2239 chained_blob_writer_, |
2234 base::TaskRunner* task_runner) | 2240 base::TaskRunner* task_runner) |
2235 : chained_blob_writer_(chained_blob_writer_), | 2241 : chained_blob_writer_(chained_blob_writer_), |
2236 task_runner_(task_runner), | 2242 task_runner_(task_runner), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2282 friend class base::RefCounted<LocalWriteClosure>; | 2288 friend class base::RefCounted<LocalWriteClosure>; |
2283 | 2289 |
2284 void callBlobCallbackOnIDBTaskRunner(bool succeeded) { | 2290 void callBlobCallbackOnIDBTaskRunner(bool succeeded) { |
2285 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 2291 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
2286 chained_blob_writer_->ReportWriteCompletion(succeeded, bytes_written_); | 2292 chained_blob_writer_->ReportWriteCompletion(succeeded, bytes_written_); |
2287 } | 2293 } |
2288 | 2294 |
2289 IndexedDBBackingStore::Transaction::ChainedBlobWriter* chained_blob_writer_; | 2295 IndexedDBBackingStore::Transaction::ChainedBlobWriter* chained_blob_writer_; |
2290 base::TaskRunner* task_runner_; | 2296 base::TaskRunner* task_runner_; |
2291 int64 bytes_written_; | 2297 int64 bytes_written_; |
| 2298 |
| 2299 DISALLOW_COPY_AND_ASSIGN(LocalWriteClosure); |
2292 }; | 2300 }; |
2293 | 2301 |
2294 bool IndexedDBBackingStore::WriteBlobFile( | 2302 bool IndexedDBBackingStore::WriteBlobFile( |
2295 int64 database_id, | 2303 int64 database_id, |
2296 const Transaction::WriteDescriptor& descriptor, | 2304 const Transaction::WriteDescriptor& descriptor, |
2297 Transaction::ChainedBlobWriter* chained_blob_writer) { | 2305 Transaction::ChainedBlobWriter* chained_blob_writer) { |
2298 | 2306 |
2299 if (!MakeIDBBlobDirectory(blob_path_, database_id, descriptor.key())) | 2307 if (!MakeIDBBlobDirectory(blob_path_, database_id, descriptor.key())) |
2300 return false; | 2308 return false; |
2301 | 2309 |
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3206 } | 3214 } |
3207 virtual std::string EncodeKey(const IndexedDBKey& key, | 3215 virtual std::string EncodeKey(const IndexedDBKey& key, |
3208 const IndexedDBKey& primary_key) OVERRIDE { | 3216 const IndexedDBKey& primary_key) OVERRIDE { |
3209 NOTREACHED(); | 3217 NOTREACHED(); |
3210 return std::string(); | 3218 return std::string(); |
3211 } | 3219 } |
3212 | 3220 |
3213 private: | 3221 private: |
3214 explicit ObjectStoreKeyCursorImpl(const ObjectStoreKeyCursorImpl* other) | 3222 explicit ObjectStoreKeyCursorImpl(const ObjectStoreKeyCursorImpl* other) |
3215 : IndexedDBBackingStore::Cursor(other) {} | 3223 : IndexedDBBackingStore::Cursor(other) {} |
| 3224 |
| 3225 DISALLOW_COPY_AND_ASSIGN(ObjectStoreKeyCursorImpl); |
3216 }; | 3226 }; |
3217 | 3227 |
3218 bool ObjectStoreKeyCursorImpl::LoadCurrentRow() { | 3228 bool ObjectStoreKeyCursorImpl::LoadCurrentRow() { |
3219 StringPiece slice(iterator_->Key()); | 3229 StringPiece slice(iterator_->Key()); |
3220 ObjectStoreDataKey object_store_data_key; | 3230 ObjectStoreDataKey object_store_data_key; |
3221 if (!ObjectStoreDataKey::Decode(&slice, &object_store_data_key)) { | 3231 if (!ObjectStoreDataKey::Decode(&slice, &object_store_data_key)) { |
3222 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3232 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
3223 return false; | 3233 return false; |
3224 } | 3234 } |
3225 | 3235 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3268 NOTREACHED(); | 3278 NOTREACHED(); |
3269 return std::string(); | 3279 return std::string(); |
3270 } | 3280 } |
3271 | 3281 |
3272 private: | 3282 private: |
3273 explicit ObjectStoreCursorImpl(const ObjectStoreCursorImpl* other) | 3283 explicit ObjectStoreCursorImpl(const ObjectStoreCursorImpl* other) |
3274 : IndexedDBBackingStore::Cursor(other), | 3284 : IndexedDBBackingStore::Cursor(other), |
3275 current_value_(other->current_value_) {} | 3285 current_value_(other->current_value_) {} |
3276 | 3286 |
3277 IndexedDBValue current_value_; | 3287 IndexedDBValue current_value_; |
| 3288 |
| 3289 DISALLOW_COPY_AND_ASSIGN(ObjectStoreCursorImpl); |
3278 }; | 3290 }; |
3279 | 3291 |
3280 bool ObjectStoreCursorImpl::LoadCurrentRow() { | 3292 bool ObjectStoreCursorImpl::LoadCurrentRow() { |
3281 StringPiece key_slice(iterator_->Key()); | 3293 StringPiece key_slice(iterator_->Key()); |
3282 ObjectStoreDataKey object_store_data_key; | 3294 ObjectStoreDataKey object_store_data_key; |
3283 if (!ObjectStoreDataKey::Decode(&key_slice, &object_store_data_key)) { | 3295 if (!ObjectStoreDataKey::Decode(&key_slice, &object_store_data_key)) { |
3284 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3296 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
3285 return false; | 3297 return false; |
3286 } | 3298 } |
3287 | 3299 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3352 key, | 3364 key, |
3353 primary_key); | 3365 primary_key); |
3354 } | 3366 } |
3355 | 3367 |
3356 private: | 3368 private: |
3357 explicit IndexKeyCursorImpl(const IndexKeyCursorImpl* other) | 3369 explicit IndexKeyCursorImpl(const IndexKeyCursorImpl* other) |
3358 : IndexedDBBackingStore::Cursor(other), | 3370 : IndexedDBBackingStore::Cursor(other), |
3359 primary_key_(new IndexedDBKey(*other->primary_key_)) {} | 3371 primary_key_(new IndexedDBKey(*other->primary_key_)) {} |
3360 | 3372 |
3361 scoped_ptr<IndexedDBKey> primary_key_; | 3373 scoped_ptr<IndexedDBKey> primary_key_; |
| 3374 |
| 3375 DISALLOW_COPY_AND_ASSIGN(IndexKeyCursorImpl); |
3362 }; | 3376 }; |
3363 | 3377 |
3364 bool IndexKeyCursorImpl::LoadCurrentRow() { | 3378 bool IndexKeyCursorImpl::LoadCurrentRow() { |
3365 StringPiece slice(iterator_->Key()); | 3379 StringPiece slice(iterator_->Key()); |
3366 IndexDataKey index_data_key; | 3380 IndexDataKey index_data_key; |
3367 if (!IndexDataKey::Decode(&slice, &index_data_key)) { | 3381 if (!IndexDataKey::Decode(&slice, &index_data_key)) { |
3368 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3382 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
3369 return false; | 3383 return false; |
3370 } | 3384 } |
3371 | 3385 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3466 private: | 3480 private: |
3467 explicit IndexCursorImpl(const IndexCursorImpl* other) | 3481 explicit IndexCursorImpl(const IndexCursorImpl* other) |
3468 : IndexedDBBackingStore::Cursor(other), | 3482 : IndexedDBBackingStore::Cursor(other), |
3469 primary_key_(new IndexedDBKey(*other->primary_key_)), | 3483 primary_key_(new IndexedDBKey(*other->primary_key_)), |
3470 current_value_(other->current_value_), | 3484 current_value_(other->current_value_), |
3471 primary_leveldb_key_(other->primary_leveldb_key_) {} | 3485 primary_leveldb_key_(other->primary_leveldb_key_) {} |
3472 | 3486 |
3473 scoped_ptr<IndexedDBKey> primary_key_; | 3487 scoped_ptr<IndexedDBKey> primary_key_; |
3474 IndexedDBValue current_value_; | 3488 IndexedDBValue current_value_; |
3475 std::string primary_leveldb_key_; | 3489 std::string primary_leveldb_key_; |
| 3490 |
| 3491 DISALLOW_COPY_AND_ASSIGN(IndexCursorImpl); |
3476 }; | 3492 }; |
3477 | 3493 |
3478 bool IndexCursorImpl::LoadCurrentRow() { | 3494 bool IndexCursorImpl::LoadCurrentRow() { |
3479 StringPiece slice(iterator_->Key()); | 3495 StringPiece slice(iterator_->Key()); |
3480 IndexDataKey index_data_key; | 3496 IndexDataKey index_data_key; |
3481 if (!IndexDataKey::Decode(&slice, &index_data_key)) { | 3497 if (!IndexDataKey::Decode(&slice, &index_data_key)) { |
3482 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3498 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
3483 return false; | 3499 return false; |
3484 } | 3500 } |
3485 | 3501 |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4046 callback_->Run(succeeded); | 4062 callback_->Run(succeeded); |
4047 transaction_->chained_blob_writer_ = NULL; | 4063 transaction_->chained_blob_writer_ = NULL; |
4048 } | 4064 } |
4049 | 4065 |
4050 private: | 4066 private: |
4051 virtual ~BlobWriteCallbackWrapper() {} | 4067 virtual ~BlobWriteCallbackWrapper() {} |
4052 friend class base::RefCounted<IndexedDBBackingStore::BlobWriteCallback>; | 4068 friend class base::RefCounted<IndexedDBBackingStore::BlobWriteCallback>; |
4053 | 4069 |
4054 IndexedDBBackingStore::Transaction* transaction_; | 4070 IndexedDBBackingStore::Transaction* transaction_; |
4055 scoped_refptr<BlobWriteCallback> callback_; | 4071 scoped_refptr<BlobWriteCallback> callback_; |
| 4072 |
| 4073 DISALLOW_COPY_AND_ASSIGN(BlobWriteCallbackWrapper); |
4056 }; | 4074 }; |
4057 | 4075 |
4058 void IndexedDBBackingStore::Transaction::WriteNewBlobs( | 4076 void IndexedDBBackingStore::Transaction::WriteNewBlobs( |
4059 BlobEntryKeyValuePairVec& new_blob_entries, | 4077 BlobEntryKeyValuePairVec& new_blob_entries, |
4060 WriteDescriptorVec& new_files_to_write, | 4078 WriteDescriptorVec& new_files_to_write, |
4061 scoped_refptr<BlobWriteCallback> callback) { | 4079 scoped_refptr<BlobWriteCallback> callback) { |
4062 DCHECK_GT(new_files_to_write.size(), 0UL); | 4080 DCHECK_GT(new_files_to_write.size(), 0UL); |
4063 DCHECK_GT(database_id_, 0); | 4081 DCHECK_GT(database_id_, 0); |
4064 BlobEntryKeyValuePairVec::iterator blob_entry_iter; | 4082 BlobEntryKeyValuePairVec::iterator blob_entry_iter; |
4065 for (blob_entry_iter = new_blob_entries.begin(); | 4083 for (blob_entry_iter = new_blob_entries.begin(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4160 const GURL& url, | 4178 const GURL& url, |
4161 int64_t key) | 4179 int64_t key) |
4162 : is_file_(false), url_(url), key_(key) {} | 4180 : is_file_(false), url_(url), key_(key) {} |
4163 | 4181 |
4164 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4182 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
4165 const FilePath& file_path, | 4183 const FilePath& file_path, |
4166 int64_t key) | 4184 int64_t key) |
4167 : is_file_(true), file_path_(file_path), key_(key) {} | 4185 : is_file_(true), file_path_(file_path), key_(key) {} |
4168 | 4186 |
4169 } // namespace content | 4187 } // namespace content |
OLD | NEW |