diff --git content/browser/appcache/appcache_internals_ui.cc content/browser/appcache/appcache_internals_ui.cc index e9ad038..2a10c80 100644 --- content/browser/appcache/appcache_internals_ui.cc +++ content/browser/appcache/appcache_internals_ui.cc @@ -369,8 +369,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/blob_storage/chrome_blob_storage_context.cc content/browser/blob_storage/chrome_blob_storage_context.cc index 3192cd0..39b1518 100644 --- content/browser/blob_storage/chrome_blob_storage_context.cc +++ content/browser/blob_storage/chrome_blob_storage_context.cc @@ -73,6 +73,11 @@ class BlobHandleImpl : public BlobHandle { ChromeBlobStorageContext::ChromeBlobStorageContext() {} +// static +const void* ChromeBlobStorageContext::GetUserDataKey() { + return kBlobStorageContextKeyName; +} + ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( BrowserContext* context) { if (!context->GetUserData(kBlobStorageContextKeyName)) { diff --git content/browser/blob_storage/chrome_blob_storage_context.h content/browser/blob_storage/chrome_blob_storage_context.h index 4c7cfac..4d5c09c 100644 --- content/browser/blob_storage/chrome_blob_storage_context.h +++ content/browser/blob_storage/chrome_blob_storage_context.h @@ -43,6 +43,7 @@ class CONTENT_EXPORT ChromeBlobStorageContext public: ChromeBlobStorageContext(); + static const void* GetUserDataKey(); static ChromeBlobStorageContext* GetFor( BrowserContext* browser_context); diff --git content/browser/browser_context.cc content/browser/browser_context.cc index b7a99d5..b9f70ea 100644 --- content/browser/browser_context.cc +++ content/browser/browser_context.cc @@ -114,7 +114,14 @@ StoragePartition* GetStoragePartitionFromConfig( if (browser_context->IsOffTheRecord()) in_memory = true; - return partition_map->Get(partition_domain, partition_name, in_memory); + StoragePartitionImpl* partition_impl = + partition_map->Get(partition_domain, partition_name, in_memory); + 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( @@ -505,6 +512,11 @@ ServiceManagerConnection* BrowserContext::GetServiceManagerConnectionFor( : nullptr; } +// 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 242d33e..4dfb463 100644 --- content/browser/devtools/protocol/service_worker_handler.cc +++ content/browser/devtools/protocol/service_worker_handler.cc @@ -321,10 +321,9 @@ Response ServiceWorkerHandler::DispatchSyncEvent( if (!base::StringToInt64(registration_id, &id)) return CreateInvalidVersionIdErrorResponse(); - StoragePartitionImpl* partition = - static_cast(BrowserContext::GetStoragePartition( + StoragePartition* partition = BrowserContext::GetStoragePartition( render_frame_host_->GetProcess()->GetBrowserContext(), - render_frame_host_->GetSiteInstance())); + render_frame_host_->GetSiteInstance()); BackgroundSyncContext* sync_context = partition->GetBackgroundSyncContext(); BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, diff --git content/browser/renderer_host/render_process_host_impl.cc content/browser/renderer_host/render_process_host_impl.cc index 9986ff6..0d2abbd 100644 --- content/browser/renderer_host/render_process_host_impl.cc +++ content/browser/renderer_host/render_process_host_impl.cc @@ -661,7 +661,7 @@ void RenderProcessHostImpl::EarlyZygoteLaunch() { 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), @@ -691,7 +691,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), @@ -722,7 +723,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()); #if defined(OS_MACOSX) @@ -926,7 +928,7 @@ bool RenderProcessHostImpl::Init() { } void RenderProcessHostImpl::EnableSendQueue() { - if (!channel_) + if (!channel_ && browser_context_) InitializeChannelProxy(); } @@ -1020,6 +1022,22 @@ 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 indexed_db_context = static_cast( + storage_partition_impl_->GetIndexedDBContext()); + 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 @@ -1034,8 +1052,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( @@ -1065,10 +1083,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()); @@ -1092,10 +1110,10 @@ void RenderProcessHostImpl::CreateMessageFilters() { AddFilter( new MidiHost(GetID(), BrowserMainLoop::GetInstance()->midi_service())); AddFilter(new AppCacheDispatcherHost( - storage_partition_impl_->GetAppCacheService(), GetID())); + app_cache_service, GetID())); AddFilter(new ClipboardMessageFilter(blob_storage_context)); AddFilter(new DOMStorageMessageFilter( - storage_partition_impl_->GetDOMStorageContext())); + dom_storage_context)); #if BUILDFLAG(ENABLE_WEBRTC) peer_connection_tracker_host_ = new PeerConnectionTrackerHost( @@ -1135,13 +1153,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()); AddFilter(new SharedWorkerMessageFilter( @@ -1149,12 +1166,12 @@ void RenderProcessHostImpl::CreateMessageFilters() { WorkerStoragePartition( storage_partition_impl_->GetURLRequestContext(), storage_partition_impl_->GetMediaURLRequestContext(), - storage_partition_impl_->GetAppCacheService(), + app_cache_service, storage_partition_impl_->GetQuotaManager(), storage_partition_impl_->GetFileSystemContext(), storage_partition_impl_->GetDatabaseTracker(), - storage_partition_impl_->GetIndexedDBContext(), - storage_partition_impl_->GetServiceWorkerContext()), + indexed_db_context, + service_worker_context), base::Bind(&RenderWidgetHelper::GetNextRoutingID, base::Unretained(widget_helper_.get())))); @@ -1170,11 +1187,8 @@ void RenderProcessHostImpl::CreateMessageFilters() { GetID(), storage_partition_impl_->GetQuotaManager(), GetContentClient()->browser()->CreateQuotaPermissionContext())); - 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()); @@ -1191,6 +1205,11 @@ void RenderProcessHostImpl::CreateMessageFilters() { void RenderProcessHostImpl::RegisterMojoInterfaces() { auto registry = base::MakeUnique(); + // Cast to the derived type from StoragePartitionImpl. + auto platform_notification_context = + static_cast( + storage_partition_impl_->GetPlatformNotificationContext()); + channel_->AddAssociatedInterfaceForIOThread( base::Bind(&IndexedDBDispatcherHost::AddBinding, base::Unretained(indexed_db_factory_.get()))); @@ -1252,8 +1271,7 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() { AddUIThreadInterface( registry.get(), base::Bind(&PlatformNotificationContextImpl::CreateService, - base::Unretained( - storage_partition_impl_->GetPlatformNotificationContext()), + base::Unretained(platform_notification_context), GetID())); AddUIThreadInterface( registry.get(), @@ -1451,6 +1469,7 @@ void RenderProcessHostImpl::ForceReleaseWorkerRefCounts() { DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK(!is_worker_ref_count_disabled_); is_worker_ref_count_disabled_ = true; + browser_context_ = nullptr; if (!GetWorkerRefCount()) return; service_worker_ref_count_ = 0; diff --git content/browser/renderer_host/render_process_host_impl.h content/browser/renderer_host/render_process_host_impl.h index aa6898d..f19264e 100644 --- content/browser/renderer_host/render_process_host_impl.h +++ content/browser/renderer_host/render_process_host_impl.h @@ -75,7 +75,6 @@ class RenderWidgetHost; class RenderWidgetHostImpl; class ResourceMessageFilter; class StoragePartition; -class StoragePartitionImpl; namespace mojom { class StoragePartitionService; @@ -111,7 +110,7 @@ class CONTENT_EXPORT RenderProcessHostImpl public NON_EXPORTED_BASE(mojom::AssociatedInterfaceProvider) { public: RenderProcessHostImpl(BrowserContext* browser_context, - StoragePartitionImpl* storage_partition_impl, + StoragePartition* storage_partition_impl, bool is_for_guests_only); ~RenderProcessHostImpl() override; @@ -516,10 +515,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/site_instance_impl.cc content/browser/site_instance_impl.cc index a4c8862..2312f35 100644 --- content/browser/site_instance_impl.cc +++ content/browser/site_instance_impl.cc @@ -198,9 +198,8 @@ RenderProcessHost* SiteInstanceImpl::GetProcess() { process_ = g_render_process_host_factory_->CreateRenderProcessHost( browser_context, this); } else { - StoragePartitionImpl* partition = - static_cast( - BrowserContext::GetStoragePartition(browser_context, this)); + StoragePartition* partition = + BrowserContext::GetStoragePartition(browser_context, this); process_ = new RenderProcessHostImpl(browser_context, partition, is_for_guests_only); } diff --git content/browser/storage_partition_impl.h content/browser/storage_partition_impl.h index 5b706ff..6d7f7cd 100644 --- content/browser/storage_partition_impl.h +++ content/browser/storage_partition_impl.h @@ -78,12 +78,11 @@ class CONTENT_EXPORT StoragePartitionImpl ZoomLevelDelegate* GetZoomLevelDelegate() override; PlatformNotificationContextImpl* GetPlatformNotificationContext() override; void ClearBluetoothAllowedDevicesMapForTesting() override; - - BackgroundFetchContext* GetBackgroundFetchContext(); - BackgroundSyncContext* GetBackgroundSyncContext(); - PaymentAppContextImpl* GetPaymentAppContext(); - BroadcastChannelProvider* GetBroadcastChannelProvider(); - BluetoothAllowedDevicesMap* GetBluetoothAllowedDevicesMap(); + BackgroundFetchContext* GetBackgroundFetchContext() override; + BackgroundSyncContext* GetBackgroundSyncContext() override; + PaymentAppContextImpl* GetPaymentAppContext() override; + BroadcastChannelProvider* GetBroadcastChannelProvider() override; + BluetoothAllowedDevicesMap* GetBluetoothAllowedDevicesMap() override; // mojom::StoragePartitionService interface. void OpenLocalStorage( @@ -123,7 +122,8 @@ class CONTENT_EXPORT StoragePartitionImpl BrowserContext* browser_context() const; // Called by each renderer process once. - void Bind(mojo::InterfaceRequest request); + void Bind(mojo::InterfaceRequest request) + override; struct DataDeletionHelper; struct QuotaManagedDataDeletionHelper; diff --git content/browser/streams/stream_context.cc content/browser/streams/stream_context.cc index 3782205..d3b4f07 100644 --- content/browser/streams/stream_context.cc +++ content/browser/streams/stream_context.cc @@ -21,6 +21,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 075ae3e..57fb5fd 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/public/browser/browser_context.h content/public/browser/browser_context.h index 89461da..619996f 100644 --- content/public/browser/browser_context.h +++ content/public/browser/browser_context.h @@ -171,6 +171,8 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { static ServiceManagerConnection* GetServiceManagerConnectionFor( BrowserContext* browser_context); + static const void* GetStoragePartitionMapUserDataKey(); + ~BrowserContext() override; // Shuts down the storage partitions associated to this browser context. @@ -246,6 +248,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; // Registers per-browser-context services to be loaded in the browser process diff --git content/public/browser/storage_partition.h content/public/browser/storage_partition.h index 4d4021d..00f0c6a 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; @@ -41,16 +42,25 @@ class DatabaseTracker; namespace content { class AppCacheService; +class BackgroundFetchContext; +class BackgroundSyncContext; +class BluetoothAllowedDevicesMap; +class BroadcastChannelProvider; class BrowserContext; class CacheStorageContext; class DOMStorageContext; class HostZoomLevelContext; class HostZoomMap; class IndexedDBContext; +class PaymentAppContextImpl; class PlatformNotificationContext; class ServiceWorkerContext; class ZoomLevelDelegate; +namespace mojom { +class StoragePartitionService; +} + // Defines what persistent state a child process can access. // // The StoragePartition defines the view each child process has of the @@ -74,6 +84,11 @@ class CONTENT_EXPORT StoragePartition { virtual HostZoomLevelContext* GetHostZoomLevelContext() = 0; virtual ZoomLevelDelegate* GetZoomLevelDelegate() = 0; virtual PlatformNotificationContext* GetPlatformNotificationContext() = 0; + virtual BackgroundFetchContext* GetBackgroundFetchContext() = 0; + virtual BackgroundSyncContext* GetBackgroundSyncContext() = 0; + virtual PaymentAppContextImpl* GetPaymentAppContext() = 0; + virtual BroadcastChannelProvider* GetBroadcastChannelProvider() = 0; + virtual BluetoothAllowedDevicesMap* GetBluetoothAllowedDevicesMap() = 0; enum : uint32_t { REMOVE_DATA_MASK_APPCACHE = 1 << 0, @@ -179,6 +194,10 @@ class CONTENT_EXPORT StoragePartition { // Clear the bluetooth allowed devices map. For test use only. virtual void ClearBluetoothAllowedDevicesMapForTesting() = 0; + // Called by each renderer process once. + virtual void Bind( + mojo::InterfaceRequest request) = 0; + protected: virtual ~StoragePartition() {} };