Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: content/browser/indexed_db/indexed_db_backing_store.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 17 matching lines...) Expand all
28 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" 28 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h"
29 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" 29 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h"
30 #include "content/common/indexed_db/indexed_db_key.h" 30 #include "content/common/indexed_db/indexed_db_key.h"
31 #include "content/common/indexed_db/indexed_db_key_path.h" 31 #include "content/common/indexed_db/indexed_db_key_path.h"
32 #include "content/common/indexed_db/indexed_db_key_range.h" 32 #include "content/common/indexed_db/indexed_db_key_range.h"
33 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
34 #include "net/url_request/url_request_context.h" 34 #include "net/url_request/url_request_context.h"
35 #include "third_party/WebKit/public/platform/WebIDBTypes.h" 35 #include "third_party/WebKit/public/platform/WebIDBTypes.h"
36 #include "third_party/WebKit/public/web/WebSerializedScriptValueVersion.h" 36 #include "third_party/WebKit/public/web/WebSerializedScriptValueVersion.h"
37 #include "third_party/leveldatabase/env_chromium.h" 37 #include "third_party/leveldatabase/env_chromium.h"
38 #include "webkit/browser/blob/blob_data_handle.h" 38 #include "storage/browser/blob/blob_data_handle.h"
39 #include "webkit/browser/fileapi/file_stream_writer.h" 39 #include "storage/browser/fileapi/file_stream_writer.h"
40 #include "webkit/browser/fileapi/file_writer_delegate.h" 40 #include "storage/browser/fileapi/file_writer_delegate.h"
41 #include "webkit/browser/fileapi/local_file_stream_writer.h" 41 #include "storage/browser/fileapi/local_file_stream_writer.h"
42 #include "webkit/common/database/database_identifier.h" 42 #include "storage/common/database/database_identifier.h"
43 43
44 using base::FilePath; 44 using base::FilePath;
45 using base::StringPiece; 45 using base::StringPiece;
46 using fileapi::FileWriterDelegate; 46 using storage::FileWriterDelegate;
47 47
48 namespace content { 48 namespace content {
49 49
50 namespace { 50 namespace {
51 51
52 FilePath GetBlobDirectoryName(const FilePath& pathBase, int64 database_id) { 52 FilePath GetBlobDirectoryName(const FilePath& pathBase, int64 database_id) {
53 return pathBase.AppendASCII(base::StringPrintf("%" PRIx64, database_id)); 53 return pathBase.AppendASCII(base::StringPrintf("%" PRIx64, database_id));
54 } 54 }
55 55
56 FilePath GetBlobDirectoryNameForKey(const FilePath& pathBase, 56 FilePath GetBlobDirectoryNameForKey(const FilePath& pathBase,
(...skipping 1837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 *new_version_number = version; 1894 *new_version_number = version;
1895 return s; 1895 return s;
1896 } 1896 }
1897 1897
1898 leveldb::Status IndexedDBBackingStore::PutRecord( 1898 leveldb::Status IndexedDBBackingStore::PutRecord(
1899 IndexedDBBackingStore::Transaction* transaction, 1899 IndexedDBBackingStore::Transaction* transaction,
1900 int64 database_id, 1900 int64 database_id,
1901 int64 object_store_id, 1901 int64 object_store_id,
1902 const IndexedDBKey& key, 1902 const IndexedDBKey& key,
1903 IndexedDBValue* value, 1903 IndexedDBValue* value,
1904 ScopedVector<webkit_blob::BlobDataHandle>* handles, 1904 ScopedVector<storage::BlobDataHandle>* handles,
1905 RecordIdentifier* record_identifier) { 1905 RecordIdentifier* record_identifier) {
1906 IDB_TRACE("IndexedDBBackingStore::PutRecord"); 1906 IDB_TRACE("IndexedDBBackingStore::PutRecord");
1907 if (!KeyPrefix::ValidIds(database_id, object_store_id)) 1907 if (!KeyPrefix::ValidIds(database_id, object_store_id))
1908 return InvalidDBKeyStatus(); 1908 return InvalidDBKeyStatus();
1909 DCHECK(key.IsValid()); 1909 DCHECK(key.IsValid());
1910 1910
1911 LevelDBTransaction* leveldb_transaction = transaction->transaction(); 1911 LevelDBTransaction* leveldb_transaction = transaction->transaction();
1912 int64 version = -1; 1912 int64 version = -1;
1913 leveldb::Status s = GetNewVersionNumber( 1913 leveldb::Status s = GetNewVersionNumber(
1914 leveldb_transaction, database_id, object_store_id, &version); 1914 leveldb_transaction, database_id, object_store_id, &version);
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 ReportWriteCompletion, 2307 ReportWriteCompletion,
2308 chained_blob_writer_, 2308 chained_blob_writer_,
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<fileapi::FileStreamWriter> writer( 2317 scoped_ptr<storage::FileStreamWriter> writer(
2318 fileapi::FileStreamWriter::CreateForLocalFile( 2318 storage::FileStreamWriter::CreateForLocalFile(
2319 task_runner_, file_path, 0, 2319 task_runner_,
2320 fileapi::FileStreamWriter::CREATE_NEW_FILE)); 2320 file_path,
2321 0,
2322 storage::FileStreamWriter::CREATE_NEW_FILE));
2321 scoped_ptr<FileWriterDelegate> delegate( 2323 scoped_ptr<FileWriterDelegate> delegate(
2322 new FileWriterDelegate(writer.Pass(), 2324 new FileWriterDelegate(writer.Pass(),
2323 FileWriterDelegate::FLUSH_ON_COMPLETION)); 2325 FileWriterDelegate::FLUSH_ON_COMPLETION));
2324 2326
2325 DCHECK(blob_url.is_valid()); 2327 DCHECK(blob_url.is_valid());
2326 scoped_ptr<net::URLRequest> blob_request(request_context->CreateRequest( 2328 scoped_ptr<net::URLRequest> blob_request(request_context->CreateRequest(
2327 blob_url, net::DEFAULT_PRIORITY, delegate.get(), NULL)); 2329 blob_url, net::DEFAULT_PRIORITY, delegate.get(), NULL));
2328 2330
2329 delegate->Start(blob_request.Pass(), 2331 delegate->Start(blob_request.Pass(),
2330 base::Bind(&LocalWriteClosure::Run, this)); 2332 base::Bind(&LocalWriteClosure::Run, this));
(...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after
4194 } 4196 }
4195 4197
4196 void IndexedDBBackingStore::BlobChangeRecord::SetBlobInfo( 4198 void IndexedDBBackingStore::BlobChangeRecord::SetBlobInfo(
4197 std::vector<IndexedDBBlobInfo>* blob_info) { 4199 std::vector<IndexedDBBlobInfo>* blob_info) {
4198 blob_info_.clear(); 4200 blob_info_.clear();
4199 if (blob_info) 4201 if (blob_info)
4200 blob_info_.swap(*blob_info); 4202 blob_info_.swap(*blob_info);
4201 } 4203 }
4202 4204
4203 void IndexedDBBackingStore::BlobChangeRecord::SetHandles( 4205 void IndexedDBBackingStore::BlobChangeRecord::SetHandles(
4204 ScopedVector<webkit_blob::BlobDataHandle>* handles) { 4206 ScopedVector<storage::BlobDataHandle>* handles) {
4205 handles_.clear(); 4207 handles_.clear();
4206 if (handles) 4208 if (handles)
4207 handles_.swap(*handles); 4209 handles_.swap(*handles);
4208 } 4210 }
4209 4211
4210 scoped_ptr<IndexedDBBackingStore::BlobChangeRecord> 4212 scoped_ptr<IndexedDBBackingStore::BlobChangeRecord>
4211 IndexedDBBackingStore::BlobChangeRecord::Clone() const { 4213 IndexedDBBackingStore::BlobChangeRecord::Clone() const {
4212 scoped_ptr<IndexedDBBackingStore::BlobChangeRecord> record( 4214 scoped_ptr<IndexedDBBackingStore::BlobChangeRecord> record(
4213 new BlobChangeRecord(key_, object_store_id_)); 4215 new BlobChangeRecord(key_, object_store_id_));
4214 record->blob_info_ = blob_info_; 4216 record->blob_info_ = blob_info_;
4215 4217
4216 ScopedVector<webkit_blob::BlobDataHandle>::const_iterator iter; 4218 ScopedVector<storage::BlobDataHandle>::const_iterator iter;
4217 for (iter = handles_.begin(); iter != handles_.end(); ++iter) 4219 for (iter = handles_.begin(); iter != handles_.end(); ++iter)
4218 record->handles_.push_back(new webkit_blob::BlobDataHandle(**iter)); 4220 record->handles_.push_back(new storage::BlobDataHandle(**iter));
4219 return record.Pass(); 4221 return record.Pass();
4220 } 4222 }
4221 4223
4222 leveldb::Status IndexedDBBackingStore::Transaction::PutBlobInfoIfNeeded( 4224 leveldb::Status IndexedDBBackingStore::Transaction::PutBlobInfoIfNeeded(
4223 int64 database_id, 4225 int64 database_id,
4224 int64 object_store_id, 4226 int64 object_store_id,
4225 const std::string& object_store_data_key, 4227 const std::string& object_store_data_key,
4226 std::vector<IndexedDBBlobInfo>* blob_info, 4228 std::vector<IndexedDBBlobInfo>* blob_info,
4227 ScopedVector<webkit_blob::BlobDataHandle>* handles) { 4229 ScopedVector<storage::BlobDataHandle>* handles) {
4228 if (!blob_info || blob_info->empty()) { 4230 if (!blob_info || blob_info->empty()) {
4229 blob_change_map_.erase(object_store_data_key); 4231 blob_change_map_.erase(object_store_data_key);
4230 incognito_blob_map_.erase(object_store_data_key); 4232 incognito_blob_map_.erase(object_store_data_key);
4231 4233
4232 BlobEntryKey blob_entry_key; 4234 BlobEntryKey blob_entry_key;
4233 StringPiece leveldb_key_piece(object_store_data_key); 4235 StringPiece leveldb_key_piece(object_store_data_key);
4234 if (!BlobEntryKey::FromObjectStoreDataKey(&leveldb_key_piece, 4236 if (!BlobEntryKey::FromObjectStoreDataKey(&leveldb_key_piece,
4235 &blob_entry_key)) { 4237 &blob_entry_key)) {
4236 NOTREACHED(); 4238 NOTREACHED();
4237 return InternalInconsistencyStatus(); 4239 return InternalInconsistencyStatus();
(...skipping 14 matching lines...) Expand all
4252 4254
4253 // This is storing an info, even if empty, even if the previous key had no blob 4255 // This is storing an info, even if empty, even if the previous key had no blob
4254 // info that we know of. It duplicates a bunch of information stored in the 4256 // info that we know of. It duplicates a bunch of information stored in the
4255 // leveldb transaction, but only w.r.t. the user keys altered--we don't keep the 4257 // leveldb transaction, but only w.r.t. the user keys altered--we don't keep the
4256 // changes to exists or index keys here. 4258 // changes to exists or index keys here.
4257 void IndexedDBBackingStore::Transaction::PutBlobInfo( 4259 void IndexedDBBackingStore::Transaction::PutBlobInfo(
4258 int64 database_id, 4260 int64 database_id,
4259 int64 object_store_id, 4261 int64 object_store_id,
4260 const std::string& object_store_data_key, 4262 const std::string& object_store_data_key,
4261 std::vector<IndexedDBBlobInfo>* blob_info, 4263 std::vector<IndexedDBBlobInfo>* blob_info,
4262 ScopedVector<webkit_blob::BlobDataHandle>* handles) { 4264 ScopedVector<storage::BlobDataHandle>* handles) {
4263 DCHECK_GT(object_store_data_key.size(), 0UL); 4265 DCHECK_GT(object_store_data_key.size(), 0UL);
4264 if (database_id_ < 0) 4266 if (database_id_ < 0)
4265 database_id_ = database_id; 4267 database_id_ = database_id;
4266 DCHECK_EQ(database_id_, database_id); 4268 DCHECK_EQ(database_id_, database_id);
4267 4269
4268 BlobChangeMap::iterator it = blob_change_map_.find(object_store_data_key); 4270 BlobChangeMap::iterator it = blob_change_map_.find(object_store_data_key);
4269 BlobChangeRecord* record = NULL; 4271 BlobChangeRecord* record = NULL;
4270 if (it == blob_change_map_.end()) { 4272 if (it == blob_change_map_.end()) {
4271 record = new BlobChangeRecord(object_store_data_key, object_store_id); 4273 record = new BlobChangeRecord(object_store_data_key, object_store_id);
4272 blob_change_map_[object_store_data_key] = record; 4274 blob_change_map_[object_store_data_key] = record;
(...skipping 19 matching lines...) Expand all
4292 int64_t size, 4294 int64_t size,
4293 base::Time last_modified) 4295 base::Time last_modified)
4294 : is_file_(true), 4296 : is_file_(true),
4295 file_path_(file_path), 4297 file_path_(file_path),
4296 key_(key), 4298 key_(key),
4297 size_(size), 4299 size_(size),
4298 last_modified_(last_modified) { 4300 last_modified_(last_modified) {
4299 } 4301 }
4300 4302
4301 } // namespace content 4303 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_backing_store.h ('k') | content/browser/indexed_db/indexed_db_backing_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698