| 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 2660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2671 return leveldb::Status::OK(); | 2671 return leveldb::Status::OK(); |
| 2672 } | 2672 } |
| 2673 | 2673 |
| 2674 BlobEntryKey blob_entry_key; | 2674 BlobEntryKey blob_entry_key; |
| 2675 StringPiece leveldb_key_piece(object_store_data_key); | 2675 StringPiece leveldb_key_piece(object_store_data_key); |
| 2676 if (!BlobEntryKey::FromObjectStoreDataKey(&leveldb_key_piece, | 2676 if (!BlobEntryKey::FromObjectStoreDataKey(&leveldb_key_piece, |
| 2677 &blob_entry_key)) { | 2677 &blob_entry_key)) { |
| 2678 NOTREACHED(); | 2678 NOTREACHED(); |
| 2679 return InternalInconsistencyStatus(); | 2679 return InternalInconsistencyStatus(); |
| 2680 } | 2680 } |
| 2681 scoped_ptr<LevelDBIterator> it = transaction()->CreateIterator(); | |
| 2682 std::string encoded_key = blob_entry_key.Encode(); | 2681 std::string encoded_key = blob_entry_key.Encode(); |
| 2683 leveldb::Status s = it->Seek(encoded_key); | 2682 bool found; |
| 2683 std::string encoded_value; |
| 2684 leveldb::Status s = transaction()->Get(encoded_key, &encoded_value, &found); |
| 2684 if (!s.ok()) | 2685 if (!s.ok()) |
| 2685 return s; | 2686 return s; |
| 2686 if (it->IsValid() && CompareKeys(it->Key(), encoded_key) == 0) { | 2687 if (found) { |
| 2687 if (!DecodeBlobData(it->Value().as_string(), &value->blob_info)) { | 2688 if (!DecodeBlobData(encoded_value, &value->blob_info)) { |
| 2688 INTERNAL_READ_ERROR(GET_BLOB_INFO_FOR_RECORD); | 2689 INTERNAL_READ_ERROR(GET_BLOB_INFO_FOR_RECORD); |
| 2689 return InternalInconsistencyStatus(); | 2690 return InternalInconsistencyStatus(); |
| 2690 } | 2691 } |
| 2691 std::vector<IndexedDBBlobInfo>::iterator iter; | 2692 std::vector<IndexedDBBlobInfo>::iterator iter; |
| 2692 for (iter = value->blob_info.begin(); iter != value->blob_info.end(); | 2693 for (iter = value->blob_info.begin(); iter != value->blob_info.end(); |
| 2693 ++iter) { | 2694 ++iter) { |
| 2694 iter->set_file_path( | 2695 iter->set_file_path( |
| 2695 backing_store_->GetBlobFileName(database_id, iter->key())); | 2696 backing_store_->GetBlobFileName(database_id, iter->key())); |
| 2696 iter->set_mark_used_callback( | 2697 iter->set_mark_used_callback( |
| 2697 backing_store_->active_blob_registry()->GetAddBlobRefCallback( | 2698 backing_store_->active_blob_registry()->GetAddBlobRefCallback( |
| (...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3974 } | 3975 } |
| 3975 | 3976 |
| 3976 bool IndexedDBBackingStore::Transaction::CollectBlobFilesToRemove() { | 3977 bool IndexedDBBackingStore::Transaction::CollectBlobFilesToRemove() { |
| 3977 if (backing_store_->is_incognito()) | 3978 if (backing_store_->is_incognito()) |
| 3978 return true; | 3979 return true; |
| 3979 | 3980 |
| 3980 BlobChangeMap::const_iterator iter = blob_change_map_.begin(); | 3981 BlobChangeMap::const_iterator iter = blob_change_map_.begin(); |
| 3981 // Look up all old files to remove as part of the transaction, store their | 3982 // Look up all old files to remove as part of the transaction, store their |
| 3982 // names in blobs_to_remove_, and remove their old blob data entries. | 3983 // names in blobs_to_remove_, and remove their old blob data entries. |
| 3983 if (iter != blob_change_map_.end()) { | 3984 if (iter != blob_change_map_.end()) { |
| 3984 scoped_ptr<LevelDBIterator> db_iter = transaction_->CreateIterator(); | |
| 3985 for (; iter != blob_change_map_.end(); ++iter) { | 3985 for (; iter != blob_change_map_.end(); ++iter) { |
| 3986 BlobEntryKey blob_entry_key; | 3986 BlobEntryKey blob_entry_key; |
| 3987 StringPiece key_piece(iter->second->key()); | 3987 StringPiece key_piece(iter->second->key()); |
| 3988 if (!BlobEntryKey::FromObjectStoreDataKey(&key_piece, &blob_entry_key)) { | 3988 if (!BlobEntryKey::FromObjectStoreDataKey(&key_piece, &blob_entry_key)) { |
| 3989 NOTREACHED(); | 3989 NOTREACHED(); |
| 3990 INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD); | 3990 INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD); |
| 3991 transaction_ = NULL; | 3991 transaction_ = NULL; |
| 3992 return false; | 3992 return false; |
| 3993 } | 3993 } |
| 3994 if (database_id_ < 0) | 3994 if (database_id_ < 0) |
| 3995 database_id_ = blob_entry_key.database_id(); | 3995 database_id_ = blob_entry_key.database_id(); |
| 3996 else | 3996 else |
| 3997 DCHECK_EQ(database_id_, blob_entry_key.database_id()); | 3997 DCHECK_EQ(database_id_, blob_entry_key.database_id()); |
| 3998 std::string blob_entry_key_bytes = blob_entry_key.Encode(); | 3998 std::string blob_entry_key_bytes = blob_entry_key.Encode(); |
| 3999 db_iter->Seek(blob_entry_key_bytes); | 3999 bool found; |
| 4000 if (db_iter->IsValid() && | 4000 std::string blob_entry_value_bytes; |
| 4001 !CompareKeys(db_iter->Key(), blob_entry_key_bytes)) { | 4001 leveldb::Status s = transaction_->Get( |
| 4002 blob_entry_key_bytes, &blob_entry_value_bytes, &found); |
| 4003 if (s.ok() && found) { |
| 4002 std::vector<IndexedDBBlobInfo> blob_info; | 4004 std::vector<IndexedDBBlobInfo> blob_info; |
| 4003 if (!DecodeBlobData(db_iter->Value().as_string(), &blob_info)) { | 4005 if (!DecodeBlobData(blob_entry_value_bytes, &blob_info)) { |
| 4004 INTERNAL_READ_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD); | 4006 INTERNAL_READ_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD); |
| 4005 transaction_ = NULL; | 4007 transaction_ = NULL; |
| 4006 return false; | 4008 return false; |
| 4007 } | 4009 } |
| 4008 std::vector<IndexedDBBlobInfo>::iterator blob_info_iter; | 4010 std::vector<IndexedDBBlobInfo>::iterator blob_info_iter; |
| 4009 for (blob_info_iter = blob_info.begin(); | 4011 for (blob_info_iter = blob_info.begin(); |
| 4010 blob_info_iter != blob_info.end(); | 4012 blob_info_iter != blob_info.end(); |
| 4011 ++blob_info_iter) | 4013 ++blob_info_iter) |
| 4012 blobs_to_remove_.push_back( | 4014 blobs_to_remove_.push_back( |
| 4013 std::make_pair(database_id_, blob_info_iter->key())); | 4015 std::make_pair(database_id_, blob_info_iter->key())); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4294 int64_t size, | 4296 int64_t size, |
| 4295 base::Time last_modified) | 4297 base::Time last_modified) |
| 4296 : is_file_(true), | 4298 : is_file_(true), |
| 4297 file_path_(file_path), | 4299 file_path_(file_path), |
| 4298 key_(key), | 4300 key_(key), |
| 4299 size_(size), | 4301 size_(size), |
| 4300 last_modified_(last_modified) { | 4302 last_modified_(last_modified) { |
| 4301 } | 4303 } |
| 4302 | 4304 |
| 4303 } // namespace content | 4305 } // namespace content |
| OLD | NEW |