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 #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 Loading... | |
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(); | 105 virtual std::vector<base::string16> GetDatabaseNames(); |
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 Loading... | |
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 public: | 332 public: |
327 explicit Transaction(IndexedDBBackingStore* backing_store); | 333 explicit Transaction(IndexedDBBackingStore* backing_store); |
328 virtual ~Transaction(); | 334 virtual ~Transaction(); |
329 virtual void Begin(); | 335 virtual void Begin(); |
330 virtual leveldb::Status Commit(); | 336 virtual leveldb::Status Commit(); |
331 virtual void Rollback(); | 337 virtual void Rollback(); |
332 void Reset() { | 338 void Reset() { |
333 backing_store_ = NULL; | 339 backing_store_ = NULL; |
334 transaction_ = NULL; | 340 transaction_ = NULL; |
335 } | 341 } |
342 void PutBlobInfo(int64 database_id, | |
343 int64 object_store_id, | |
344 const std::string& key, | |
345 std::vector<IndexedDBBlobInfo>*, | |
346 ScopedVector<webkit_blob::BlobDataHandle>* handles); | |
336 | 347 |
337 LevelDBTransaction* transaction() { return transaction_; } | 348 LevelDBTransaction* transaction() { return transaction_; } |
338 | 349 |
339 private: | 350 private: |
351 class BlobChangeRecord { | |
352 public: | |
353 BlobChangeRecord() {} | |
cmumford
2014/04/10 16:59:43
Initialize object_store_id_. My preference would b
ericu
2014/04/14 23:23:38
Done.
| |
354 void set_key(const std::string& key) { key_ = key; } | |
355 const std::string& key() const { return key_; } | |
356 void set_object_store_id(int64 object_store_id) { | |
cmumford
2014/04/10 16:59:43
Can possibly eliminate need for set_key() and set_
ericu
2014/04/14 23:23:38
Done. For future reference, the master CLs from w
| |
357 object_store_id_ = object_store_id; | |
358 } | |
359 int64 object_store_id() const { return object_store_id_; } | |
360 void SetBlobInfo(std::vector<IndexedDBBlobInfo>* blob_info); | |
361 std::vector<IndexedDBBlobInfo>& mutable_blob_info() { return blob_info_; } | |
362 void SetHandles(ScopedVector<webkit_blob::BlobDataHandle>* handles); | |
363 | |
364 private: | |
365 std::string key_; | |
366 int64 object_store_id_; | |
367 std::vector<IndexedDBBlobInfo> blob_info_; | |
368 ScopedVector<webkit_blob::BlobDataHandle> handles_; | |
369 }; | |
370 typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap; | |
371 | |
340 IndexedDBBackingStore* backing_store_; | 372 IndexedDBBackingStore* backing_store_; |
341 scoped_refptr<LevelDBTransaction> transaction_; | 373 scoped_refptr<LevelDBTransaction> transaction_; |
374 BlobChangeMap blob_change_map_; | |
375 int64 database_id_; | |
342 }; | 376 }; |
343 | 377 |
344 protected: | 378 protected: |
345 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, | 379 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, |
346 const GURL& origin_url, | 380 const GURL& origin_url, |
381 const base::FilePath& blob_path, | |
347 scoped_ptr<LevelDBDatabase> db, | 382 scoped_ptr<LevelDBDatabase> db, |
348 scoped_ptr<LevelDBComparator> comparator, | 383 scoped_ptr<LevelDBComparator> comparator, |
349 base::TaskRunner* task_runner); | 384 base::TaskRunner* task_runner); |
350 virtual ~IndexedDBBackingStore(); | 385 virtual ~IndexedDBBackingStore(); |
351 friend class base::RefCounted<IndexedDBBackingStore>; | 386 friend class base::RefCounted<IndexedDBBackingStore>; |
352 | 387 |
353 private: | 388 private: |
354 static scoped_refptr<IndexedDBBackingStore> Create( | 389 static scoped_refptr<IndexedDBBackingStore> Create( |
355 IndexedDBFactory* indexed_db_factory, | 390 IndexedDBFactory* indexed_db_factory, |
356 const GURL& origin_url, | 391 const GURL& origin_url, |
392 const base::FilePath& blob_path, | |
357 scoped_ptr<LevelDBDatabase> db, | 393 scoped_ptr<LevelDBDatabase> db, |
358 scoped_ptr<LevelDBComparator> comparator, | 394 scoped_ptr<LevelDBComparator> comparator, |
359 base::TaskRunner* task_runner); | 395 base::TaskRunner* task_runner); |
360 | 396 |
361 static bool ReadCorruptionInfo(const base::FilePath& path_base, | 397 static bool ReadCorruptionInfo(const base::FilePath& path_base, |
362 const GURL& origin_url, | 398 const GURL& origin_url, |
363 std::string& message); | 399 std::string& message); |
364 | 400 |
365 leveldb::Status FindKeyInIndex( | 401 leveldb::Status FindKeyInIndex( |
366 IndexedDBBackingStore::Transaction* transaction, | 402 IndexedDBBackingStore::Transaction* transaction, |
367 int64 database_id, | 403 int64 database_id, |
368 int64 object_store_id, | 404 int64 object_store_id, |
369 int64 index_id, | 405 int64 index_id, |
370 const IndexedDBKey& key, | 406 const IndexedDBKey& key, |
371 std::string* found_encoded_primary_key, | 407 std::string* found_encoded_primary_key, |
372 bool* found); | 408 bool* found); |
373 leveldb::Status GetIndexes(int64 database_id, | 409 leveldb::Status GetIndexes(int64 database_id, |
374 int64 object_store_id, | 410 int64 object_store_id, |
375 IndexedDBObjectStoreMetadata::IndexMap* map) | 411 IndexedDBObjectStoreMetadata::IndexMap* map) |
376 WARN_UNUSED_RESULT; | 412 WARN_UNUSED_RESULT; |
377 | 413 |
378 IndexedDBFactory* indexed_db_factory_; | 414 IndexedDBFactory* indexed_db_factory_; |
379 const GURL origin_url_; | 415 const GURL origin_url_; |
416 base::FilePath blob_path_; | |
380 | 417 |
381 // The origin identifier is a key prefix unique to the origin used in the | 418 // The origin identifier is a key prefix unique to the origin used in the |
382 // leveldb backing store to partition data by origin. It is a normalized | 419 // leveldb backing store to partition data by origin. It is a normalized |
383 // version of the origin URL with a versioning suffix appended, e.g. | 420 // version of the origin URL with a versioning suffix appended, e.g. |
384 // "http_localhost_81@1" Since only one origin is stored per backing store | 421 // "http_localhost_81@1" Since only one origin is stored per backing store |
385 // this is redundant but necessary for backwards compatibility; the suffix | 422 // this is redundant but necessary for backwards compatibility; the suffix |
386 // provides for future flexibility. | 423 // provides for future flexibility. |
387 const std::string origin_identifier_; | 424 const std::string origin_identifier_; |
388 base::TaskRunner* task_runner_; | 425 base::TaskRunner* task_runner_; |
426 std::set<int> child_process_ids_granted_; | |
389 | 427 |
390 scoped_ptr<LevelDBDatabase> db_; | 428 scoped_ptr<LevelDBDatabase> db_; |
391 scoped_ptr<LevelDBComparator> comparator_; | 429 scoped_ptr<LevelDBComparator> comparator_; |
392 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_ | 430 // Whenever blobs are registered in active_blob_registry_, indexed_db_factory_ |
393 // will hold a reference to this backing store. | 431 // will hold a reference to this backing store. |
394 IndexedDBActiveBlobRegistry active_blob_registry_; | 432 IndexedDBActiveBlobRegistry active_blob_registry_; |
395 base::OneShotTimer<IndexedDBBackingStore> close_timer_; | 433 base::OneShotTimer<IndexedDBBackingStore> close_timer_; |
396 }; | 434 }; |
397 | 435 |
398 } // namespace content | 436 } // namespace content |
399 | 437 |
400 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 438 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
OLD | NEW |