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 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 scoped_refptr<IndexedDBBackingStore> backing_store = | 1063 scoped_refptr<IndexedDBBackingStore> backing_store = |
1064 Create(indexed_db_factory, | 1064 Create(indexed_db_factory, |
1065 origin_url, | 1065 origin_url, |
1066 blob_path, | 1066 blob_path, |
1067 request_context, | 1067 request_context, |
1068 db.Pass(), | 1068 db.Pass(), |
1069 comparator.Pass(), | 1069 comparator.Pass(), |
1070 task_runner, | 1070 task_runner, |
1071 status); | 1071 status); |
1072 | 1072 |
1073 if (clean_journal && backing_store && | 1073 if (clean_journal && backing_store.get() && |
1074 !backing_store->CleanUpBlobJournal(LiveBlobJournalKey::Encode()).ok()) { | 1074 !backing_store->CleanUpBlobJournal(LiveBlobJournalKey::Encode()).ok()) { |
1075 HistogramOpenStatus( | 1075 HistogramOpenStatus( |
1076 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, origin_url); | 1076 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, origin_url); |
1077 return scoped_refptr<IndexedDBBackingStore>(); | 1077 return scoped_refptr<IndexedDBBackingStore>(); |
1078 } | 1078 } |
1079 return backing_store; | 1079 return backing_store; |
1080 } | 1080 } |
1081 | 1081 |
1082 // static | 1082 // static |
1083 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( | 1083 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( |
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2246 aborted_ = true; | 2246 aborted_ = true; |
2247 } | 2247 } |
2248 | 2248 |
2249 private: | 2249 private: |
2250 virtual ~ChainedBlobWriterImpl() {} | 2250 virtual ~ChainedBlobWriterImpl() {} |
2251 | 2251 |
2252 void WriteNextFile() { | 2252 void WriteNextFile() { |
2253 DCHECK(!waiting_for_callback_); | 2253 DCHECK(!waiting_for_callback_); |
2254 DCHECK(!aborted_); | 2254 DCHECK(!aborted_); |
2255 if (iter_ == blobs_.end()) { | 2255 if (iter_ == blobs_.end()) { |
2256 DCHECK(!self_ref_); | 2256 DCHECK(!self_ref_.get()); |
2257 callback_->Run(true); | 2257 callback_->Run(true); |
2258 return; | 2258 return; |
2259 } else { | 2259 } else { |
2260 if (!backing_store_->WriteBlobFile(database_id_, *iter_, this)) { | 2260 if (!backing_store_->WriteBlobFile(database_id_, *iter_, this)) { |
2261 callback_->Run(false); | 2261 callback_->Run(false); |
2262 return; | 2262 return; |
2263 } | 2263 } |
2264 waiting_for_callback_ = true; | 2264 waiting_for_callback_ = true; |
2265 } | 2265 } |
2266 } | 2266 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 write_status == FileWriterDelegate::SUCCESS_COMPLETED, | 2309 write_status == FileWriterDelegate::SUCCESS_COMPLETED, |
2310 bytes_written_)); | 2310 bytes_written_)); |
2311 } | 2311 } |
2312 | 2312 |
2313 void writeBlobToFileOnIOThread(const FilePath& file_path, | 2313 void writeBlobToFileOnIOThread(const FilePath& file_path, |
2314 const GURL& blob_url, | 2314 const GURL& blob_url, |
2315 net::URLRequestContext* request_context) { | 2315 net::URLRequestContext* request_context) { |
2316 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 2316 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
2317 scoped_ptr<storage::FileStreamWriter> writer( | 2317 scoped_ptr<storage::FileStreamWriter> writer( |
2318 storage::FileStreamWriter::CreateForLocalFile( | 2318 storage::FileStreamWriter::CreateForLocalFile( |
2319 task_runner_, | 2319 task_runner_.get(), |
2320 file_path, | 2320 file_path, |
2321 0, | 2321 0, |
2322 storage::FileStreamWriter::CREATE_NEW_FILE)); | 2322 storage::FileStreamWriter::CREATE_NEW_FILE)); |
2323 scoped_ptr<FileWriterDelegate> delegate( | 2323 scoped_ptr<FileWriterDelegate> delegate( |
2324 new FileWriterDelegate(writer.Pass(), | 2324 new FileWriterDelegate(writer.Pass(), |
2325 FileWriterDelegate::FLUSH_ON_COMPLETION)); | 2325 FileWriterDelegate::FLUSH_ON_COMPLETION)); |
2326 | 2326 |
2327 DCHECK(blob_url.is_valid()); | 2327 DCHECK(blob_url.is_valid()); |
2328 scoped_ptr<net::URLRequest> blob_request(request_context->CreateRequest( | 2328 scoped_ptr<net::URLRequest> blob_request(request_context->CreateRequest( |
2329 blob_url, net::DEFAULT_PRIORITY, delegate.get(), NULL)); | 2329 blob_url, net::DEFAULT_PRIORITY, delegate.get(), NULL)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2389 | 2389 |
2390 task_runner_->PostTask( | 2390 task_runner_->PostTask( |
2391 FROM_HERE, | 2391 FROM_HERE, |
2392 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, | 2392 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, |
2393 chained_blob_writer, | 2393 chained_blob_writer, |
2394 true, | 2394 true, |
2395 info.size)); | 2395 info.size)); |
2396 } else { | 2396 } else { |
2397 DCHECK(descriptor.url().is_valid()); | 2397 DCHECK(descriptor.url().is_valid()); |
2398 scoped_refptr<LocalWriteClosure> write_closure( | 2398 scoped_refptr<LocalWriteClosure> write_closure( |
2399 new LocalWriteClosure(chained_blob_writer, task_runner_)); | 2399 new LocalWriteClosure(chained_blob_writer, task_runner_.get())); |
2400 content::BrowserThread::PostTask( | 2400 content::BrowserThread::PostTask( |
2401 content::BrowserThread::IO, | 2401 content::BrowserThread::IO, |
2402 FROM_HERE, | 2402 FROM_HERE, |
2403 base::Bind(&LocalWriteClosure::writeBlobToFileOnIOThread, | 2403 base::Bind(&LocalWriteClosure::writeBlobToFileOnIOThread, |
2404 write_closure.get(), | 2404 write_closure.get(), |
2405 path, | 2405 path, |
2406 descriptor.url(), | 2406 descriptor.url(), |
2407 request_context_)); | 2407 request_context_)); |
2408 } | 2408 } |
2409 return true; | 2409 return true; |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3051 DCHECK(iterator_->IsValid()); | 3051 DCHECK(iterator_->IsValid()); |
3052 } | 3052 } |
3053 } | 3053 } |
3054 } | 3054 } |
3055 | 3055 |
3056 IndexedDBBackingStore::Cursor::Cursor( | 3056 IndexedDBBackingStore::Cursor::Cursor( |
3057 scoped_refptr<IndexedDBBackingStore> backing_store, | 3057 scoped_refptr<IndexedDBBackingStore> backing_store, |
3058 IndexedDBBackingStore::Transaction* transaction, | 3058 IndexedDBBackingStore::Transaction* transaction, |
3059 int64 database_id, | 3059 int64 database_id, |
3060 const CursorOptions& cursor_options) | 3060 const CursorOptions& cursor_options) |
3061 : backing_store_(backing_store), | 3061 : backing_store_(backing_store.get()), |
3062 transaction_(transaction), | 3062 transaction_(transaction), |
3063 database_id_(database_id), | 3063 database_id_(database_id), |
3064 cursor_options_(cursor_options) { | 3064 cursor_options_(cursor_options) { |
3065 } | 3065 } |
3066 IndexedDBBackingStore::Cursor::~Cursor() {} | 3066 IndexedDBBackingStore::Cursor::~Cursor() {} |
3067 | 3067 |
3068 bool IndexedDBBackingStore::Cursor::FirstSeek(leveldb::Status* s) { | 3068 bool IndexedDBBackingStore::Cursor::FirstSeek(leveldb::Status* s) { |
3069 iterator_ = transaction_->transaction()->CreateIterator(); | 3069 iterator_ = transaction_->transaction()->CreateIterator(); |
3070 if (cursor_options_.forward) | 3070 if (cursor_options_.forward) |
3071 *s = iterator_->Seek(cursor_options_.low_key); | 3071 *s = iterator_->Seek(cursor_options_.low_key); |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4036 if (!s.ok()) | 4036 if (!s.ok()) |
4037 return s; | 4037 return s; |
4038 // To signal how many blobs need attention right now. | 4038 // To signal how many blobs need attention right now. |
4039 blobs_to_remove_.swap(primary_journal); | 4039 blobs_to_remove_.swap(primary_journal); |
4040 return leveldb::Status::OK(); | 4040 return leveldb::Status::OK(); |
4041 } | 4041 } |
4042 | 4042 |
4043 leveldb::Status IndexedDBBackingStore::Transaction::CommitPhaseOne( | 4043 leveldb::Status IndexedDBBackingStore::Transaction::CommitPhaseOne( |
4044 scoped_refptr<BlobWriteCallback> callback) { | 4044 scoped_refptr<BlobWriteCallback> callback) { |
4045 IDB_TRACE("IndexedDBBackingStore::Transaction::CommitPhaseOne"); | 4045 IDB_TRACE("IndexedDBBackingStore::Transaction::CommitPhaseOne"); |
4046 DCHECK(transaction_); | 4046 DCHECK(transaction_.get()); |
4047 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread()); | 4047 DCHECK(backing_store_->task_runner()->RunsTasksOnCurrentThread()); |
4048 | 4048 |
4049 leveldb::Status s; | 4049 leveldb::Status s; |
4050 | 4050 |
4051 s = backing_store_->CleanUpBlobJournal(BlobJournalKey::Encode()); | 4051 s = backing_store_->CleanUpBlobJournal(BlobJournalKey::Encode()); |
4052 if (!s.ok()) { | 4052 if (!s.ok()) { |
4053 INTERNAL_WRITE_ERROR(TRANSACTION_COMMIT_METHOD); | 4053 INTERNAL_WRITE_ERROR(TRANSACTION_COMMIT_METHOD); |
4054 transaction_ = NULL; | 4054 transaction_ = NULL; |
4055 return s; | 4055 return s; |
4056 } | 4056 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4169 // Creating the writer will start it going asynchronously. | 4169 // Creating the writer will start it going asynchronously. |
4170 chained_blob_writer_ = | 4170 chained_blob_writer_ = |
4171 new ChainedBlobWriterImpl(database_id_, | 4171 new ChainedBlobWriterImpl(database_id_, |
4172 backing_store_, | 4172 backing_store_, |
4173 new_files_to_write, | 4173 new_files_to_write, |
4174 new BlobWriteCallbackWrapper(this, callback)); | 4174 new BlobWriteCallbackWrapper(this, callback)); |
4175 } | 4175 } |
4176 | 4176 |
4177 void IndexedDBBackingStore::Transaction::Rollback() { | 4177 void IndexedDBBackingStore::Transaction::Rollback() { |
4178 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); | 4178 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); |
4179 if (chained_blob_writer_) { | 4179 if (chained_blob_writer_.get()) { |
4180 chained_blob_writer_->Abort(); | 4180 chained_blob_writer_->Abort(); |
4181 chained_blob_writer_ = NULL; | 4181 chained_blob_writer_ = NULL; |
4182 } | 4182 } |
4183 if (transaction_.get() == NULL) | 4183 if (transaction_.get() == NULL) |
4184 return; | 4184 return; |
4185 transaction_->Rollback(); | 4185 transaction_->Rollback(); |
4186 transaction_ = NULL; | 4186 transaction_ = NULL; |
4187 } | 4187 } |
4188 | 4188 |
4189 IndexedDBBackingStore::BlobChangeRecord::BlobChangeRecord( | 4189 IndexedDBBackingStore::BlobChangeRecord::BlobChangeRecord( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4294 int64_t size, | 4294 int64_t size, |
4295 base::Time last_modified) | 4295 base::Time last_modified) |
4296 : is_file_(true), | 4296 : is_file_(true), |
4297 file_path_(file_path), | 4297 file_path_(file_path), |
4298 key_(key), | 4298 key_(key), |
4299 size_(size), | 4299 size_(size), |
4300 last_modified_(last_modified) { | 4300 last_modified_(last_modified) { |
4301 } | 4301 } |
4302 | 4302 |
4303 } // namespace content | 4303 } // namespace content |
OLD | NEW |