diff options
author | ericu@chromium.org <ericu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-14 19:04:35 +0000 |
---|---|---|
committer | ericu@chromium.org <ericu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-14 19:04:35 +0000 |
commit | e62fe0db25fc82dbb2d29de746b0f0a0fde37651 (patch) | |
tree | 07a75dc50407e9f264d171b551d2cf53d1ccacb4 /content/browser/indexed_db | |
parent | 9593d731d76b1356687151391d8c9902493bbbd8 (diff) | |
download | chromium_src-e62fe0db25fc82dbb2d29de746b0f0a0fde37651.zip chromium_src-e62fe0db25fc82dbb2d29de746b0f0a0fde37651.tar.gz chromium_src-e62fe0db25fc82dbb2d29de746b0f0a0fde37651.tar.bz2 |
Plumb request_context, ipc_process_id, and blob_storage_context through to where they'll be needed.
BUG=108012
Review URL: https://codereview.chromium.org/229623002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263693 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/indexed_db')
6 files changed, 123 insertions, 21 deletions
diff --git a/content/browser/indexed_db/indexed_db_dispatcher_host.cc b/content/browser/indexed_db/indexed_db_dispatcher_host.cc index b627393..5366443 100644 --- a/content/browser/indexed_db/indexed_db_dispatcher_host.cc +++ b/content/browser/indexed_db/indexed_db_dispatcher_host.cc @@ -26,6 +26,7 @@ #include "content/public/common/result_codes.h" #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" #include "url/gurl.h" +#include "webkit/browser/blob/blob_storage_context.h" #include "webkit/browser/database/database_util.h" #include "webkit/common/database/database_identifier.h" @@ -35,11 +36,33 @@ using blink::WebIDBKey; namespace content { IndexedDBDispatcherHost::IndexedDBDispatcherHost( - IndexedDBContextImpl* indexed_db_context) + int ipc_process_id, + net::URLRequestContextGetter* request_context_getter, + IndexedDBContextImpl* indexed_db_context, + ChromeBlobStorageContext* blob_storage_context) : BrowserMessageFilter(IndexedDBMsgStart), + request_context_getter_(request_context_getter), + request_context_(NULL), indexed_db_context_(indexed_db_context), + blob_storage_context_(blob_storage_context), database_dispatcher_host_(new DatabaseDispatcherHost(this)), - cursor_dispatcher_host_(new CursorDispatcherHost(this)) { + cursor_dispatcher_host_(new CursorDispatcherHost(this)), + ipc_process_id_(ipc_process_id) { + DCHECK(indexed_db_context_); +} + +IndexedDBDispatcherHost::IndexedDBDispatcherHost( + int ipc_process_id, + net::URLRequestContext* request_context, + IndexedDBContextImpl* indexed_db_context, + ChromeBlobStorageContext* blob_storage_context) + : BrowserMessageFilter(IndexedDBMsgStart), + request_context_(request_context), + indexed_db_context_(indexed_db_context), + blob_storage_context_(blob_storage_context), + database_dispatcher_host_(new DatabaseDispatcherHost(this)), + cursor_dispatcher_host_(new CursorDispatcherHost(this)), + ipc_process_id_(ipc_process_id) { DCHECK(indexed_db_context_); } @@ -47,6 +70,17 @@ IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { STLDeleteValues(&blob_data_handle_map_); } +void IndexedDBDispatcherHost::OnChannelConnected(int32 peer_pid) { + BrowserMessageFilter::OnChannelConnected(peer_pid); + + if (request_context_getter_.get()) { + DCHECK(!request_context_); + request_context_ = request_context_getter_->GetURLRequestContext(); + request_context_getter_ = NULL; + DCHECK(request_context_); + } +} + void IndexedDBDispatcherHost::OnChannelClosing() { bool success = indexed_db_context_->TaskRunner()->PostTask( FROM_HERE, @@ -176,7 +210,7 @@ uint32 IndexedDBDispatcherHost::TransactionIdToProcessId( void IndexedDBDispatcherHost::HoldBlobDataHandle( const std::string& uuid, scoped_ptr<webkit_blob::BlobDataHandle>& blob_data_handle) { - DCHECK(ContainsKey(blob_data_handle_map_, uuid)); + DCHECK(!ContainsKey(blob_data_handle_map_, uuid)); blob_data_handle_map_[uuid] = blob_data_handle.release(); } @@ -276,11 +310,12 @@ void IndexedDBDispatcherHost::OnIDBFactoryOpen( this, params.ipc_thread_id, params.ipc_database_callbacks_id); IndexedDBPendingConnection connection(callbacks, database_callbacks, - 0 /* TODO(ericu) ipc_process_id */, + ipc_process_id_, host_transaction_id, params.version); + DCHECK(request_context_); Context()->GetIDBFactory()->Open( - params.name, connection, origin_url, indexed_db_path); + params.name, connection, request_context_, origin_url, indexed_db_path); } void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( @@ -289,8 +324,10 @@ void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( GURL origin_url = webkit_database::GetOriginFromIdentifier(params.database_identifier); base::FilePath indexed_db_path = indexed_db_context_->data_path(); + DCHECK(request_context_); Context()->GetIDBFactory()->DeleteDatabase( params.name, + request_context_, new IndexedDBCallbacks( this, params.ipc_thread_id, params.ipc_callbacks_id), origin_url, diff --git a/content/browser/indexed_db/indexed_db_dispatcher_host.h b/content/browser/indexed_db/indexed_db_dispatcher_host.h index 9c99dc5..de54ae1 100644 --- a/content/browser/indexed_db/indexed_db_dispatcher_host.h +++ b/content/browser/indexed_db/indexed_db_dispatcher_host.h @@ -11,7 +11,9 @@ #include "base/basictypes.h" #include "base/id_map.h" #include "base/memory/ref_counted.h" +#include "content/browser/fileapi/chrome_blob_storage_context.h" #include "content/public/browser/browser_message_filter.h" +#include "net/url_request/url_request_context_getter.h" #include "url/gurl.h" #include "webkit/browser/blob/blob_data_handle.h" @@ -42,12 +44,20 @@ struct IndexedDBDatabaseMetadata; class IndexedDBDispatcherHost : public BrowserMessageFilter { public: // Only call the constructor from the UI thread. - explicit IndexedDBDispatcherHost(IndexedDBContextImpl* indexed_db_context); + IndexedDBDispatcherHost(int ipc_process_id, + net::URLRequestContextGetter* request_context_getter, + IndexedDBContextImpl* indexed_db_context, + ChromeBlobStorageContext* blob_storage_context); + IndexedDBDispatcherHost(int ipc_process_id, + net::URLRequestContext* request_context, + IndexedDBContextImpl* indexed_db_context, + ChromeBlobStorageContext* blob_storage_context); static ::IndexedDBDatabaseMetadata ConvertMetadata( const content::IndexedDBDatabaseMetadata& metadata); // BrowserMessageFilter implementation. + virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; virtual void OnChannelClosing() OVERRIDE; virtual void OnDestruct() const OVERRIDE; virtual base::TaskRunner* OverrideTaskRunnerForMessage( @@ -59,6 +69,9 @@ class IndexedDBDispatcherHost : public BrowserMessageFilter { // A shortcut for accessing our context. IndexedDBContextImpl* Context() { return indexed_db_context_; } + webkit_blob::BlobStorageContext* blob_storage_context() const { + return blob_storage_context_->context(); + } // IndexedDBCallbacks call these methods to add the results into the // applicable map. See below for more details. @@ -236,7 +249,12 @@ class IndexedDBDispatcherHost : public BrowserMessageFilter { RefIDMap<IndexedDBCursor> map_; }; + // The getter holds the context until OnChannelConnected() can be called from + // the IO thread, which will extract the net::URLRequestContext from it. + scoped_refptr<net::URLRequestContextGetter> request_context_getter_; + net::URLRequestContext* request_context_; scoped_refptr<IndexedDBContextImpl> indexed_db_context_; + scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; typedef std::map<std::string, webkit_blob::BlobDataHandle*> BlobDataHandleMap; BlobDataHandleMap blob_data_handle_map_; @@ -245,6 +263,9 @@ class IndexedDBDispatcherHost : public BrowserMessageFilter { scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; + // Used to set file permissions for blob storage. + int ipc_process_id_; + DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); }; diff --git a/content/browser/indexed_db/indexed_db_factory.cc b/content/browser/indexed_db/indexed_db_factory.cc index e3a415a..e214785 100644 --- a/content/browser/indexed_db/indexed_db_factory.cc +++ b/content/browser/indexed_db/indexed_db_factory.cc @@ -180,6 +180,7 @@ void IndexedDBFactory::GetDatabaseNames( scoped_refptr<IndexedDBBackingStore> backing_store = OpenBackingStore(origin_url, data_directory, + NULL /* request_context */, &data_loss, &data_loss_message, &disk_full); @@ -198,6 +199,7 @@ void IndexedDBFactory::GetDatabaseNames( void IndexedDBFactory::DeleteDatabase( const base::string16& name, + net::URLRequestContext* request_context, scoped_refptr<IndexedDBCallbacks> callbacks, const GURL& origin_url, const base::FilePath& data_directory) { @@ -218,6 +220,7 @@ void IndexedDBFactory::DeleteDatabase( scoped_refptr<IndexedDBBackingStore> backing_store = OpenBackingStore(origin_url, data_directory, + request_context, &data_loss, &data_loss_message, &disk_full); @@ -306,6 +309,7 @@ bool IndexedDBFactory::IsBackingStorePendingClose(const GURL& origin_url) scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( const GURL& origin_url, const base::FilePath& data_directory, + net::URLRequestContext* request_context, blink::WebIDBDataLoss* data_loss, std::string* data_loss_message, bool* disk_full) { @@ -339,7 +343,7 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( // All backing stores associated with this factory should be of the same // type. - DCHECK(session_only_backing_stores_.empty() || open_in_memory); + DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); return backing_store; } @@ -349,6 +353,7 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( void IndexedDBFactory::Open(const base::string16& name, const IndexedDBPendingConnection& connection, + net::URLRequestContext* request_context, const GURL& origin_url, const base::FilePath& data_directory) { IDB_TRACE("IndexedDBFactory::Open"); @@ -364,6 +369,7 @@ void IndexedDBFactory::Open(const base::string16& name, scoped_refptr<IndexedDBBackingStore> backing_store = OpenBackingStore(origin_url, data_directory, + request_context, &data_loss, &data_loss_message, &disk_full); diff --git a/content/browser/indexed_db/indexed_db_factory.h b/content/browser/indexed_db/indexed_db_factory.h index 3b5a947..77f1e65 100644 --- a/content/browser/indexed_db/indexed_db_factory.h +++ b/content/browser/indexed_db/indexed_db_factory.h @@ -18,6 +18,10 @@ #include "content/common/content_export.h" #include "url/gurl.h" +namespace net { +class URLRequestContext; +} + namespace content { class IndexedDBBackingStore; @@ -32,7 +36,6 @@ class CONTENT_EXPORT IndexedDBFactory explicit IndexedDBFactory(IndexedDBContextImpl* context); - // Notifications from weak pointers. void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, bool forcedClose); @@ -41,10 +44,12 @@ class CONTENT_EXPORT IndexedDBFactory const base::FilePath& data_directory); void Open(const base::string16& name, const IndexedDBPendingConnection& connection, + net::URLRequestContext* request_context, const GURL& origin_url, const base::FilePath& data_directory); void DeleteDatabase(const base::string16& name, + net::URLRequestContext* request_context, scoped_refptr<IndexedDBCallbacks> callbacks, const GURL& origin_url, const base::FilePath& data_directory); @@ -78,12 +83,14 @@ class CONTENT_EXPORT IndexedDBFactory virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( const GURL& origin_url, const base::FilePath& data_directory, + net::URLRequestContext* request_context, blink::WebIDBDataLoss* data_loss, std::string* data_loss_reason, bool* disk_full); void ReleaseBackingStore(const GURL& origin_url, bool immediate); void CloseBackingStore(const GURL& origin_url); + IndexedDBContextImpl* context() const { return context_; } private: FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, diff --git a/content/browser/indexed_db/indexed_db_factory_unittest.cc b/content/browser/indexed_db/indexed_db_factory_unittest.cc index 1290856..8361c36 100644 --- a/content/browser/indexed_db/indexed_db_factory_unittest.cc +++ b/content/browser/indexed_db/indexed_db_factory_unittest.cc @@ -39,6 +39,7 @@ class MockIDBFactory : public IndexedDBFactory { scoped_refptr<IndexedDBBackingStore> backing_store = OpenBackingStore(origin, data_directory, + NULL /* request_context */, &data_loss, &data_loss_message, &disk_full); @@ -202,6 +203,7 @@ class DiskFullFactory : public IndexedDBFactory { virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( const GURL& origin_url, const base::FilePath& data_directory, + net::URLRequestContext* request_context, blink::WebIDBDataLoss* data_loss, std::string* data_loss_message, bool* disk_full) OVERRIDE { @@ -240,7 +242,11 @@ TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { 0, /* child_process_id */ 2, /* transaction_id */ 1 /* version */); - factory->Open(name, connection, origin, temp_directory.path()); + factory->Open(name, + connection, + NULL /* request_context */, + origin, + temp_directory.path()); } TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { @@ -259,8 +265,11 @@ TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { 0, /* child_process_id */ transaction_id, IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); - factory()->Open( - ASCIIToUTF16("db"), connection, origin, temp_directory.path()); + factory()->Open(ASCIIToUTF16("db"), + connection, + NULL /* request_context */, + origin, + temp_directory.path()); EXPECT_TRUE(callbacks->connection()); @@ -289,8 +298,11 @@ TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) { 0, /* child_process_id */ transaction_id, IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); - factory()->Open( - ASCIIToUTF16("db"), connection, origin, temp_directory.path()); + factory()->Open(ASCIIToUTF16("db"), + connection, + NULL /* request_context */, + origin, + temp_directory.path()); EXPECT_TRUE(callbacks->connection()); IndexedDBBackingStore* store = @@ -325,8 +337,11 @@ TEST_F(IndexedDBFactoryTest, DeleteDatabaseClosesBackingStore) { const bool expect_connection = false; scoped_refptr<MockIndexedDBCallbacks> callbacks( new MockIndexedDBCallbacks(expect_connection)); - factory()->DeleteDatabase( - ASCIIToUTF16("db"), callbacks, origin, temp_directory.path()); + factory()->DeleteDatabase(ASCIIToUTF16("db"), + NULL /* request_context */, + callbacks, + origin, + temp_directory.path()); EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); @@ -377,8 +392,11 @@ TEST_F(IndexedDBFactoryTest, ForceCloseReleasesBackingStore) { 0, /* child_process_id */ transaction_id, IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); - factory()->Open( - ASCIIToUTF16("db"), connection, origin, temp_directory.path()); + factory()->Open(ASCIIToUTF16("db"), + connection, + NULL /* request_context */, + origin, + temp_directory.path()); EXPECT_TRUE(callbacks->connection()); EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); @@ -453,7 +471,11 @@ TEST_F(IndexedDBFactoryTest, DatabaseFailedOpen) { 0, /* child_process_id */ transaction_id, db_version); - factory()->Open(db_name, connection, origin, temp_directory.path()); + factory()->Open(db_name, + connection, + NULL /* request_context */, + origin, + temp_directory.path()); EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); // Pump the message loop so the upgrade transaction can run. @@ -474,7 +496,11 @@ TEST_F(IndexedDBFactoryTest, DatabaseFailedOpen) { 0, /* child_process_id */ transaction_id, db_version - 1); - factory()->Open(db_name, connection, origin, temp_directory.path()); + factory()->Open(db_name, + connection, + NULL /* request_context */, + origin, + temp_directory.path()); EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); } diff --git a/content/browser/indexed_db/indexed_db_unittest.cc b/content/browser/indexed_db/indexed_db_unittest.cc index 5bf1efb..bf253f4 100644 --- a/content/browser/indexed_db/indexed_db_unittest.cc +++ b/content/browser/indexed_db/indexed_db_unittest.cc @@ -181,6 +181,7 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { 0 /* version */); factory->Open(base::ASCIIToUTF16("opendb"), open_connection, + NULL /* request_context */, kTestOrigin, idb_context->data_path()); IndexedDBPendingConnection closed_connection(closed_callbacks, @@ -190,6 +191,7 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { 0 /* version */); factory->Open(base::ASCIIToUTF16("closeddb"), closed_connection, + NULL /* request_context */, kTestOrigin, idb_context->data_path()); @@ -257,8 +259,11 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnCommitFailure) { 0 /* child_process_id */, transaction_id, IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); - factory->Open( - base::ASCIIToUTF16("db"), connection, kTestOrigin, temp_dir.path()); + factory->Open(base::ASCIIToUTF16("db"), + connection, + NULL /* request_context */, + kTestOrigin, + temp_dir.path()); EXPECT_TRUE(callbacks->connection()); |