| Index: content/browser/browser_context.cc
|
| diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
|
| index d1e481c5aa48762bb7e56b196564c9410ce97909..4916ea0b0eb60705155fde2f34526dda2823c18d 100644
|
| --- a/content/browser/browser_context.cc
|
| +++ b/content/browser/browser_context.cc
|
| @@ -12,8 +12,8 @@
|
| #include "content/browser/in_process_webkit/indexed_db_context_impl.h"
|
| #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
|
| #include "content/public/browser/resource_context.h"
|
| -#include "content/browser/storage_partition.h"
|
| -#include "content/browser/storage_partition_map.h"
|
| +#include "content/browser/storage_partition_impl.h"
|
| +#include "content/browser/storage_partition_impl_map.h"
|
| #include "content/common/child_process_host_impl.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/content_browser_client.h"
|
| @@ -36,53 +36,22 @@ namespace {
|
| StoragePartition* GetStoragePartitionByPartitionId(
|
| BrowserContext* browser_context,
|
| const std::string& partition_id) {
|
| - StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>(
|
| - browser_context->GetUserData(kStorageParitionMapKeyName));
|
| + StoragePartitionImplMap* partition_map =
|
| + static_cast<StoragePartitionImplMap*>(
|
| + browser_context->GetUserData(kStorageParitionMapKeyName));
|
| if (!partition_map) {
|
| - partition_map = new StoragePartitionMap(browser_context);
|
| + partition_map = new StoragePartitionImplMap(browser_context);
|
| browser_context->SetUserData(kStorageParitionMapKeyName, partition_map);
|
| }
|
|
|
| return partition_map->Get(partition_id);
|
| }
|
|
|
| -StoragePartition* GetStoragePartition(BrowserContext* browser_context,
|
| - int renderer_child_id) {
|
| - const std::string& partition_id =
|
| - GetContentClient()->browser()->GetStoragePartitionIdForChildProcess(
|
| - browser_context,
|
| - renderer_child_id);
|
| -
|
| - return GetStoragePartitionByPartitionId(browser_context, partition_id);
|
| -}
|
| -
|
| -// Run |callback| on each storage partition in |browser_context|.
|
| -void ForEachStoragePartition(
|
| - BrowserContext* browser_context,
|
| - const base::Callback<void(StoragePartition*)>& callback) {
|
| - StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>(
|
| - browser_context->GetUserData(kStorageParitionMapKeyName));
|
| - if (!partition_map) {
|
| - return;
|
| - }
|
| -
|
| - partition_map->ForEach(callback);
|
| -}
|
| -
|
| -// Used to convert a callback meant to take a DOMStorageContextImpl* into one
|
| -// that can take a StoragePartition*.
|
| -void ProcessDOMStorageContext(
|
| - const base::Callback<void(DOMStorageContextImpl*)>& callback,
|
| - StoragePartition* partition) {
|
| - callback.Run(partition->dom_storage_context());
|
| -}
|
| -
|
| // Run |callback| on each DOMStorageContextImpl in |browser_context|.
|
| -void ForEachDOMStorageContext(
|
| - BrowserContext* browser_context,
|
| - const base::Callback<void(DOMStorageContextImpl*)>& callback) {
|
| - ForEachStoragePartition(browser_context,
|
| - base::Bind(&ProcessDOMStorageContext, callback));
|
| +void PurgeDOMStorageContextInPartition(const std::string& id,
|
| + StoragePartition* storage_partition) {
|
| + static_cast<StoragePartitionImpl*>(storage_partition)->
|
| + GetDOMStorageContext()->PurgeMemory();
|
| }
|
|
|
| void SaveSessionStateOnIOThread(ResourceContext* resource_context) {
|
| @@ -103,12 +72,6 @@ void PurgeMemoryOnIOThread(ResourceContext* resource_context) {
|
| ResourceContext::GetAppCacheService(resource_context)->PurgeMemory();
|
| }
|
|
|
| -DOMStorageContextImpl* GetDefaultDOMStorageContextImpl(
|
| - BrowserContext* context) {
|
| - return static_cast<DOMStorageContextImpl*>(
|
| - BrowserContext::GetDefaultDOMStorageContext(context));
|
| -}
|
| -
|
| } // namespace
|
|
|
| DownloadManager* BrowserContext::GetDownloadManager(
|
| @@ -138,87 +101,82 @@ DownloadManager* BrowserContext::GetDownloadManager(
|
|
|
| quota::QuotaManager* BrowserContext::GetQuotaManager(
|
| BrowserContext* browser_context) {
|
| - // TODO(ajwong): Change this API to require a process id instead of using
|
| - // kInvalidChildProcessId.
|
| - StoragePartition* partition =
|
| - GetStoragePartition(browser_context,
|
| - ChildProcessHostImpl::kInvalidChildProcessId);
|
| - return partition->quota_manager();
|
| + // TODO(ajwong): Change this API to require a SiteInstance instead of
|
| + // using GetDefaultStoragePartition().
|
| + return GetDefaultStoragePartition(browser_context)->GetQuotaManager();
|
| }
|
|
|
| -DOMStorageContext* BrowserContext::GetDefaultDOMStorageContext(
|
| +IndexedDBContext* BrowserContext::GetIndexedDBContext(
|
| BrowserContext* browser_context) {
|
| - // TODO(ajwong): Force all users to know which process id they are performing
|
| - // actions on behalf of, migrate them to GetDOMStorageContext(), and then
|
| - // delete this function.
|
| - return GetDOMStorageContext(browser_context,
|
| - ChildProcessHostImpl::kInvalidChildProcessId);
|
| + // TODO(ajwong): Change this API to require a SiteInstance instead of
|
| + // using GetDefaultStoragePartition().
|
| + return GetDefaultStoragePartition(browser_context)->GetIndexedDBContext();
|
| }
|
|
|
| -DOMStorageContext* BrowserContext::GetDOMStorageContext(
|
| - BrowserContext* browser_context,
|
| - int render_child_id) {
|
| - StoragePartition* partition =
|
| - GetStoragePartition(browser_context, render_child_id);
|
| - return partition->dom_storage_context();
|
| +webkit_database::DatabaseTracker* BrowserContext::GetDatabaseTracker(
|
| + BrowserContext* browser_context) {
|
| + // TODO(ajwong): Change this API to require a SiteInstance instead of
|
| + // using GetDefaultStoragePartition().
|
| + return GetDefaultStoragePartition(browser_context)->GetDatabaseTracker();
|
| }
|
|
|
| -DOMStorageContext* BrowserContext::GetDOMStorageContextByPartitionId(
|
| - BrowserContext* browser_context,
|
| - const std::string& partition_id) {
|
| - StoragePartition* partition =
|
| - GetStoragePartitionByPartitionId(browser_context, partition_id);
|
| - return partition->dom_storage_context();
|
| +appcache::AppCacheService* BrowserContext::GetAppCacheService(
|
| + BrowserContext* browser_context) {
|
| + // TODO(ajwong): Change this API to require a SiteInstance instead of
|
| + // using GetDefaultStoragePartition().
|
| + return GetDefaultStoragePartition(browser_context)->GetAppCacheService();
|
| }
|
|
|
| -IndexedDBContext* BrowserContext::GetIndexedDBContext(
|
| +fileapi::FileSystemContext* BrowserContext::GetFileSystemContext(
|
| BrowserContext* browser_context) {
|
| - // TODO(ajwong): Change this API to require a process id instead of using
|
| - // kInvalidChildProcessId.
|
| - StoragePartition* partition =
|
| - GetStoragePartition(browser_context,
|
| - ChildProcessHostImpl::kInvalidChildProcessId);
|
| - return partition->indexed_db_context();
|
| + // TODO(ajwong): Change this API to require a SiteInstance instead of
|
| + // using GetDefaultStoragePartition().
|
| + return GetDefaultStoragePartition(browser_context)->GetFileSystemContext();
|
| }
|
|
|
| -webkit_database::DatabaseTracker* BrowserContext::GetDatabaseTracker(
|
| - BrowserContext* browser_context) {
|
| - // TODO(ajwong): Change this API to require a process id instead of using
|
| - // kInvalidChildProcessId.
|
| - StoragePartition* partition =
|
| - GetStoragePartition(browser_context,
|
| - ChildProcessHostImpl::kInvalidChildProcessId);
|
| - return partition->database_tracker();
|
| +StoragePartition* BrowserContext::GetStoragePartition(
|
| + BrowserContext* browser_context,
|
| + SiteInstance* site_instance) {
|
| + std::string partition_id; // Default to "" for NULL |site_instance|.
|
| +
|
| + // TODO(ajwong): After GetDefaultStoragePartition() is removed, get rid of
|
| + // this conditional and require that |site_instance| is non-NULL.
|
| + if (site_instance) {
|
| + partition_id = GetContentClient()->browser()->
|
| + GetStoragePartitionIdForSiteInstance(browser_context,
|
| + site_instance);
|
| + }
|
| +
|
| + return GetStoragePartitionByPartitionId(browser_context, partition_id);
|
| }
|
|
|
| -appcache::AppCacheService* BrowserContext::GetAppCacheService(
|
| - BrowserContext* browser_context) {
|
| - // TODO(ajwong): Change this API to require a process id instead of using
|
| - // kInvalidChildProcessId.
|
| - StoragePartition* partition =
|
| - GetStoragePartition(browser_context,
|
| - ChildProcessHostImpl::kInvalidChildProcessId);
|
| - return partition->appcache_service();
|
| +void BrowserContext::ForEachStoragePartition(
|
| + BrowserContext* browser_context,
|
| + const StoragePartitionCallback& callback) {
|
| + StoragePartitionImplMap* partition_map =
|
| + static_cast<StoragePartitionImplMap*>(
|
| + browser_context->GetUserData(kStorageParitionMapKeyName));
|
| + if (!partition_map)
|
| + return;
|
| +
|
| + partition_map->ForEach(callback);
|
| }
|
|
|
| -fileapi::FileSystemContext* BrowserContext::GetFileSystemContext(
|
| +StoragePartition* BrowserContext::GetDefaultStoragePartition(
|
| BrowserContext* browser_context) {
|
| - // TODO(ajwong): Change this API to require a process id instead of using
|
| - // kInvalidChildProcessId.
|
| - StoragePartition* partition =
|
| - GetStoragePartition(browser_context,
|
| - ChildProcessHostImpl::kInvalidChildProcessId);
|
| - return partition->filesystem_context();
|
| + return GetStoragePartition(browser_context, NULL);
|
| }
|
|
|
| void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) {
|
| // This will be enough to tickle initialization of BrowserContext if
|
| // necessary, which initializes ResourceContext. The reason we don't call
|
| - // ResourceContext::InitializeResourceContext directly here is that if
|
| - // ResourceContext ends up initializing it will call back into BrowserContext
|
| - // and when that call returns it'll end rewriting its UserData map (with the
|
| - // same value) but this causes a race condition. See http://crbug.com/115678.
|
| - GetStoragePartition(context, ChildProcessHostImpl::kInvalidChildProcessId);
|
| + // ResourceContext::InitializeResourceContext() directly here is that
|
| + // ResourceContext initialization may call back into BrowserContext
|
| + // and when that call returns it'll end rewriting its UserData map. It will
|
| + // end up rewriting the same value but this still causes a race condition.
|
| + //
|
| + // See http://crbug.com/115678.
|
| + GetDefaultStoragePartition(context);
|
| }
|
|
|
| void BrowserContext::SaveSessionState(BrowserContext* browser_context) {
|
| @@ -231,10 +189,10 @@ void BrowserContext::SaveSessionState(BrowserContext* browser_context) {
|
| browser_context->GetResourceContext()));
|
| }
|
|
|
| - // TODO(ajwong): This is the only usage of GetDefaultDOMStorageContextImpl().
|
| - // After we migrate this to support multiple DOMStorageContexts, don't forget
|
| - // to remove the GetDefaultDOMStorageContextImpl() function as well.
|
| - GetDefaultDOMStorageContextImpl(browser_context)->SetForceKeepSessionState();
|
| + DOMStorageContextImpl* dom_storage_context_impl =
|
| + static_cast<DOMStorageContextImpl*>(
|
| + GetDefaultStoragePartition(browser_context)->GetDOMStorageContext());
|
| + dom_storage_context_impl->SetForceKeepSessionState();
|
|
|
| if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) {
|
| IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>(
|
| @@ -254,8 +212,8 @@ void BrowserContext::PurgeMemory(BrowserContext* browser_context) {
|
| browser_context->GetResourceContext()));
|
| }
|
|
|
| - ForEachDOMStorageContext(browser_context,
|
| - base::Bind(&DOMStorageContextImpl::PurgeMemory));
|
| + ForEachStoragePartition(browser_context,
|
| + base::Bind(&PurgeDOMStorageContextInPartition));
|
| }
|
|
|
| BrowserContext::~BrowserContext() {
|
|
|