diff --git content/browser/appcache/appcache_internals_ui.cc content/browser/appcache/appcache_internals_ui.cc index 71bf90c54ae5..d3308da307d7 100644 --- content/browser/appcache/appcache_internals_ui.cc +++ content/browser/appcache/appcache_internals_ui.cc @@ -372,8 +372,8 @@ void AppCacheInternalsUI::CreateProxyForPartition( StoragePartition* storage_partition) { scoped_refptr proxy = new Proxy(weak_ptr_factory_.GetWeakPtr(), storage_partition->GetPath()); - proxy->Initialize(static_cast(storage_partition) - ->GetAppCacheService()); + proxy->Initialize(static_cast( + storage_partition->GetAppCacheService())); appcache_proxies_.push_back(proxy); } diff --git content/browser/background_fetch/background_fetch_service_impl.cc content/browser/background_fetch/background_fetch_service_impl.cc index be53f5115d3d..92f09f04f3a1 100644 --- content/browser/background_fetch/background_fetch_service_impl.cc +++ content/browser/background_fetch/background_fetch_service_impl.cc @@ -38,8 +38,7 @@ void BackgroundFetchServiceImpl::Create( BrowserThread::IO, FROM_HERE, base::BindOnce( BackgroundFetchServiceImpl::CreateOnIoThread, - WrapRefCounted(static_cast( - render_process_host->GetStoragePartition()) + WrapRefCounted(render_process_host->GetStoragePartition() ->GetBackgroundFetchContext()), origin, std::move(request))); } diff --git content/browser/blob_storage/chrome_blob_storage_context.cc content/browser/blob_storage/chrome_blob_storage_context.cc index 0478c2f4dccf..4faa6c1d4b46 100644 --- content/browser/blob_storage/chrome_blob_storage_context.cc +++ content/browser/blob_storage/chrome_blob_storage_context.cc @@ -76,6 +76,11 @@ class BlobHandleImpl : public BlobHandle { ChromeBlobStorageContext::ChromeBlobStorageContext() {} +// static +const void* ChromeBlobStorageContext::GetUserDataKey() { + return kBlobStorageContextKeyName; +} + ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( BrowserContext* context) { DCHECK_CURRENTLY_ON(BrowserThread::UI); diff --git content/browser/blob_storage/chrome_blob_storage_context.h content/browser/blob_storage/chrome_blob_storage_context.h index 8c5b031e1e65..bbe6fa6525a6 100644 --- content/browser/blob_storage/chrome_blob_storage_context.h +++ content/browser/blob_storage/chrome_blob_storage_context.h @@ -50,6 +50,8 @@ class CONTENT_EXPORT ChromeBlobStorageContext public: ChromeBlobStorageContext(); + static const void* GetUserDataKey(); + // Must be called on the UI thread. static ChromeBlobStorageContext* GetFor( BrowserContext* browser_context); diff --git content/browser/bluetooth/web_bluetooth_service_impl.cc content/browser/bluetooth/web_bluetooth_service_impl.cc index e5c7291dcc8f..0eec8a11db35 100644 --- content/browser/bluetooth/web_bluetooth_service_impl.cc +++ content/browser/bluetooth/web_bluetooth_service_impl.cc @@ -1233,9 +1233,9 @@ url::Origin WebBluetoothServiceImpl::GetOrigin() { } BluetoothAllowedDevices& WebBluetoothServiceImpl::allowed_devices() { - StoragePartitionImpl* partition = static_cast( + StoragePartition* partition = BrowserContext::GetDefaultStoragePartition( - web_contents()->GetBrowserContext())); + web_contents()->GetBrowserContext()); scoped_refptr allowed_devices_map = partition->GetBluetoothAllowedDevicesMap(); return allowed_devices_map->GetOrCreateAllowedDevices(GetOrigin()); diff --git content/browser/browser_context.cc content/browser/browser_context.cc index 125078b9cb44..b24609a807ba 100644 --- content/browser/browser_context.cc +++ content/browser/browser_context.cc @@ -127,11 +127,18 @@ StoragePartition* GetStoragePartitionFromConfig( StoragePartitionImplMap* partition_map = GetStoragePartitionMap(browser_context); - if (browser_context->IsOffTheRecord()) + if (browser_context->IsOffTheRecord() || browser_context->GetPath().empty()) in_memory = true; - return partition_map->Get(partition_domain, partition_name, in_memory, - can_create); + StoragePartitionImpl* partition_impl = + partition_map->Get(partition_domain, partition_name, in_memory, + can_create); + if (partition_impl->browser_context() == browser_context) + return partition_impl; + + // |browser_context| is a CefBrowserContextProxy object. + return partition_impl->browser_context()-> + GetStoragePartitionProxy(browser_context, partition_impl); } void SaveSessionStateOnIOThread( @@ -553,6 +560,11 @@ ServiceManagerConnection* BrowserContext::GetServiceManagerConnectionFor( BrowserContext::BrowserContext() : media_device_id_salt_(CreateRandomMediaDeviceIDSalt()) {} +// static +const void* BrowserContext::GetStoragePartitionMapUserDataKey() { + return kStoragePartitionMapKeyName; +} + BrowserContext::~BrowserContext() { CHECK(GetUserData(kMojoWasInitialized)) << "Attempting to destroy a BrowserContext that never called " diff --git content/browser/devtools/protocol/service_worker_handler.cc content/browser/devtools/protocol/service_worker_handler.cc index 64dff1f030bb..244f62ec40dc 100644 --- content/browser/devtools/protocol/service_worker_handler.cc +++ content/browser/devtools/protocol/service_worker_handler.cc @@ -337,8 +337,7 @@ Response ServiceWorkerHandler::DispatchSyncEvent( if (!base::StringToInt64(registration_id, &id)) return CreateInvalidVersionIdErrorResponse(); - StoragePartitionImpl* partition = - static_cast(process_->GetStoragePartition()); + StoragePartition* partition = process_->GetStoragePartition(); BackgroundSyncContext* sync_context = partition->GetBackgroundSyncContext(); BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, diff --git content/browser/download/download_manager_impl.cc content/browser/download/download_manager_impl.cc index 11eb1d3b732a..52962a868999 100644 --- content/browser/download/download_manager_impl.cc +++ content/browser/download/download_manager_impl.cc @@ -73,9 +73,9 @@ namespace content { namespace { -StoragePartitionImpl* GetStoragePartition(BrowserContext* context, - int render_process_id, - int render_frame_id) { +StoragePartition* GetStoragePartition(BrowserContext* context, + int render_process_id, + int render_frame_id) { DCHECK_CURRENTLY_ON(BrowserThread::UI); SiteInstance* site_instance = nullptr; @@ -85,8 +85,7 @@ StoragePartitionImpl* GetStoragePartition(BrowserContext* context, if (render_frame_host_) site_instance = render_frame_host_->GetSiteInstance(); } - return static_cast( - BrowserContext::GetStoragePartition(context, site_instance)); + return BrowserContext::GetStoragePartition(context, site_instance); } bool CanRequestURLFromRenderer(int render_process_id, GURL url) { @@ -1069,7 +1068,7 @@ void DownloadManagerImpl::BeginDownloadInternal( if (base::FeatureList::IsEnabled(features::kNetworkService)) { std::unique_ptr request = CreateResourceRequest(params.get()); - StoragePartitionImpl* storage_partition = + StoragePartition* storage_partition = GetStoragePartition(browser_context_, params->render_process_host_id(), params->render_frame_host_routing_id()); @@ -1090,7 +1089,8 @@ void DownloadManagerImpl::BeginDownloadInternal( BrowserThread::IO, FROM_HERE, base::BindOnce( &BeginResourceDownload, std::move(params), std::move(request), - storage_partition->url_loader_factory_getter(), + base::WrapRefCounted( + storage_partition->url_loader_factory_getter()), base::WrapRefCounted(storage_partition->GetFileSystemContext()), id, weak_factory_.GetWeakPtr(), site_url, tab_url, tab_referrer_url), base::BindOnce(&DownloadManagerImpl::AddUrlDownloadHandler, diff --git content/browser/loader/navigation_url_loader_network_service.cc content/browser/loader/navigation_url_loader_network_service.cc index d9297fa8365e..38a3fb629a7a 100644 --- content/browser/loader/navigation_url_loader_network_service.cc +++ content/browser/loader/navigation_url_loader_network_service.cc @@ -868,11 +868,12 @@ NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( .PassInterface(); } - auto* partition = static_cast(storage_partition); + auto* partition = storage_partition; DCHECK(!request_controller_); request_controller_ = std::make_unique( std::move(initial_handlers), std::move(new_request), resource_context, - partition->url_loader_factory_getter(), request_info->common_params.url, + base::WrapRefCounted(partition->url_loader_factory_getter()), + request_info->common_params.url, request_info->begin_params->initiator_origin, request_info->begin_params->suggested_filename, weak_factory_.GetWeakPtr()); diff --git content/browser/payments/payment_app_provider_impl.cc content/browser/payments/payment_app_provider_impl.cc index b9d2670514c0..004939aa055a 100644 --- content/browser/payments/payment_app_provider_impl.cc +++ content/browser/payments/payment_app_provider_impl.cc @@ -328,10 +328,11 @@ void StartServiceWorkerForDispatch(BrowserContext* browser_context, ServiceWorkerStartCallback callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); - StoragePartitionImpl* partition = static_cast( - BrowserContext::GetDefaultStoragePartition(browser_context)); + StoragePartition* partition = + BrowserContext::GetDefaultStoragePartition(browser_context); scoped_refptr service_worker_context = - partition->GetServiceWorkerContext(); + static_cast( + partition->GetServiceWorkerContext()); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, @@ -357,8 +358,8 @@ void PaymentAppProviderImpl::GetAllPaymentApps( GetAllPaymentAppsCallback callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); - StoragePartitionImpl* partition = static_cast( - BrowserContext::GetDefaultStoragePartition(browser_context)); + StoragePartition* partition = + BrowserContext::GetDefaultStoragePartition(browser_context); scoped_refptr payment_app_context = partition->GetPaymentAppContext(); diff --git content/browser/renderer_host/render_process_host_impl.cc content/browser/renderer_host/render_process_host_impl.cc index 22c72f3ac929..c12815670521 100644 --- content/browser/renderer_host/render_process_host_impl.cc +++ content/browser/renderer_host/render_process_host_impl.cc @@ -497,9 +497,8 @@ class SpareRenderProcessHostManager : public RenderProcessHostObserver { SpareRenderProcessHostManager() {} void WarmupSpareRenderProcessHost(BrowserContext* browser_context) { - StoragePartitionImpl* current_partition = - static_cast( - BrowserContext::GetStoragePartition(browser_context, nullptr)); + StoragePartition* current_partition = + BrowserContext::GetStoragePartition(browser_context, nullptr); if (spare_render_process_host_ && matching_browser_context_ == browser_context && @@ -638,11 +637,10 @@ class DefaultSubframeProcessHostHolder : public base::SupportsUserData::Data, // Gets the correct render process to use for this SiteInstance. RenderProcessHost* GetProcessHost(SiteInstance* site_instance, bool is_for_guests_only) { - StoragePartitionImpl* default_partition = - static_cast( - BrowserContext::GetDefaultStoragePartition(browser_context_)); - StoragePartitionImpl* partition = static_cast( - BrowserContext::GetStoragePartition(browser_context_, site_instance)); + StoragePartition* default_partition = + BrowserContext::GetDefaultStoragePartition(browser_context_); + StoragePartition* partition = + BrowserContext::GetStoragePartition(browser_context_, site_instance); // Is this the default storage partition? If it isn't, then just give it its // own non-shared process. @@ -1237,7 +1235,7 @@ void RenderProcessHost::SetMaxRendererProcessCount(size_t count) { // static RenderProcessHost* RenderProcessHostImpl::CreateRenderProcessHost( BrowserContext* browser_context, - StoragePartitionImpl* storage_partition_impl, + StoragePartition* storage_partition_impl, SiteInstance* site_instance, bool is_for_guests_only) { if (g_render_process_host_factory_) { @@ -1246,8 +1244,8 @@ RenderProcessHost* RenderProcessHostImpl::CreateRenderProcessHost( } if (!storage_partition_impl) { - storage_partition_impl = static_cast( - BrowserContext::GetStoragePartition(browser_context, site_instance)); + storage_partition_impl = + BrowserContext::GetStoragePartition(browser_context, site_instance); } // If we've made a StoragePartition for guests (e.g., for the tag), // stash the Site URL on it. This way, when we start a service worker inside @@ -1269,7 +1267,7 @@ RenderProcessHost* RenderProcessHostImpl::CreateRenderProcessHost( // static RenderProcessHost* RenderProcessHostImpl::CreateOrUseSpareRenderProcessHost( BrowserContext* browser_context, - StoragePartitionImpl* storage_partition_impl, + StoragePartition* storage_partition_impl, SiteInstance* site_instance, bool is_for_guests_only) { RenderProcessHost* render_process_host = @@ -1289,7 +1287,7 @@ RenderProcessHost* RenderProcessHostImpl::CreateOrUseSpareRenderProcessHost( RenderProcessHostImpl::RenderProcessHostImpl( BrowserContext* browser_context, - StoragePartitionImpl* storage_partition_impl, + StoragePartition* storage_partition_impl, bool is_for_guests_only) : fast_shutdown_started_(false), deleting_soon_(false), @@ -1322,7 +1320,8 @@ RenderProcessHostImpl::RenderProcessHostImpl( indexed_db_factory_(new IndexedDBDispatcherHost( id_, storage_partition_impl_->GetURLRequestContext(), - storage_partition_impl_->GetIndexedDBContext(), + static_cast( + storage_partition_impl_->GetIndexedDBContext()), ChromeBlobStorageContext::GetFor(browser_context_))), channel_connected_(false), sent_render_process_ready_(false), @@ -1356,7 +1355,8 @@ RenderProcessHostImpl::RenderProcessHostImpl( } push_messaging_manager_.reset(new PushMessagingManager( - GetID(), storage_partition_impl_->GetServiceWorkerContext())); + GetID(), static_cast( + storage_partition_impl_->GetServiceWorkerContext()))); AddObserver(indexed_db_factory_.get()); @@ -1671,6 +1671,20 @@ void RenderProcessHostImpl::ResetChannelProxy() { void RenderProcessHostImpl::CreateMessageFilters() { DCHECK_CURRENTLY_ON(BrowserThread::UI); + + // Cast to the derived type from StoragePartitionImpl. + auto app_cache_service = static_cast( + storage_partition_impl_->GetAppCacheService()); + auto dom_storage_context = static_cast( + storage_partition_impl_->GetDOMStorageContext()); + auto cache_storage_context = static_cast( + storage_partition_impl_->GetCacheStorageContext()); + auto service_worker_context = static_cast( + storage_partition_impl_->GetServiceWorkerContext()); + auto platform_notification_context = + static_cast( + storage_partition_impl_->GetPlatformNotificationContext()); + AddFilter(new ResourceSchedulerFilter(GetID())); MediaInternals* media_internals = MediaInternals::GetInstance(); // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages @@ -1685,8 +1699,8 @@ void RenderProcessHostImpl::CreateMessageFilters() { new RenderMessageFilter( GetID(), GetBrowserContext(), request_context.get(), widget_helper_.get(), media_internals, - storage_partition_impl_->GetDOMStorageContext(), - storage_partition_impl_->GetCacheStorageContext())); + dom_storage_context, + cache_storage_context)); AddFilter(render_message_filter.get()); render_frame_message_filter_ = new RenderFrameMessageFilter( @@ -1715,10 +1729,10 @@ void RenderProcessHostImpl::CreateMessageFilters() { ChromeBlobStorageContext::GetFor(browser_context); resource_message_filter_ = new ResourceMessageFilter( - GetID(), storage_partition_impl_->GetAppCacheService(), + GetID(), app_cache_service, blob_storage_context.get(), storage_partition_impl_->GetFileSystemContext(), - storage_partition_impl_->GetServiceWorkerContext(), get_contexts_callback, + service_worker_context, get_contexts_callback, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); AddFilter(resource_message_filter_.get()); @@ -1743,8 +1757,7 @@ void RenderProcessHostImpl::CreateMessageFilters() { } AddFilter( new MidiHost(GetID(), BrowserMainLoop::GetInstance()->midi_service())); - AddFilter(new DOMStorageMessageFilter( - storage_partition_impl_->GetDOMStorageContext())); + AddFilter(new DOMStorageMessageFilter(dom_storage_context)); #if BUILDFLAG(ENABLE_WEBRTC) peer_connection_tracker_host_ = new PeerConnectionTrackerHost(GetID()); @@ -1767,13 +1780,12 @@ void RenderProcessHostImpl::CreateMessageFilters() { scoped_refptr cache_storage_filter = new CacheStorageDispatcherHost(); - cache_storage_filter->Init(storage_partition_impl_->GetCacheStorageContext()); + cache_storage_filter->Init(cache_storage_context); AddFilter(cache_storage_filter.get()); scoped_refptr service_worker_filter = new ServiceWorkerDispatcherHost(GetID(), resource_context); - service_worker_filter->Init( - storage_partition_impl_->GetServiceWorkerContext()); + service_worker_filter->Init(service_worker_context); AddFilter(service_worker_filter.get()); #if BUILDFLAG(ENABLE_WEBRTC) @@ -1785,11 +1797,8 @@ void RenderProcessHostImpl::CreateMessageFilters() { AddFilter(new TraceMessageFilter(GetID())); AddFilter(new ResolveProxyMsgHelper(request_context.get())); - scoped_refptr service_worker_context( - static_cast( - storage_partition_impl_->GetServiceWorkerContext())); notification_message_filter_ = new NotificationMessageFilter( - GetID(), storage_partition_impl_->GetPlatformNotificationContext(), + GetID(), platform_notification_context, resource_context, service_worker_context, browser_context); AddFilter(notification_message_filter_.get()); @@ -1931,7 +1940,8 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() { registry->AddInterface(base::BindRepeating( &AppCacheDispatcherHost::Create, - base::Unretained(storage_partition_impl_->GetAppCacheService()), + base::Unretained(static_cast( + storage_partition_impl_->GetAppCacheService())), GetID())); AddUIThreadInterface(registry.get(), base::Bind(&FieldTrialRecorder::Create)); diff --git content/browser/renderer_host/render_process_host_impl.h content/browser/renderer_host/render_process_host_impl.h index f81189990b1f..39afa6c9ecfd 100644 --- content/browser/renderer_host/render_process_host_impl.h +++ content/browser/renderer_host/render_process_host_impl.h @@ -83,7 +83,6 @@ class ResourceMessageFilter; class SiteInstance; class SiteInstanceImpl; class StoragePartition; -class StoragePartitionImpl; #if BUILDFLAG(ENABLE_WEBRTC) class MediaStreamDispatcherHost; @@ -127,7 +126,7 @@ class CONTENT_EXPORT RenderProcessHostImpl // legal). static RenderProcessHost* CreateOrUseSpareRenderProcessHost( BrowserContext* browser_context, - StoragePartitionImpl* storage_partition_impl, + StoragePartition* storage_partition_impl, SiteInstance* site_instance, bool is_for_guests_only); @@ -139,7 +138,7 @@ class CONTENT_EXPORT RenderProcessHostImpl // null. static RenderProcessHost* CreateRenderProcessHost( BrowserContext* browser_context, - StoragePartitionImpl* storage_partition_impl, + StoragePartition* storage_partition_impl, SiteInstance* site_instance, bool is_for_guests_only); @@ -420,7 +419,7 @@ class CONTENT_EXPORT RenderProcessHostImpl // Use CreateRenderProcessHost() instead of calling this constructor // directly. RenderProcessHostImpl(BrowserContext* browser_context, - StoragePartitionImpl* storage_partition_impl, + StoragePartition* storage_partition_impl, bool is_for_guests_only); // Initializes a new IPC::ChannelProxy in |channel_|, which will be connected @@ -656,10 +655,10 @@ class CONTENT_EXPORT RenderProcessHostImpl // called. int instance_id_ = 1; - BrowserContext* const browser_context_; + BrowserContext* browser_context_; // Owned by |browser_context_|. - StoragePartitionImpl* storage_partition_impl_; + StoragePartition* storage_partition_impl_; // The observers watching our lifetime. base::ObserverList observers_; diff --git content/browser/renderer_interface_binders.cc content/browser/renderer_interface_binders.cc index 01ba96322f69..6dde251b3d1b 100644 --- content/browser/renderer_interface_binders.cc +++ content/browser/renderer_interface_binders.cc @@ -133,7 +133,7 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() { parameterized_binder_registry_.AddInterface( base::Bind([](payments::mojom::PaymentManagerRequest request, RenderProcessHost* host, const url::Origin& origin) { - static_cast(host->GetStoragePartition()) + host->GetStoragePartition() ->GetPaymentAppContext() ->CreatePaymentManager(std::move(request)); })); @@ -147,7 +147,7 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() { parameterized_binder_registry_.AddInterface(base::BindRepeating( [](blink::mojom::LockManagerRequest request, RenderProcessHost* host, const url::Origin& origin) { - static_cast(host->GetStoragePartition()) + host->GetStoragePartition() ->GetLockManager() ->CreateService(std::move(request), origin); })); @@ -156,9 +156,10 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() { parameterized_binder_registry_.AddInterface( base::Bind([](blink::mojom::NotificationServiceRequest request, RenderProcessHost* host, const url::Origin& origin) { - static_cast(host->GetStoragePartition()) - ->GetPlatformNotificationContext() - ->CreateService(host->GetID(), origin, std::move(request)); + static_cast( + host->GetStoragePartition() + ->GetPlatformNotificationContext()) + ->CreateService(host->GetID(), origin, std::move(request)); })); parameterized_binder_registry_.AddInterface( base::BindRepeating(&BackgroundFetchServiceImpl::Create)); diff --git content/browser/shared_worker/shared_worker_connector_impl.cc content/browser/shared_worker/shared_worker_connector_impl.cc index 1e95910e7168..45adb88b1e96 100644 --- content/browser/shared_worker/shared_worker_connector_impl.cc +++ content/browser/shared_worker/shared_worker_connector_impl.cc @@ -34,10 +34,9 @@ void SharedWorkerConnectorImpl::Connect( mojom::SharedWorkerClientPtr client, blink::mojom::SharedWorkerCreationContextType creation_context_type, mojo::ScopedMessagePipeHandle message_port) { - SharedWorkerServiceImpl* service = - static_cast( - RenderProcessHost::FromID(process_id_)->GetStoragePartition()) - ->GetSharedWorkerService(); + SharedWorkerServiceImpl* service = static_cast( + RenderProcessHost::FromID(process_id_)->GetStoragePartition() + ->GetSharedWorkerService()); service->ConnectToWorker(process_id_, frame_id_, std::move(info), std::move(client), creation_context_type, blink::MessagePortChannel(std::move(message_port))); diff --git content/browser/storage_partition_impl.h content/browser/storage_partition_impl.h index 4fb38a200f04..182f14ead806 100644 --- content/browser/storage_partition_impl.h +++ content/browser/storage_partition_impl.h @@ -87,7 +87,7 @@ class CONTENT_EXPORT StoragePartitionImpl storage::FileSystemContext* GetFileSystemContext() override; storage::DatabaseTracker* GetDatabaseTracker() override; DOMStorageContextWrapper* GetDOMStorageContext() override; - LockManager* GetLockManager(); // override; TODO: Add to interface + LockManager* GetLockManager() override; IndexedDBContextImpl* GetIndexedDBContext() override; CacheStorageContextImpl* GetCacheStorageContext() override; ServiceWorkerContextWrapper* GetServiceWorkerContext() override; @@ -124,13 +124,13 @@ class CONTENT_EXPORT StoragePartitionImpl void ClearBluetoothAllowedDevicesMapForTesting() override; void FlushNetworkInterfaceForTesting() override; - BackgroundFetchContext* GetBackgroundFetchContext(); - BackgroundSyncContext* GetBackgroundSyncContext(); - PaymentAppContextImpl* GetPaymentAppContext(); - BroadcastChannelProvider* GetBroadcastChannelProvider(); - BluetoothAllowedDevicesMap* GetBluetoothAllowedDevicesMap(); - BlobURLLoaderFactory* GetBlobURLLoaderFactory(); - BlobRegistryWrapper* GetBlobRegistry(); + BackgroundFetchContext* GetBackgroundFetchContext() override; + BackgroundSyncContext* GetBackgroundSyncContext() override; + PaymentAppContextImpl* GetPaymentAppContext() override; + BroadcastChannelProvider* GetBroadcastChannelProvider() override; + BluetoothAllowedDevicesMap* GetBluetoothAllowedDevicesMap() override; + BlobURLLoaderFactory* GetBlobURLLoaderFactory() override; + BlobRegistryWrapper* GetBlobRegistry() override; // mojom::StoragePartitionService interface. void OpenLocalStorage( @@ -141,18 +141,18 @@ class CONTENT_EXPORT StoragePartitionImpl const url::Origin& origin, mojo::InterfaceRequest request) override; - scoped_refptr url_loader_factory_getter() { - return url_loader_factory_getter_; + URLLoaderFactoryGetter* url_loader_factory_getter() override { + return url_loader_factory_getter_.get(); } // Can return nullptr while |this| is being destroyed. - BrowserContext* browser_context() const; + BrowserContext* browser_context() const override; // Called by each renderer process once. Returns the id of the created // binding. mojo::BindingId Bind( int process_id, - mojo::InterfaceRequest request); + mojo::InterfaceRequest request) override; auto& bindings_for_testing() { return bindings_; } @@ -163,10 +163,11 @@ class CONTENT_EXPORT StoragePartitionImpl // one must use the "chrome-guest://blahblah" site URL to ensure that the // service worker stays in this StoragePartition. This is an empty GURL if // this StoragePartition is not for guests. - void set_site_for_service_worker(const GURL& site_for_service_worker) { + void set_site_for_service_worker( + const GURL& site_for_service_worker) override { site_for_service_worker_ = site_for_service_worker; } - const GURL& site_for_service_worker() const { + const GURL& site_for_service_worker() const override { return site_for_service_worker_; } diff --git content/browser/streams/stream_context.cc content/browser/streams/stream_context.cc index 7aafca3aafcd..aac07962f6a5 100644 --- content/browser/streams/stream_context.cc +++ content/browser/streams/stream_context.cc @@ -22,6 +22,11 @@ namespace content { StreamContext::StreamContext() {} +// static +const void* StreamContext::GetUserDataKey() { + return kStreamContextKeyName; +} + StreamContext* StreamContext::GetFor(BrowserContext* context) { if (!context->GetUserData(kStreamContextKeyName)) { scoped_refptr stream = new StreamContext(); diff --git content/browser/streams/stream_context.h content/browser/streams/stream_context.h index 075ae3e7431e..57fb5fd2c4a8 100644 --- content/browser/streams/stream_context.h +++ content/browser/streams/stream_context.h @@ -29,6 +29,7 @@ class StreamContext public: StreamContext(); + CONTENT_EXPORT static const void* GetUserDataKey(); CONTENT_EXPORT static StreamContext* GetFor(BrowserContext* browser_context); void InitializeOnIOThread(); diff --git content/browser/webui/web_ui_url_loader_factory.cc content/browser/webui/web_ui_url_loader_factory.cc index 53845bd346ed..e2c023cd688e 100644 --- content/browser/webui/web_ui_url_loader_factory.cc +++ content/browser/webui/web_ui_url_loader_factory.cc @@ -20,13 +20,13 @@ #include "content/browser/histogram_internals_url_loader.h" #include "content/browser/loader/global_routing_id.h" #include "content/browser/resource_context_impl.h" -#include "content/browser/storage_partition_impl.h" #include "content/browser/webui/network_error_url_loader.h" #include "content/browser/webui/url_data_manager_backend.h" #include "content/browser/webui/url_data_source_impl.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_process_host.h" +#include "content/public/browser/storage_partition.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/url_constants.h" @@ -302,9 +302,8 @@ class WebUIURLLoaderFactory : public network::mojom::URLLoaderFactory, const std::string& scheme() const { return scheme_; } private: - StoragePartitionImpl* GetStoragePartition() { - return static_cast( - render_frame_host_->GetProcess()->GetStoragePartition()); + StoragePartition* GetStoragePartition() { + return render_frame_host_->GetProcess()->GetStoragePartition(); } RenderFrameHost* render_frame_host_; diff --git content/public/browser/browser_context.h content/public/browser/browser_context.h index f75be61ccdef..84f1063fb081 100644 --- content/public/browser/browser_context.h +++ content/public/browser/browser_context.h @@ -200,6 +200,8 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { BrowserContext(); + static const void* GetStoragePartitionMapUserDataKey(); + ~BrowserContext() override; // Shuts down the storage partitions associated to this browser context. @@ -288,6 +290,14 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { const base::FilePath& partition_path, bool in_memory) = 0; + // CEF returns a proxy object that forwards method calls to |partition_impl|. + virtual content::StoragePartition* GetStoragePartitionProxy( + BrowserContext* browser_context, + content::StoragePartition* partition_impl) { + NOTREACHED(); + return nullptr; + } + using StaticServiceMap = std::map; diff --git content/public/browser/storage_partition.h content/public/browser/storage_partition.h index 9bf0a872f380..73ede1ccdedf 100644 --- content/public/browser/storage_partition.h +++ content/public/browser/storage_partition.h @@ -13,6 +13,7 @@ #include "base/files/file_path.h" #include "base/time/time.h" #include "content/common/content_export.h" +#include "mojo/public/cpp/bindings/binding_set.h" #include "net/cookies/cookie_store.h" class GURL; @@ -49,13 +50,22 @@ class DatabaseTracker; namespace content { class AppCacheService; +class BackgroundFetchContext; +class BackgroundSyncContext; +class BlobRegistryWrapper; +class BlobURLLoaderFactory; +class BluetoothAllowedDevicesMap; +class BroadcastChannelProvider; class BrowserContext; class CacheStorageContext; class DOMStorageContext; class IndexedDBContext; +class LockManager; +class PaymentAppContextImpl; class PlatformNotificationContext; class ServiceWorkerContext; class SharedWorkerService; +class URLLoaderFactoryGetter; #if !defined(OS_ANDROID) class HostZoomLevelContext; @@ -63,6 +73,10 @@ class HostZoomMap; class ZoomLevelDelegate; #endif // !defined(OS_ANDROID) +namespace mojom { +class StoragePartitionService; +} + // Defines what persistent state a child process can access. // // The StoragePartition defines the view each child process has of the @@ -88,6 +102,7 @@ class CONTENT_EXPORT StoragePartition { virtual storage::FileSystemContext* GetFileSystemContext() = 0; virtual storage::DatabaseTracker* GetDatabaseTracker() = 0; virtual DOMStorageContext* GetDOMStorageContext() = 0; + virtual LockManager* GetLockManager() = 0; virtual IndexedDBContext* GetIndexedDBContext() = 0; virtual ServiceWorkerContext* GetServiceWorkerContext() = 0; virtual SharedWorkerService* GetSharedWorkerService() = 0; @@ -204,6 +219,25 @@ class CONTENT_EXPORT StoragePartition { // use only. virtual void FlushNetworkInterfaceForTesting() = 0; + virtual BackgroundFetchContext* GetBackgroundFetchContext() = 0; + virtual BackgroundSyncContext* GetBackgroundSyncContext() = 0; + virtual PaymentAppContextImpl* GetPaymentAppContext() = 0; + virtual BroadcastChannelProvider* GetBroadcastChannelProvider() = 0; + virtual BluetoothAllowedDevicesMap* GetBluetoothAllowedDevicesMap() = 0; + virtual BlobURLLoaderFactory* GetBlobURLLoaderFactory() = 0; + virtual BlobRegistryWrapper* GetBlobRegistry() = 0; + + virtual URLLoaderFactoryGetter* url_loader_factory_getter() = 0; + virtual BrowserContext* browser_context() const = 0; + + virtual mojo::BindingId Bind( + int process_id, + mojo::InterfaceRequest request) = 0; + + virtual void set_site_for_service_worker( + const GURL& site_for_service_worker) = 0; + virtual const GURL& site_for_service_worker() const = 0; + protected: virtual ~StoragePartition() {} }; diff --git storage/browser/database/database_tracker.cc storage/browser/database/database_tracker.cc index e1e508e205be..10432c7d833e 100644 --- storage/browser/database/database_tracker.cc +++ storage/browser/database/database_tracker.cc @@ -491,7 +491,7 @@ bool DatabaseTracker::LazyInit() { meta_table_.reset(new sql::MetaTable()); is_initialized_ = - base::CreateDirectory(db_dir_) && + (is_incognito_ ? true : base::CreateDirectory(db_dir_)) && (db_->is_open() || (is_incognito_ ? db_->OpenInMemory() : db_->Open(kTrackerDatabaseFullPath))) &&