summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-17 16:49:29 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-17 16:49:29 +0000
commit7fd47a85b9e070b1acbe4d6129f0edb9e3498099 (patch)
tree26a20943bc57da6e615b6b67f4bc039adffaaa02 /content
parentadb57e8c2fe59d5e27fac60f7870fd5157e8aca7 (diff)
downloadchromium_src-7fd47a85b9e070b1acbe4d6129f0edb9e3498099.zip
chromium_src-7fd47a85b9e070b1acbe4d6129f0edb9e3498099.tar.gz
chromium_src-7fd47a85b9e070b1acbe4d6129f0edb9e3498099.tar.bz2
Move creation of BrowserContext objects that live in content to content, instead of depending on the embedder. Apart from allowing us to hide more of content from embedders, it simplifies the work that every embedder has to do (see the change the shell_browser_context.cc as an example).
BUG=98716 Review URL: https://chromiumcodereview.appspot.com/9419033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122521 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/browser_context.cc164
-rw-r--r--content/browser/browser_context.h13
-rw-r--r--content/browser/file_system/file_system_browsertest.cc3
-rw-r--r--content/browser/in_process_webkit/dom_storage_browsertest.cc3
-rw-r--r--content/browser/in_process_webkit/dom_storage_unittest.cc28
-rw-r--r--content/browser/in_process_webkit/indexed_db_browsertest.cc27
-rw-r--r--content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc6
-rw-r--r--content/browser/renderer_host/render_message_filter.cc3
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc18
-rw-r--r--content/browser/renderer_host/render_view_host.cc3
-rw-r--r--content/browser/tab_contents/navigation_controller_impl.cc2
-rw-r--r--content/content_browser.gypi1
-rw-r--r--content/public/browser/browser_context.cc10
-rw-r--r--content/public/browser/browser_context.h25
-rw-r--r--content/public/common/content_constants.cc3
-rw-r--r--content/public/common/content_constants.h5
-rw-r--r--content/shell/shell_browser_context.cc76
-rw-r--r--content/shell/shell_browser_context.h14
-rw-r--r--content/test/test_browser_context.cc31
-rw-r--r--content/test/test_browser_context.h14
-rw-r--r--content/test/test_browser_thread.cc16
21 files changed, 277 insertions, 188 deletions
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
new file mode 100644
index 0000000..db95d2a
--- /dev/null
+++ b/content/browser/browser_context.cc
@@ -0,0 +1,164 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/browser/browser_context.h"
+
+#include "content/browser/appcache/chrome_appcache_service.h"
+#include "content/browser/chrome_blob_storage_context.h"
+#include "content/browser/file_system/browser_file_system_helper.h"
+#include "content/browser/in_process_webkit/webkit_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/common/content_constants.h"
+#include "webkit/database/database_tracker.h"
+#include "webkit/quota/quota_manager.h"
+
+using content::BrowserThread;
+using fileapi::FileSystemContext;
+using quota::QuotaManager;
+using webkit_database::DatabaseTracker;
+
+static const char* kAppCacheServicKeyName = "content_appcache_service_tracker";
+static const char* kBlobStorageContextKeyName = "content_blob_storage_context";
+static const char* kDatabaseTrackerKeyName = "content_database_tracker";
+static const char* kFileSystemContextKeyName = "content_file_system_context";
+static const char* kQuotaManagerKeyName = "content_quota_manager";
+static const char* kWebKitContextKeyName = "content_webkit_context";
+
+namespace content {
+
+// Adapter class that releases a refcounted object when the
+// SupportsUserData::Data object is deleted.
+template <typename T>
+class UserDataAdapter : public base::SupportsUserData::Data {
+ public:
+ static T* Get(BrowserContext* context, const char* key) {
+ UserDataAdapter* data =
+ static_cast<UserDataAdapter*>(context->GetUserData(key));
+ return static_cast<T*>(data->object_.get());
+ }
+
+ UserDataAdapter(T* object) : object_(object) {}
+
+ private:
+ scoped_refptr<T> object_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserDataAdapter);
+};
+
+void CreateQuotaManagerAndClients(BrowserContext* context) {
+ if (context->GetUserData(kQuotaManagerKeyName)) {
+ DCHECK(context->GetUserData(kDatabaseTrackerKeyName));
+ DCHECK(context->GetUserData(kFileSystemContextKeyName));
+ DCHECK(context->GetUserData(kWebKitContextKeyName));
+ return;
+ }
+
+ // All of the clients have to be created and registered with the
+ // QuotaManager prior to the QuotaManger being used. So we do them
+ // all together here prior to handing out a reference to anything
+ // that utlizes the QuotaManager.
+ scoped_refptr<QuotaManager> quota_manager = new quota::QuotaManager(
+ context->IsOffTheRecord(), context->GetPath(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
+ context->GetSpecialStoragePolicy());
+ context->SetUserData(kQuotaManagerKeyName,
+ new UserDataAdapter<QuotaManager>(quota_manager));
+
+ // Each consumer is responsible for registering its QuotaClient during
+ // its construction.
+ scoped_refptr<FileSystemContext> filesystem_context = CreateFileSystemContext(
+ context->GetPath(), context->IsOffTheRecord(),
+ context->GetSpecialStoragePolicy(), quota_manager->proxy());
+ context->SetUserData(
+ kFileSystemContextKeyName,
+ new UserDataAdapter<FileSystemContext>(filesystem_context));
+
+ scoped_refptr<DatabaseTracker> db_tracker = new DatabaseTracker(
+ context->GetPath(), context->IsOffTheRecord(), false,
+ context->GetSpecialStoragePolicy(), quota_manager->proxy(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
+ context->SetUserData(kDatabaseTrackerKeyName,
+ new UserDataAdapter<DatabaseTracker>(db_tracker));
+
+ scoped_refptr<WebKitContext> webkit_context = new WebKitContext(
+ context->IsOffTheRecord(), context->GetPath(),
+ context->GetSpecialStoragePolicy(), false, quota_manager->proxy(),
+ BrowserThread::GetMessageLoopProxyForThread(
+ BrowserThread::WEBKIT_DEPRECATED));
+ context->SetUserData(kWebKitContextKeyName,
+ new UserDataAdapter<WebKitContext>(webkit_context));
+
+ scoped_refptr<ChromeAppCacheService> appcache_service =
+ new ChromeAppCacheService(quota_manager->proxy());
+ context->SetUserData(
+ kAppCacheServicKeyName,
+ new UserDataAdapter<ChromeAppCacheService>(appcache_service));
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ChromeAppCacheService::InitializeOnIOThread,
+ appcache_service,
+ context->IsOffTheRecord() ? FilePath() :
+ context->GetPath().Append(content::kAppCacheDirname),
+ context->GetResourceContext(),
+ make_scoped_refptr(context->GetSpecialStoragePolicy())));
+}
+
+QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) {
+ CreateQuotaManagerAndClients(context);
+ return UserDataAdapter<QuotaManager>::Get(context, kQuotaManagerKeyName);
+}
+
+WebKitContext* BrowserContext::GetWebKitContext(BrowserContext* context) {
+ CreateQuotaManagerAndClients(context);
+ return UserDataAdapter<WebKitContext>::Get(context, kWebKitContextKeyName);
+}
+
+DatabaseTracker* BrowserContext::GetDatabaseTracker(BrowserContext* context) {
+ CreateQuotaManagerAndClients(context);
+ return UserDataAdapter<DatabaseTracker>::Get(
+ context, kDatabaseTrackerKeyName);
+}
+
+ChromeAppCacheService* BrowserContext::GetAppCacheService(
+ BrowserContext* browser_context) {
+ CreateQuotaManagerAndClients(browser_context);
+ return UserDataAdapter<ChromeAppCacheService>::Get(
+ browser_context, kAppCacheServicKeyName);
+}
+
+FileSystemContext* BrowserContext::GetFileSystemContext(
+ BrowserContext* browser_context) {
+ CreateQuotaManagerAndClients(browser_context);
+ return UserDataAdapter<FileSystemContext>::Get(
+ browser_context, kFileSystemContextKeyName);
+}
+
+ChromeBlobStorageContext* BrowserContext::GetBlobStorageContext(
+ BrowserContext* context) {
+ if (!context->GetUserData(kBlobStorageContextKeyName)) {
+ scoped_refptr<ChromeBlobStorageContext> blob =
+ new ChromeBlobStorageContext();
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob));
+ context->SetUserData(kBlobStorageContextKeyName,
+ new UserDataAdapter<ChromeBlobStorageContext>(blob));
+ }
+
+ return UserDataAdapter<ChromeBlobStorageContext>::Get(
+ context, kBlobStorageContextKeyName);
+}
+
+BrowserContext::~BrowserContext() {
+ if (GetUserData(kDatabaseTrackerKeyName)) {
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&webkit_database::DatabaseTracker::Shutdown,
+ GetDatabaseTracker(this)));
+ }
+}
+
+} // namespace content
diff --git a/content/browser/browser_context.h b/content/browser/browser_context.h
deleted file mode 100644
index 8bdb181..0000000
--- a/content/browser/browser_context.h
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_BROWSER_BROWSER_CONTEXT_H_
-#define CONTENT_BROWSER_BROWSER_CONTEXT_H_
-#pragma once
-
-// Deprecated header.
-// TODO(joi): Remove in a follow-up change.
-#include "content/public/browser/browser_context.h"
-
-#endif // CONTENT_BROWSER_BROWSER_CONTEXT_H_
diff --git a/content/browser/file_system/file_system_browsertest.cc b/content/browser/file_system/file_system_browsertest.cc
index 582cd08..edd7cc9 100644
--- a/content/browser/file_system/file_system_browsertest.cc
+++ b/content/browser/file_system/file_system_browsertest.cc
@@ -58,7 +58,8 @@ class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest {
const int kTemporaryStorageQuotaMaxSize =
kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion;
SetTempQuota(
- kTemporaryStorageQuotaMaxSize, browser()->profile()->GetQuotaManager());
+ kTemporaryStorageQuotaMaxSize,
+ content::BrowserContext::GetQuotaManager(browser()->profile()));
}
static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) {
diff --git a/content/browser/in_process_webkit/dom_storage_browsertest.cc b/content/browser/in_process_webkit/dom_storage_browsertest.cc
index 2456399..cdd4d55 100644
--- a/content/browser/in_process_webkit/dom_storage_browsertest.cc
+++ b/content/browser/in_process_webkit/dom_storage_browsertest.cc
@@ -11,6 +11,7 @@
#include "content/browser/in_process_webkit/dom_storage_context.h"
#include "content/browser/in_process_webkit/webkit_context.h"
+using content::BrowserContext;
using content::BrowserThread;
typedef InProcessBrowserTest DOMStorageBrowserTest;
@@ -39,7 +40,7 @@ IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ClearLocalState) {
// context which should trigger the clean up.
{
TestingProfile profile;
- WebKitContext *webkit_context = profile.GetWebKitContext();
+ WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile);
webkit_context->dom_storage_context()->
set_data_path_for_testing(temp_dir.path());
webkit_context->set_clear_local_state_on_exit(true);
diff --git a/content/browser/in_process_webkit/dom_storage_unittest.cc b/content/browser/in_process_webkit/dom_storage_unittest.cc
index 355871e..049fbb3 100644
--- a/content/browser/in_process_webkit/dom_storage_unittest.cc
+++ b/content/browser/in_process_webkit/dom_storage_unittest.cc
@@ -10,6 +10,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/quota/mock_special_storage_policy.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::BrowserThreadImpl;
@@ -33,10 +34,10 @@ TEST_F(DOMStorageTest, SessionOnly) {
new quota::MockSpecialStoragePolicy;
special_storage_policy->AddSessionOnly(session_only_origin);
- TestBrowserContext browser_context;
+ scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext);
// Create databases for permanent and session-only origins.
- FilePath domstorage_dir = browser_context.GetPath().Append(
+ FilePath domstorage_dir = browser_context->GetPath().Append(
DOMStorageContext::kLocalStorageDirectory);
FilePath::StringType session_only_database(
FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
@@ -55,12 +56,14 @@ TEST_F(DOMStorageTest, SessionOnly) {
ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1));
// Inject MockSpecialStoragePolicy into DOMStorageContext.
- browser_context.GetWebKitContext()->dom_storage_context()->
- special_storage_policy_ = special_storage_policy;
+ BrowserContext::GetWebKitContext(browser_context.get())->
+ dom_storage_context()->special_storage_policy_ = special_storage_policy;
- // Delete the WebKitContext before destroying TestBrowserContext. This way the
+ // Delete the TestBrowserContext but own the temp dir. This way the
// temporary data directory stays alive long enough to conduct the test.
- browser_context.webkit_context_ = NULL;
+ ScopedTempDir temp_dir;
+ ignore_result(temp_dir.Set(browser_context->TakePath()));
+ browser_context.reset();
// Run the message loop to ensure that DOMStorageContext gets destroyed.
message_loop_.RunAllPending();
@@ -76,10 +79,10 @@ TEST_F(DOMStorageTest, SaveSessionState) {
new quota::MockSpecialStoragePolicy;
special_storage_policy->AddSessionOnly(session_only_origin);
- TestBrowserContext browser_context;
+ scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext);
// Create databases for permanent and session-only origins.
- FilePath domstorage_dir = browser_context.GetPath().Append(
+ FilePath domstorage_dir = browser_context->GetPath().Append(
DOMStorageContext::kLocalStorageDirectory);
FilePath::StringType session_only_database(
FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
@@ -99,7 +102,8 @@ TEST_F(DOMStorageTest, SaveSessionState) {
// Inject MockSpecialStoragePolicy into DOMStorageContext.
DOMStorageContext* dom_storage_context =
- browser_context.GetWebKitContext()->dom_storage_context();
+ BrowserContext::GetWebKitContext(browser_context.get())->
+ dom_storage_context();
dom_storage_context->special_storage_policy_ = special_storage_policy;
dom_storage_context->set_clear_local_state_on_exit_(true);
@@ -107,9 +111,11 @@ TEST_F(DOMStorageTest, SaveSessionState) {
// Save session state. This should bypass the destruction-time deletion.
dom_storage_context->SaveSessionState();
- // Delete the WebKitContext before destroying TestBrowserContext. This way the
+ // Delete the TestBrowserContext but own the temp dir. This way the
// temporary data directory stays alive long enough to conduct the test.
- browser_context.webkit_context_ = NULL;
+ ScopedTempDir temp_dir;
+ ignore_result(temp_dir.Set(browser_context->TakePath()));
+ browser_context.reset();
// Run the message loop to ensure that DOMStorageContext gets destroyed.
message_loop_.RunAllPending();
diff --git a/content/browser/in_process_webkit/indexed_db_browsertest.cc b/content/browser/in_process_webkit/indexed_db_browsertest.cc
index 003d4b5..d1fcb5a 100644
--- a/content/browser/in_process_webkit/indexed_db_browsertest.cc
+++ b/content/browser/in_process_webkit/indexed_db_browsertest.cc
@@ -23,6 +23,7 @@
#include "webkit/quota/quota_manager.h"
#include "webkit/quota/special_storage_policy.h"
+using content::BrowserContext;
using content::BrowserThread;
using quota::QuotaManager;
using webkit_database::DatabaseUtil;
@@ -153,7 +154,7 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearLocalState) {
// Create some indexedDB paths.
// With the levelDB backend, these are directories.
- WebKitContext *webkit_context = profile.GetWebKitContext();
+ WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile);
IndexedDBContext* idb_context = webkit_context->indexed_db_context();
idb_context->set_data_path_for_testing(temp_dir.path());
protected_path = idb_context->GetIndexedDBFilePath(
@@ -168,11 +169,15 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearLocalState) {
}
// Make sure we wait until the destructor has run.
- scoped_refptr<base::ThreadTestHelper> helper(
+ scoped_refptr<base::ThreadTestHelper> helper_io(
+ new base::ThreadTestHelper(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
+ ASSERT_TRUE(helper_io->Run());
+ scoped_refptr<base::ThreadTestHelper> helper_webkit(
new base::ThreadTestHelper(
BrowserThread::GetMessageLoopProxyForThread(
BrowserThread::WEBKIT_DEPRECATED)));
- ASSERT_TRUE(helper->Run());
+ ASSERT_TRUE(helper_webkit->Run());
ASSERT_TRUE(file_util::DirectoryExists(protected_path));
ASSERT_FALSE(file_util::DirectoryExists(unprotected_path));
@@ -200,7 +205,7 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearSessionOnlyDatabases) {
// Create some indexedDB paths.
// With the levelDB backend, these are directories.
- WebKitContext *webkit_context = profile.GetWebKitContext();
+ WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile);
IndexedDBContext* idb_context = webkit_context->indexed_db_context();
// Override the storage policy with our own.
@@ -215,12 +220,15 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearSessionOnlyDatabases) {
ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
}
- // Make sure we wait until the destructor has run.
- scoped_refptr<base::ThreadTestHelper> helper(
+ scoped_refptr<base::ThreadTestHelper> helper_io(
+ new base::ThreadTestHelper(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
+ ASSERT_TRUE(helper_io->Run());
+ scoped_refptr<base::ThreadTestHelper> helper_webkit(
new base::ThreadTestHelper(
BrowserThread::GetMessageLoopProxyForThread(
BrowserThread::WEBKIT_DEPRECATED)));
- ASSERT_TRUE(helper->Run());
+ ASSERT_TRUE(helper_webkit->Run());
EXPECT_TRUE(file_util::DirectoryExists(normal_path));
EXPECT_FALSE(file_util::DirectoryExists(session_only_path));
@@ -246,7 +254,7 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, SaveSessionState) {
// Create some indexedDB paths.
// With the levelDB backend, these are directories.
- WebKitContext *webkit_context = profile.GetWebKitContext();
+ WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile);
IndexedDBContext* idb_context = webkit_context->indexed_db_context();
// Override the storage policy with our own.
@@ -284,7 +292,8 @@ class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest {
const int kTemporaryStorageQuotaMaxSize = kInitialQuotaKilobytes
* 1024 * QuotaManager::kPerHostTemporaryPortion;
SetTempQuota(
- kTemporaryStorageQuotaMaxSize, browser()->profile()->GetQuotaManager());
+ kTemporaryStorageQuotaMaxSize,
+ content::BrowserContext::GetQuotaManager(browser()->profile()));
}
static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) {
diff --git a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc
index 04e7041..0689eeb 100644
--- a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc
+++ b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc
@@ -18,6 +18,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/database/database_util.h"
+using content::BrowserContext;
using content::BrowserThread;
// Declared to shorten the line lengths.
@@ -42,9 +43,11 @@ class IndexedDBQuotaClientTest : public testing::Test {
weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
message_loop_(MessageLoop::TYPE_IO),
webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_),
+ file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_),
io_thread_(BrowserThread::IO, &message_loop_) {
TestBrowserContext browser_context;
- idb_context_ = browser_context.GetWebKitContext()->indexed_db_context();
+ idb_context_ = BrowserContext::GetWebKitContext(&browser_context)->
+ indexed_db_context();
setup_temp_dir();
}
void setup_temp_dir() {
@@ -158,6 +161,7 @@ class IndexedDBQuotaClientTest : public testing::Test {
base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_;
MessageLoop message_loop_;
BrowserThreadImpl webkit_thread_;
+ BrowserThreadImpl file_thread_;
BrowserThreadImpl io_thread_;
quota::QuotaStatusCode delete_status_;
};
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index dde71d0..a05771e 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -67,6 +67,7 @@
#include "base/file_descriptor_posix.h"
#endif
+using content::BrowserContext;
using content::BrowserMessageFilter;
using content::BrowserThread;
using content::ChildProcessHostImpl;
@@ -273,7 +274,7 @@ RenderMessageFilter::RenderMessageFilter(
resource_context_(browser_context->GetResourceContext()),
render_widget_helper_(render_widget_helper),
incognito_(browser_context->IsOffTheRecord()),
- webkit_context_(browser_context->GetWebKitContext()),
+ webkit_context_(BrowserContext::GetWebKitContext(browser_context)),
render_process_id_(render_process_id),
cpu_usage_(0) {
DCHECK(request_context_);
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 6b3973b..f9dd954 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -114,6 +114,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
+using content::BrowserContext;
using content::BrowserMessageFilter;
using content::BrowserThread;
using content::ChildProcessHost;
@@ -460,12 +461,12 @@ void RenderProcessHostImpl::CreateMessageFilters() {
channel_->AddFilter(new AudioRendererHost(resource_context));
channel_->AddFilter(new VideoCaptureHost(resource_context));
channel_->AddFilter(new AppCacheDispatcherHost(
- browser_context->GetAppCacheService(), GetID()));
+ BrowserContext::GetAppCacheService(browser_context), GetID()));
channel_->AddFilter(new ClipboardMessageFilter());
channel_->AddFilter(new DOMStorageMessageFilter(GetID(),
- browser_context->GetWebKitContext()));
+ BrowserContext::GetWebKitContext(browser_context)));
channel_->AddFilter(new IndexedDBDispatcherHost(GetID(),
- browser_context->GetWebKitContext()));
+ BrowserContext::GetWebKitContext(browser_context)));
channel_->AddFilter(GeolocationDispatcherHost::New(
GetID(), browser_context->GetGeolocationPermissionContext()));
channel_->AddFilter(new GpuMessageFilter(GetID(), widget_helper_.get()));
@@ -478,14 +479,14 @@ void RenderProcessHostImpl::CreateMessageFilters() {
browser_context->GetSpeechInputPreferences(), resource_context));
channel_->AddFilter(new FileSystemDispatcherHost(
browser_context->GetRequestContext(),
- browser_context->GetFileSystemContext()));
+ BrowserContext::GetFileSystemContext(browser_context)));
channel_->AddFilter(new device_orientation::MessageFilter());
channel_->AddFilter(new BlobMessageFilter(GetID(),
- browser_context->GetBlobStorageContext()));
+ BrowserContext::GetBlobStorageContext(browser_context)));
channel_->AddFilter(new FileUtilitiesMessageFilter(GetID()));
channel_->AddFilter(new MimeRegistryMessageFilter());
channel_->AddFilter(new DatabaseMessageFilter(
- browser_context->GetDatabaseTracker()));
+ BrowserContext::GetDatabaseTracker(browser_context)));
#if defined(OS_MACOSX)
channel_->AddFilter(new TextInputClientMessageFilter(GetID()));
#elif defined(OS_WIN)
@@ -509,8 +510,9 @@ void RenderProcessHostImpl::CreateMessageFilters() {
channel_->AddFilter(new TraceMessageFilter());
channel_->AddFilter(new ResolveProxyMsgHelper(
browser_context->GetRequestContextForRenderProcess(GetID())));
- channel_->AddFilter(new QuotaDispatcherHost(GetID(),
- browser_context->GetQuotaManager(),
+ channel_->AddFilter(new QuotaDispatcherHost(
+ GetID(),
+ content::BrowserContext::GetQuotaManager(browser_context),
content::GetContentClient()->browser()->CreateQuotaPermissionContext()));
channel_->AddFilter(new content::GamepadBrowserMessageFilter(this));
channel_->AddFilter(new ProfilerMessageFilter());
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc
index 9e6086d..4b74771 100644
--- a/content/browser/renderer_host/render_view_host.cc
+++ b/content/browser/renderer_host/render_view_host.cc
@@ -59,6 +59,7 @@
#include "webkit/glue/webdropdata.h"
using base::TimeDelta;
+using content::BrowserContext;
using content::BrowserMessageFilter;
using content::BrowserThread;
using content::DomOperationNotificationDetails;
@@ -136,7 +137,7 @@ RenderViewHost::RenderViewHost(SiteInstance* instance,
render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING) {
if (!session_storage_namespace_) {
session_storage_namespace_ = new SessionStorageNamespace(
- process()->GetBrowserContext()->GetWebKitContext());
+ BrowserContext::GetWebKitContext(process()->GetBrowserContext()));
}
DCHECK(instance_);
diff --git a/content/browser/tab_contents/navigation_controller_impl.cc b/content/browser/tab_contents/navigation_controller_impl.cc
index e72fc89..0e893bd 100644
--- a/content/browser/tab_contents/navigation_controller_impl.cc
+++ b/content/browser/tab_contents/navigation_controller_impl.cc
@@ -183,7 +183,7 @@ NavigationControllerImpl::NavigationControllerImpl(
DCHECK(browser_context_);
if (!session_storage_namespace_) {
session_storage_namespace_ = new SessionStorageNamespace(
- browser_context_->GetWebKitContext());
+ BrowserContext::GetWebKitContext(browser_context_));
}
}
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 508601d..55c7f13 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -150,6 +150,7 @@
'browser/appcache/chrome_appcache_service.h',
'browser/browser_child_process_host_impl.cc',
'browser/browser_child_process_host_impl.h',
+ 'browser/browser_context.cc',
'browser/browser_main.cc',
'browser/browser_main.h',
'browser/browser_main_loop.cc',
diff --git a/content/public/browser/browser_context.cc b/content/public/browser/browser_context.cc
deleted file mode 100644
index b8f540f..0000000
--- a/content/public/browser/browser_context.cc
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/public/browser/browser_context.h"
-
-namespace content {
-
-
-} // namespace content
diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h
index 9618315..dd00b4a 100644
--- a/content/public/browser/browser_context.h
+++ b/content/public/browser/browser_context.h
@@ -20,6 +20,7 @@ class URLRequestContextGetter;
namespace quota {
class QuotaManager;
+class SpecialStoragePolicy;
}
namespace webkit_database {
@@ -43,7 +44,19 @@ class SpeechInputPreferences;
// It lives on the UI thread.
class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
public:
- virtual ~BrowserContext() {}
+ // Getter for the QuotaManager associated with the given BrowserContext.
+ static quota::QuotaManager* GetQuotaManager(BrowserContext* browser_context);
+ static WebKitContext* GetWebKitContext(BrowserContext* browser_context);
+ static webkit_database::DatabaseTracker* GetDatabaseTracker(
+ BrowserContext* browser_context);
+ static ChromeAppCacheService* GetAppCacheService(
+ BrowserContext* browser_context);
+ static fileapi::FileSystemContext* GetFileSystemContext(
+ BrowserContext* browser_context);
+ static ChromeBlobStorageContext* GetBlobStorageContext(
+ BrowserContext* browser_context);
+
+ virtual ~BrowserContext();
// Returns the path of the directory where this context's data is stored.
virtual FilePath GetPath() = 0;
@@ -90,14 +103,8 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
// This doesn't belong here; http://crbug.com/90737
virtual bool DidLastSessionExitCleanly() = 0;
- // The following getters return references to various storage related
- // contexts associated with this browser context.
- virtual quota::QuotaManager* GetQuotaManager() = 0;
- virtual WebKitContext* GetWebKitContext() = 0;
- virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0;
- virtual ChromeBlobStorageContext* GetBlobStorageContext() = 0;
- virtual ChromeAppCacheService* GetAppCacheService() = 0;
- virtual fileapi::FileSystemContext* GetFileSystemContext() = 0;
+ // Returns a special storage policy implementation, or NULL.
+ virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0;
};
} // namespace content
diff --git a/content/public/common/content_constants.cc b/content/public/common/content_constants.cc
index 743622d5e..4fb5bd6 100644
--- a/content/public/common/content_constants.cc
+++ b/content/public/common/content_constants.cc
@@ -6,6 +6,9 @@
namespace content {
+const FilePath::CharType kAppCacheDirname[] =
+ FILE_PATH_LITERAL("Application Cache");
+
// This number used to be limited to 32 in the past (see b/535234).
const size_t kMaxRendererProcessCount = 82;
const int kMaxSessionHistoryEntries = 50;
diff --git a/content/public/common/content_constants.h b/content/public/common/content_constants.h
index a5e2c53..0df8b8b 100644
--- a/content/public/common/content_constants.h
+++ b/content/public/common/content_constants.h
@@ -10,10 +10,15 @@
#include <stddef.h> // For size_t
+#include "base/file_path.h"
#include "content/common/content_export.h"
namespace content {
+// The name of the directory under BrowserContext::GetPath where the AppCache is
+// put.
+CONTENT_EXPORT extern const FilePath::CharType kAppCacheDirname[];
+
CONTENT_EXPORT extern const size_t kMaxRendererProcessCount;
// The maximum number of session history entries per tab.
diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc
index cd47383..b118413 100644
--- a/content/shell/shell_browser_context.cc
+++ b/content/shell/shell_browser_context.cc
@@ -10,10 +10,7 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "base/threading/thread.h"
-#include "content/browser/appcache/chrome_appcache_service.h"
-#include "content/browser/chrome_blob_storage_context.h"
#include "content/browser/download/download_manager_impl.h"
-#include "content/browser/file_system/browser_file_system_helper.h"
#include "content/browser/host_zoom_map_impl.h"
#include "content/browser/in_process_webkit/webkit_context.h"
#include "content/public/browser/browser_thread.h"
@@ -23,8 +20,6 @@
#include "content/shell/shell_download_manager_delegate.h"
#include "content/shell/shell_resource_context.h"
#include "content/shell/shell_url_request_context_getter.h"
-#include "webkit/database/database_tracker.h"
-#include "webkit/quota/quota_manager.h"
#if defined(OS_WIN)
#include "base/base_paths_win.h"
@@ -164,7 +159,7 @@ ResourceContext* ShellBrowserContext::GetResourceContext() {
if (!resource_context_.get()) {
resource_context_.reset(new ShellResourceContext(
static_cast<ShellURLRequestContextGetter*>(GetRequestContext()),
- GetBlobStorageContext()));
+ BrowserContext::GetBlobStorageContext(this)));
}
return resource_context_.get();
}
@@ -194,73 +189,8 @@ bool ShellBrowserContext::DidLastSessionExitCleanly() {
return true;
}
-quota::QuotaManager* ShellBrowserContext::GetQuotaManager() {
- CreateQuotaManagerAndClients();
- return quota_manager_.get();
-}
-
-WebKitContext* ShellBrowserContext::GetWebKitContext() {
- CreateQuotaManagerAndClients();
- return webkit_context_.get();
-}
-
-webkit_database::DatabaseTracker* ShellBrowserContext::GetDatabaseTracker() {
- CreateQuotaManagerAndClients();
- return db_tracker_;
-}
-
-ChromeBlobStorageContext* ShellBrowserContext::GetBlobStorageContext() {
- if (!blob_storage_context_) {
- blob_storage_context_ = new ChromeBlobStorageContext();
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(
- &ChromeBlobStorageContext::InitializeOnIOThread,
- blob_storage_context_.get()));
- }
- return blob_storage_context_;
-}
-
-ChromeAppCacheService* ShellBrowserContext::GetAppCacheService() {
- CreateQuotaManagerAndClients();
- return appcache_service_;
-}
-
-fileapi::FileSystemContext* ShellBrowserContext::GetFileSystemContext() {
- CreateQuotaManagerAndClients();
- return file_system_context_.get();
-}
-
-void ShellBrowserContext::CreateQuotaManagerAndClients() {
- if (quota_manager_.get())
- return;
- quota_manager_ = new quota::QuotaManager(
- IsOffTheRecord(),
- GetPath(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
- NULL);
-
- file_system_context_ = CreateFileSystemContext(
- GetPath(), IsOffTheRecord(), NULL, quota_manager_->proxy());
- db_tracker_ = new webkit_database::DatabaseTracker(
- GetPath(), IsOffTheRecord(), false, NULL, quota_manager_->proxy(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
- webkit_context_ = new WebKitContext(
- IsOffTheRecord(), GetPath(), NULL, false, quota_manager_->proxy(),
- BrowserThread::GetMessageLoopProxyForThread(
- BrowserThread::WEBKIT_DEPRECATED));
- appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy());
- scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy;
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(
- &ChromeAppCacheService::InitializeOnIOThread,
- appcache_service_.get(),
- IsOffTheRecord()
- ? FilePath() : GetPath().Append(FILE_PATH_LITERAL("AppCache")),
- GetResourceContext(),
- special_storage_policy));
+quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
+ return NULL;
}
} // namespace content
diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h
index 84d29b8..3def4fd 100644
--- a/content/shell/shell_browser_context.h
+++ b/content/shell/shell_browser_context.h
@@ -40,15 +40,9 @@ class ShellBrowserContext : public BrowserContext {
GetGeolocationPermissionContext() OVERRIDE;
virtual SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE;
virtual bool DidLastSessionExitCleanly() OVERRIDE;
- virtual quota::QuotaManager* GetQuotaManager() OVERRIDE;
- virtual WebKitContext* GetWebKitContext() OVERRIDE;
- virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE;
- virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE;
- virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE;
- virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE;
+ virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
private:
- void CreateQuotaManagerAndClients();
FilePath path_;
scoped_ptr<ResourceContext> resource_context_;
@@ -58,12 +52,6 @@ class ShellBrowserContext : public BrowserContext {
scoped_refptr<HostZoomMap> host_zoom_map_;
scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
scoped_refptr<SpeechInputPreferences> speech_input_preferences_;
- scoped_refptr<WebKitContext> webkit_context_;
- scoped_refptr<ChromeAppCacheService> appcache_service_;
- scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
- scoped_refptr<fileapi::FileSystemContext> file_system_context_;
- scoped_refptr<quota::QuotaManager> quota_manager_;
- scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
ShellBrowserMainParts* shell_main_parts_;
diff --git a/content/test/test_browser_context.cc b/content/test/test_browser_context.cc
index bc8a3ee..df3934e 100644
--- a/content/test/test_browser_context.cc
+++ b/content/test/test_browser_context.cc
@@ -19,6 +19,10 @@ TestBrowserContext::TestBrowserContext() {
TestBrowserContext::~TestBrowserContext() {
}
+FilePath TestBrowserContext::TakePath() {
+ return browser_context_dir_.Take();
+}
+
FilePath TestBrowserContext::GetPath() {
return browser_context_dir_.path();
}
@@ -67,31 +71,6 @@ bool TestBrowserContext::DidLastSessionExitCleanly() {
return true;
}
-quota::QuotaManager* TestBrowserContext::GetQuotaManager() {
- return NULL;
-}
-
-WebKitContext* TestBrowserContext::GetWebKitContext() {
- if (webkit_context_ == NULL) {
- webkit_context_ = new WebKitContext(
- IsOffTheRecord(), GetPath(),
- NULL, false, NULL, NULL);
- }
- return webkit_context_;
-}
-
-webkit_database::DatabaseTracker* TestBrowserContext::GetDatabaseTracker() {
- return NULL;
-}
-
-ChromeBlobStorageContext* TestBrowserContext::GetBlobStorageContext() {
- return NULL;
-}
-
-ChromeAppCacheService* TestBrowserContext::GetAppCacheService() {
- return NULL;
-}
-
-fileapi::FileSystemContext* TestBrowserContext::GetFileSystemContext() {
+quota::SpecialStoragePolicy* TestBrowserContext::GetSpecialStoragePolicy() {
return NULL;
}
diff --git a/content/test/test_browser_context.h b/content/test/test_browser_context.h
index ee5acf6..c0873c0 100644
--- a/content/test/test_browser_context.h
+++ b/content/test/test_browser_context.h
@@ -20,6 +20,10 @@ class TestBrowserContext : public content::BrowserContext {
TestBrowserContext();
virtual ~TestBrowserContext();
+ // Takes ownership of the temporary directory so that it's not deleted when
+ // this object is destructed.
+ FilePath TakePath();
+
virtual FilePath GetPath() OVERRIDE;
virtual bool IsOffTheRecord() OVERRIDE;
virtual content::DownloadManager* GetDownloadManager() OVERRIDE;
@@ -33,20 +37,12 @@ class TestBrowserContext : public content::BrowserContext {
GetGeolocationPermissionContext() OVERRIDE;
virtual content::SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE;
virtual bool DidLastSessionExitCleanly() OVERRIDE;
- virtual quota::QuotaManager* GetQuotaManager() OVERRIDE;
- virtual WebKitContext* GetWebKitContext() OVERRIDE;
- virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE;
- virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE;
- virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE;
- virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE;
+ virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
private:
FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SessionOnly);
FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SaveSessionState);
- // WebKitContext, lazily initialized by GetWebKitContext().
- scoped_refptr<WebKitContext> webkit_context_;
-
ScopedTempDir browser_context_dir_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserContext);
diff --git a/content/test/test_browser_thread.cc b/content/test/test_browser_thread.cc
index 9224726..ed8d02c 100644
--- a/content/test/test_browser_thread.cc
+++ b/content/test/test_browser_thread.cc
@@ -7,6 +7,7 @@
#include "base/message_loop.h"
#include "base/threading/thread.h"
#include "content/browser/browser_thread_impl.h"
+#include "content/browser/notification_service_impl.h"
namespace content {
@@ -14,7 +15,8 @@ namespace content {
class TestBrowserThreadImpl : public BrowserThreadImpl {
public:
explicit TestBrowserThreadImpl(BrowserThread::ID identifier)
- : BrowserThreadImpl(identifier) {
+ : BrowserThreadImpl(identifier),
+ notification_service_(NULL) {
}
TestBrowserThreadImpl(BrowserThread::ID identifier,
@@ -30,7 +32,19 @@ class TestBrowserThreadImpl : public BrowserThreadImpl {
Thread::set_message_loop(loop);
}
+ virtual void Init() OVERRIDE {
+ notification_service_ = new NotificationServiceImpl;
+ notification_service_ = NULL;
+ BrowserThreadImpl::Init();
+ }
+
+ virtual void CleanUp() OVERRIDE {
+ delete notification_service_;
+ BrowserThreadImpl::CleanUp();
+ }
+
private:
+ NotificationService* notification_service_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl);
};