 Chromium Code Reviews
 Chromium Code Reviews Issue 240003011:
  Add blob-writing functionality [as yet un-called] to IDB's backend.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 240003011:
  Add blob-writing functionality [as yet un-called] to IDB's backend.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: content/browser/indexed_db/indexed_db_backing_store.h | 
| diff --git a/content/browser/indexed_db/indexed_db_backing_store.h b/content/browser/indexed_db/indexed_db_backing_store.h | 
| index 19f476e81183642947fff1eb0eed254af7634763..171c0d2d097b78be9a5e0046ee1ecff6d3bed6df 100644 | 
| --- a/content/browser/indexed_db/indexed_db_backing_store.h | 
| +++ b/content/browser/indexed_db/indexed_db_backing_store.h | 
| @@ -18,6 +18,7 @@ | 
| #include "content/browser/indexed_db/indexed_db.h" | 
| #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" | 
| #include "content/browser/indexed_db/indexed_db_blob_info.h" | 
| +#include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 
| #include "content/browser/indexed_db/indexed_db_metadata.h" | 
| #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 
| #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 
| @@ -33,6 +34,14 @@ namespace base { | 
| class TaskRunner; | 
| } | 
| +namespace fileapi { | 
| +class FileWriterDelegate; | 
| +} | 
| + | 
| +namespace net { | 
| +class URLRequestContext; | 
| +} | 
| + | 
| namespace content { | 
| class IndexedDBFactory; | 
| @@ -76,6 +85,7 @@ class CONTENT_EXPORT IndexedDBBackingStore | 
| IndexedDBFactory* indexed_db_factory, | 
| const GURL& origin_url, | 
| const base::FilePath& path_base, | 
| + net::URLRequestContext* request_context, | 
| blink::WebIDBDataLoss* data_loss, | 
| std::string* data_loss_message, | 
| bool* disk_full, | 
| @@ -85,6 +95,7 @@ class CONTENT_EXPORT IndexedDBBackingStore | 
| IndexedDBFactory* indexed_db_factory, | 
| const GURL& origin_url, | 
| const base::FilePath& path_base, | 
| + net::URLRequestContext* request_context, | 
| blink::WebIDBDataLoss* data_loss, | 
| std::string* data_loss_message, | 
| bool* disk_full, | 
| @@ -160,6 +171,13 @@ class CONTENT_EXPORT IndexedDBBackingStore | 
| DISALLOW_COPY_AND_ASSIGN(RecordIdentifier); | 
| }; | 
| + class BlobWriteCallback : public RefCounted<BlobWriteCallback> { | 
| + public: | 
| + virtual ~BlobWriteCallback() {} | 
| + virtual void DidSucceed() = 0; | 
| + virtual void DidFail() = 0; | 
| + }; | 
| + | 
| virtual leveldb::Status GetRecord( | 
| IndexedDBBackingStore::Transaction* transaction, | 
| int64 database_id, | 
| @@ -242,6 +260,8 @@ class CONTENT_EXPORT IndexedDBBackingStore | 
| // Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef. | 
| virtual void ReportBlobUnused(int64 database_id, int64 blob_key); | 
| + base::FilePath GetBlobFileName(int64 database_id, int64 key); | 
| + | 
| class Cursor { | 
| public: | 
| virtual ~Cursor(); | 
| @@ -354,6 +374,52 @@ class CONTENT_EXPORT IndexedDBBackingStore | 
| LevelDBTransaction* transaction() { return transaction_; } | 
| + // This holds a BlobEntryKey and the encoded IndexedDBBlobInfo vector stored | 
| + // under that key. | 
| + typedef std::vector<std::pair<BlobEntryKey, std::string> > | 
| + BlobEntryKeyValuePairVec; | 
| + | 
| + class WriteDescriptor { | 
| + public: | 
| + WriteDescriptor(const GURL& url, int64_t key); | 
| + WriteDescriptor(const base::FilePath& path, int64_t key); | 
| + | 
| + bool is_file() const { return is_file_; } | 
| + const GURL& url() const { | 
| + DCHECK(!is_file_); | 
| + return url_; | 
| + } | 
| + const base::FilePath& file_path() const { | 
| + DCHECK(is_file_); | 
| + return file_path_; | 
| + } | 
| + int64_t key() const { return key_; } | 
| + | 
| + private: | 
| + bool is_file_; | 
| + GURL url_; | 
| + base::FilePath file_path_; | 
| + int64_t key_; | 
| + }; | 
| + | 
| + class ChainedBlobWriter : public base::RefCounted<ChainedBlobWriter> { | 
| + public: | 
| + virtual void set_delegate( | 
| + scoped_ptr<fileapi::FileWriterDelegate> delegate) = 0; | 
| + | 
| + virtual void ReportWriteCompletion(bool succeeded, | 
| 
cmumford
2014/04/18 17:19:06
Nit: This class has a completion callback with a s
 
ericu
2014/04/21 20:54:19
Done; I'm not sure why I had that difference...it
 | 
| + int64 bytes_written) = 0; | 
| + | 
| + virtual void Abort() = 0; | 
| + | 
| + protected: | 
| + virtual ~ChainedBlobWriter() {} | 
| + friend class base::RefCounted<ChainedBlobWriter>; | 
| + }; | 
| + class ChainedBlobWriterImpl; | 
| 
cmumford
2014/04/18 17:19:06
ChainedBlobWriterImpl doesn't seem to be used in t
 
ericu
2014/04/21 20:54:19
It has to be declared as a member of 
IndexedDBBac
 | 
| + | 
| + typedef std::vector<WriteDescriptor> WriteDescriptorVec; | 
| + | 
| private: | 
| class BlobChangeRecord { | 
| public: | 
| @@ -371,29 +437,44 @@ class CONTENT_EXPORT IndexedDBBackingStore | 
| std::vector<IndexedDBBlobInfo> blob_info_; | 
| ScopedVector<webkit_blob::BlobDataHandle> handles_; | 
| }; | 
| + class BlobWriteCallbackWrapper; | 
| typedef std::map<std::string, BlobChangeRecord*> BlobChangeMap; | 
| + // The callback will be called eventually on success or failure. | 
| + void WriteNewBlobs(BlobEntryKeyValuePairVec& new_blob_entries, | 
| + WriteDescriptorVec& new_files_to_write, | 
| + scoped_refptr<BlobWriteCallback> callback); | 
| + | 
| IndexedDBBackingStore* backing_store_; | 
| scoped_refptr<LevelDBTransaction> transaction_; | 
| BlobChangeMap blob_change_map_; | 
| int64 database_id_; | 
| + scoped_refptr<ChainedBlobWriter> chained_blob_writer_; | 
| }; | 
| protected: | 
| IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, | 
| const GURL& origin_url, | 
| const base::FilePath& blob_path, | 
| + net::URLRequestContext* request_context, | 
| scoped_ptr<LevelDBDatabase> db, | 
| scoped_ptr<LevelDBComparator> comparator, | 
| base::TaskRunner* task_runner); | 
| virtual ~IndexedDBBackingStore(); | 
| friend class base::RefCounted<IndexedDBBackingStore>; | 
| + virtual bool WriteBlobFile( | 
| + int64 database_id, | 
| + const Transaction::WriteDescriptor& descriptor, | 
| + Transaction::ChainedBlobWriter* chained_blob_writer); | 
| + virtual bool RemoveBlobFile(int64 database_id, int64 key); | 
| + | 
| private: | 
| static scoped_refptr<IndexedDBBackingStore> Create( | 
| IndexedDBFactory* indexed_db_factory, | 
| const GURL& origin_url, | 
| const base::FilePath& blob_path, | 
| + net::URLRequestContext* request_context, | 
| scoped_ptr<LevelDBDatabase> db, | 
| scoped_ptr<LevelDBComparator> comparator, | 
| base::TaskRunner* task_runner); | 
| @@ -414,6 +495,7 @@ class CONTENT_EXPORT IndexedDBBackingStore | 
| int64 object_store_id, | 
| IndexedDBObjectStoreMetadata::IndexMap* map) | 
| WARN_UNUSED_RESULT; | 
| + bool RemoveBlobDirectory(int64 database_id); | 
| IndexedDBFactory* indexed_db_factory_; | 
| const GURL origin_url_; | 
| @@ -426,6 +508,8 @@ class CONTENT_EXPORT IndexedDBBackingStore | 
| // this is redundant but necessary for backwards compatibility; the suffix | 
| // provides for future flexibility. | 
| const std::string origin_identifier_; | 
| + | 
| + net::URLRequestContext* request_context_; | 
| base::TaskRunner* task_runner_; | 
| std::set<int> child_process_ids_granted_; |