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

Unified Diff: content/browser/indexed_db/indexed_db_backing_store.h

Issue 240003011: Add blob-writing functionality [as yet un-called] to IDB's backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Factor out GetBlobFilenameForKey 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 side-by-side diff with in-line comments
Download patch
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..8b83875e75044140854e4d5461ded8a72ca3c77f 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,12 @@ class CONTENT_EXPORT IndexedDBBackingStore
DISALLOW_COPY_AND_ASSIGN(RecordIdentifier);
};
+ class BlobWriteCallback : public RefCounted<BlobWriteCallback> {
+ public:
+ virtual ~BlobWriteCallback() {}
+ virtual void Run(bool succeeded) = 0;
+ };
+
virtual leveldb::Status GetRecord(
IndexedDBBackingStore::Transaction* transaction,
int64 database_id,
@@ -242,6 +259,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 +373,53 @@ 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;
+
+ // TODO(ericu): Add a reason in the event of failure.
+ virtual void ReportWriteCompletion(bool succeeded,
+ int64 bytes_written) = 0;
+
+ virtual void Abort() = 0;
+
+ protected:
+ virtual ~ChainedBlobWriter() {}
+ friend class base::RefCounted<ChainedBlobWriter>;
+ };
+ class ChainedBlobWriterImpl;
+
+ 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_;

Powered by Google App Engine
This is Rietveld 408576698