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

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

Issue 232343004: Pass blob info through from the IPC to the backing store on put. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge out Created 6 years, 8 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
« no previous file with comments | « no previous file | content/browser/indexed_db/indexed_db_backing_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
16 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
17 #include "content/browser/indexed_db/indexed_db.h" 18 #include "content/browser/indexed_db/indexed_db.h"
18 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" 19 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h"
20 #include "content/browser/indexed_db/indexed_db_blob_info.h"
19 #include "content/browser/indexed_db/indexed_db_metadata.h" 21 #include "content/browser/indexed_db/indexed_db_metadata.h"
20 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" 22 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h"
21 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" 23 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h"
22 #include "content/common/content_export.h" 24 #include "content/common/content_export.h"
23 #include "content/common/indexed_db/indexed_db_key.h" 25 #include "content/common/indexed_db/indexed_db_key.h"
24 #include "content/common/indexed_db/indexed_db_key_path.h" 26 #include "content/common/indexed_db/indexed_db_key_path.h"
25 #include "content/common/indexed_db/indexed_db_key_range.h" 27 #include "content/common/indexed_db/indexed_db_key_range.h"
26 #include "third_party/leveldatabase/src/include/leveldb/status.h" 28 #include "third_party/leveldatabase/src/include/leveldb/status.h"
27 #include "url/gurl.h" 29 #include "url/gurl.h"
30 #include "webkit/browser/blob/blob_data_handle.h"
28 31
29 namespace base { 32 namespace base {
30 class TaskRunner; 33 class TaskRunner;
31 } 34 }
32 35
33 namespace content { 36 namespace content {
34 37
35 class IndexedDBFactory; 38 class IndexedDBFactory;
36 class LevelDBComparator; 39 class LevelDBComparator;
37 class LevelDBDatabase; 40 class LevelDBDatabase;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 LevelDBFactory* leveldb_factory, 91 LevelDBFactory* leveldb_factory,
89 base::TaskRunner* task_runner); 92 base::TaskRunner* task_runner);
90 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( 93 static scoped_refptr<IndexedDBBackingStore> OpenInMemory(
91 const GURL& origin_url, 94 const GURL& origin_url,
92 base::TaskRunner* task_runner); 95 base::TaskRunner* task_runner);
93 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( 96 static scoped_refptr<IndexedDBBackingStore> OpenInMemory(
94 const GURL& origin_url, 97 const GURL& origin_url,
95 LevelDBFactory* level_db_factory, 98 LevelDBFactory* level_db_factory,
96 base::TaskRunner* task_runner); 99 base::TaskRunner* task_runner);
97 100
101 void GrantChildProcessPermissions(int child_process_id);
102
98 // Compact is public for testing. 103 // Compact is public for testing.
99 virtual void Compact(); 104 virtual void Compact();
100 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*); 105 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*);
101 virtual leveldb::Status GetIDBDatabaseMetaData( 106 virtual leveldb::Status GetIDBDatabaseMetaData(
102 const base::string16& name, 107 const base::string16& name,
103 IndexedDBDatabaseMetadata* metadata, 108 IndexedDBDatabaseMetadata* metadata,
104 bool* success) WARN_UNUSED_RESULT; 109 bool* success) WARN_UNUSED_RESULT;
105 virtual leveldb::Status CreateIDBDatabaseMetaData( 110 virtual leveldb::Status CreateIDBDatabaseMetaData(
106 const base::string16& name, 111 const base::string16& name,
107 const base::string16& version, 112 const base::string16& version,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 IndexedDBBackingStore::Transaction* transaction, 164 IndexedDBBackingStore::Transaction* transaction,
160 int64 database_id, 165 int64 database_id,
161 int64 object_store_id, 166 int64 object_store_id,
162 const IndexedDBKey& key, 167 const IndexedDBKey& key,
163 IndexedDBValue* record) WARN_UNUSED_RESULT; 168 IndexedDBValue* record) WARN_UNUSED_RESULT;
164 virtual leveldb::Status PutRecord( 169 virtual leveldb::Status PutRecord(
165 IndexedDBBackingStore::Transaction* transaction, 170 IndexedDBBackingStore::Transaction* transaction,
166 int64 database_id, 171 int64 database_id,
167 int64 object_store_id, 172 int64 object_store_id,
168 const IndexedDBKey& key, 173 const IndexedDBKey& key,
169 const IndexedDBValue& value, 174 IndexedDBValue& value,
175 ScopedVector<webkit_blob::BlobDataHandle>* handles,
170 RecordIdentifier* record) WARN_UNUSED_RESULT; 176 RecordIdentifier* record) WARN_UNUSED_RESULT;
171 virtual leveldb::Status ClearObjectStore( 177 virtual leveldb::Status ClearObjectStore(
172 IndexedDBBackingStore::Transaction* transaction, 178 IndexedDBBackingStore::Transaction* transaction,
173 int64 database_id, 179 int64 database_id,
174 int64 object_store_id) WARN_UNUSED_RESULT; 180 int64 object_store_id) WARN_UNUSED_RESULT;
175 virtual leveldb::Status DeleteRecord( 181 virtual leveldb::Status DeleteRecord(
176 IndexedDBBackingStore::Transaction* transaction, 182 IndexedDBBackingStore::Transaction* transaction,
177 int64 database_id, 183 int64 database_id,
178 int64 object_store_id, 184 int64 object_store_id,
179 const RecordIdentifier& record) WARN_UNUSED_RESULT; 185 const RecordIdentifier& record) WARN_UNUSED_RESULT;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 public: 339 public:
334 explicit Transaction(IndexedDBBackingStore* backing_store); 340 explicit Transaction(IndexedDBBackingStore* backing_store);
335 virtual ~Transaction(); 341 virtual ~Transaction();
336 virtual void Begin(); 342 virtual void Begin();
337 virtual leveldb::Status Commit(); 343 virtual leveldb::Status Commit();
338 virtual void Rollback(); 344 virtual void Rollback();
339 void Reset() { 345 void Reset() {
340 backing_store_ = NULL; 346 backing_store_ = NULL;
341 transaction_ = NULL; 347 transaction_ = NULL;
342 } 348 }
349 void PutBlobInfo(int64 database_id,
350 int64 object_store_id,
351 const std::string& key,
352 std::vector<IndexedDBBlobInfo>*,
353 ScopedVector<webkit_blob::BlobDataHandle>* handles);
343 354
344 LevelDBTransaction* transaction() { return transaction_; } 355 LevelDBTransaction* transaction() { return transaction_; }
345 356
346 private: 357 private:
358 class BlobChangeRecord {
359 public:
360 BlobChangeRecord(const std::string& key, int64 object_store_id);
361 ~BlobChangeRecord();
362 const std::string& key() const { return key_; }
363 int64 object_store_id() const { return object_store_id_; }
364 void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info);
365 std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; }
366 void SetHandles(ScopedVector<webkit_blob::BlobDataHandle>* handles);
367
368 private:
369 std::string key_;
370 int64 object_store_id_;
371 std::vector<IndexedDBBlobInfo> blob_info_;
372 ScopedVector<webkit_blob::BlobDataHandle> handles_;
373 };
374 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap;
375
347 IndexedDBBackingStore* backing_store_; 376 IndexedDBBackingStore* backing_store_;
348 scoped_refptr<LevelDBTransaction> transaction_; 377 scoped_refptr<LevelDBTransaction> transaction_;
378 BlobChangeMap blob_change_map_;
379 int64 database_id_;
349 }; 380 };
350 381
351 protected: 382 protected:
352 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, 383 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory,
353 const GURL& origin_url, 384 const GURL& origin_url,
385 const base::FilePath& blob_path,
354 scoped_ptr<LevelDBDatabase> db, 386 scoped_ptr<LevelDBDatabase> db,
355 scoped_ptr<LevelDBComparator> comparator, 387 scoped_ptr<LevelDBComparator> comparator,
356 base::TaskRunner* task_runner); 388 base::TaskRunner* task_runner);
357 virtual ~IndexedDBBackingStore(); 389 virtual ~IndexedDBBackingStore();
358 friend class base::RefCounted<IndexedDBBackingStore>; 390 friend class base::RefCounted<IndexedDBBackingStore>;
359 391
360 private: 392 private:
361 static scoped_refptr<IndexedDBBackingStore> Create( 393 static scoped_refptr<IndexedDBBackingStore> Create(
362 IndexedDBFactory* indexed_db_factory, 394 IndexedDBFactory* indexed_db_factory,
363 const GURL& origin_url, 395 const GURL& origin_url,
396 const base::FilePath& blob_path,
364 scoped_ptr<LevelDBDatabase> db, 397 scoped_ptr<LevelDBDatabase> db,
365 scoped_ptr<LevelDBComparator> comparator, 398 scoped_ptr<LevelDBComparator> comparator,
366 base::TaskRunner* task_runner); 399 base::TaskRunner* task_runner);
367 400
368 static bool ReadCorruptionInfo(const base::FilePath& path_base, 401 static bool ReadCorruptionInfo(const base::FilePath& path_base,
369 const GURL& origin_url, 402 const GURL& origin_url,
370 std::string& message); 403 std::string& message);
371 404
372 leveldb::Status FindKeyInIndex( 405 leveldb::Status FindKeyInIndex(
373 IndexedDBBackingStore::Transaction* transaction, 406 IndexedDBBackingStore::Transaction* transaction,
374 int64 database_id, 407 int64 database_id,
375 int64 object_store_id, 408 int64 object_store_id,
376 int64 index_id, 409 int64 index_id,
377 const IndexedDBKey& key, 410 const IndexedDBKey& key,
378 std::string* found_encoded_primary_key, 411 std::string* found_encoded_primary_key,
379 bool* found); 412 bool* found);
380 leveldb::Status GetIndexes(int64 database_id, 413 leveldb::Status GetIndexes(int64 database_id,
381 int64 object_store_id, 414 int64 object_store_id,
382 IndexedDBObjectStoreMetadata::IndexMap* map) 415 IndexedDBObjectStoreMetadata::IndexMap* map)
383 WARN_UNUSED_RESULT; 416 WARN_UNUSED_RESULT;
384 417
385 IndexedDBFactory* indexed_db_factory_; 418 IndexedDBFactory* indexed_db_factory_;
386 const GURL origin_url_; 419 const GURL origin_url_;
420 base::FilePath blob_path_;
387 421
388 // The origin identifier is a key prefix unique to the origin used in the 422 // The origin identifier is a key prefix unique to the origin used in the
389 // leveldb backing store to partition data by origin. It is a normalized 423 // leveldb backing store to partition data by origin. It is a normalized
390 // version of the origin URL with a versioning suffix appended, e.g. 424 // version of the origin URL with a versioning suffix appended, e.g.
391 // "http_localhost_81@1" Since only one origin is stored per backing store 425 // "http_localhost_81@1" Since only one origin is stored per backing store
392 // this is redundant but necessary for backwards compatibility; the suffix 426 // this is redundant but necessary for backwards compatibility; the suffix
393 // provides for future flexibility. 427 // provides for future flexibility.
394 const std::string origin_identifier_; 428 const std::string origin_identifier_;
395 base::TaskRunner* task_runner_; 429 base::TaskRunner* task_runner_;
430 std::set<int> child_process_ids_granted_;
396 431
397 scoped_ptr<LevelDBDatabase> db_; 432 scoped_ptr<LevelDBDatabase> db_;
398 scoped_ptr<LevelDBComparator> comparator_; 433 scoped_ptr<LevelDBComparator> comparator_;
399 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_ 434 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_
400 // will hold a reference to this backing store. 435 // will hold a reference to this backing store.
401 IndexedDBActiveBlobRegistry active_blob_registry_; 436 IndexedDBActiveBlobRegistry active_blob_registry_;
402 base::OneShotTimer<IndexedDBBackingStore> close_timer_; 437 base::OneShotTimer<IndexedDBBackingStore> close_timer_;
403 }; 438 };
404 439
405 } // namespace content 440 } // namespace content
406 441
407 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ 442 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/indexed_db/indexed_db_backing_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698