summaryrefslogtreecommitdiffstats
path: root/content/browser
diff options
context:
space:
mode:
Diffstat (limited to 'content/browser')
-rw-r--r--content/browser/browser_context.cc90
-rw-r--r--content/browser/in_process_webkit/dom_storage_browsertest.cc2
-rw-r--r--content/browser/in_process_webkit/dom_storage_context_impl.h12
-rw-r--r--content/browser/in_process_webkit/dom_storage_unittest.cc2
-rw-r--r--content/browser/in_process_webkit/indexed_db_browsertest.cc2
-rw-r--r--content/browser/in_process_webkit/webkit_context.cc45
-rw-r--r--content/browser/in_process_webkit/webkit_context.h24
-rw-r--r--content/browser/in_process_webkit/webkit_context_unittest.cc77
8 files changed, 95 insertions, 159 deletions
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index cabf7a2..4bfc9e7 100644
--- a/content/browser/browser_context.cc
+++ b/content/browser/browser_context.cc
@@ -6,10 +6,15 @@
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/file_system/browser_file_system_helper.h"
+#include "content/browser/in_process_webkit/dom_storage_context_impl.h"
+#include "content/browser/in_process_webkit/indexed_db_context_impl.h"
#include "content/browser/in_process_webkit/webkit_context.h"
#include "content/browser/resource_context_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_constants.h"
+#include "net/base/cookie_monster.h"
+#include "net/base/cookie_store.h"
+#include "net/url_request/url_request_context.h"
#include "webkit/database/database_tracker.h"
#include "webkit/quota/quota_manager.h"
@@ -67,7 +72,7 @@ void CreateQuotaManagerAndClients(BrowserContext* context) {
scoped_refptr<WebKitContext> webkit_context = new WebKitContext(
context->IsOffTheRecord(), context->GetPath(),
- context->GetSpecialStoragePolicy(), false, quota_manager->proxy(),
+ context->GetSpecialStoragePolicy(), quota_manager->proxy(),
BrowserThread::GetMessageLoopProxyForThread(
BrowserThread::WEBKIT_DEPRECATED));
context->SetUserData(kWebKitContextKeyName,
@@ -94,6 +99,29 @@ void CreateQuotaManagerAndClients(BrowserContext* context) {
}
}
+void SaveSessionStateOnIOThread(ResourceContext* resource_context) {
+ resource_context->GetRequestContext()->cookie_store()->GetCookieMonster()->
+ SaveSessionCookies();
+ ResourceContext::GetAppCacheService(resource_context)->set_save_session_state(
+ true);
+}
+
+void SaveSessionStateOnWebkitThread(
+ scoped_refptr<DOMStorageContextImpl> dom_storage_context,
+ scoped_refptr<IndexedDBContextImpl> indexed_db_context) {
+ dom_storage_context->SaveSessionState();
+ indexed_db_context->SaveSessionState();
+}
+
+void PurgeMemoryOnIOThread(ResourceContext* resource_context) {
+ ResourceContext::GetAppCacheService(resource_context)->PurgeMemory();
+}
+
+void PurgeMemoryOnWebkitThread(
+ scoped_refptr<DOMStorageContextImpl> dom_storage_context) {
+ dom_storage_context->PurgeMemory();
+}
+
QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) {
CreateQuotaManagerAndClients(context);
return UserDataAdapter<QuotaManager>::Get(context, kQuotaManagerKeyName);
@@ -128,6 +156,66 @@ void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) {
content::EnsureResourceContextInitialized(context);
}
+void BrowserContext::SaveSessionState(BrowserContext* browser_context) {
+ GetDatabaseTracker(browser_context)->SaveSessionState();
+
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&SaveSessionStateOnIOThread,
+ browser_context->GetResourceContext()));
+ }
+
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) {
+ DOMStorageContextImpl* dom_context = static_cast<DOMStorageContextImpl*>(
+ DOMStorageContextImpl::GetForBrowserContext(browser_context));
+ IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>(
+ IndexedDBContext::GetForBrowserContext(browser_context));
+ BrowserThread::PostTask(
+ BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
+ base::Bind(&SaveSessionStateOnWebkitThread,
+ make_scoped_refptr(dom_context),
+ make_scoped_refptr(indexed_db)));
+ }
+}
+
+void BrowserContext::ClearLocalOnDestruction(BrowserContext* browser_context) {
+ DOMStorageContextImpl* dom_context = static_cast<DOMStorageContextImpl*>(
+ DOMStorageContextImpl::GetForBrowserContext(browser_context));
+ dom_context->set_clear_local_state_on_exit(true);
+
+ IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>(
+ IndexedDBContext::GetForBrowserContext(browser_context));
+ indexed_db->set_clear_local_state_on_exit(true);
+
+ GetDatabaseTracker(browser_context)->SetClearLocalStateOnExit(true);
+
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&appcache::AppCacheService::set_clear_local_state_on_exit,
+ base::Unretained(GetAppCacheService(browser_context)), true));
+ }
+}
+
+void BrowserContext::PurgeMemory(BrowserContext* browser_context) {
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&PurgeMemoryOnIOThread,
+ browser_context->GetResourceContext()));
+ }
+
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) {
+ DOMStorageContextImpl* dom_context = static_cast<DOMStorageContextImpl*>(
+ DOMStorageContextImpl::GetForBrowserContext(browser_context));
+ BrowserThread::PostTask(
+ BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
+ base::Bind(&PurgeMemoryOnWebkitThread,
+ make_scoped_refptr(dom_context)));
+ }
+}
+
BrowserContext::~BrowserContext() {
if (GetUserData(kDatabaseTrackerKeyName) &&
BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
diff --git a/content/browser/in_process_webkit/dom_storage_browsertest.cc b/content/browser/in_process_webkit/dom_storage_browsertest.cc
index 61d533b..922e96f 100644
--- a/content/browser/in_process_webkit/dom_storage_browsertest.cc
+++ b/content/browser/in_process_webkit/dom_storage_browsertest.cc
@@ -86,7 +86,7 @@ IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, MAYBE_ClearLocalState) {
&browser_context);
webkit_context->dom_storage_context()->
set_data_path_for_testing(temp_dir.path());
- webkit_context->set_clear_local_state_on_exit(true);
+ webkit_context->dom_storage_context()->set_clear_local_state_on_exit(true);
}
// Make sure we wait until the destructor has run.
scoped_refptr<base::ThreadTestHelper> helper(
diff --git a/content/browser/in_process_webkit/dom_storage_context_impl.h b/content/browser/in_process_webkit/dom_storage_context_impl.h
index 84cd29c..2b1a6ba 100644
--- a/content/browser/in_process_webkit/dom_storage_context_impl.h
+++ b/content/browser/in_process_webkit/dom_storage_context_impl.h
@@ -29,8 +29,6 @@ class SpecialStoragePolicy;
// context. The specifics of responsibilities are fairly well documented here
// and in StorageNamespace and StorageArea. Everything is only to be accessed
// on the WebKit thread unless noted otherwise.
-//
-// NOTE: Virtual methods facilitate mocking functions for testing.
class CONTENT_EXPORT DOMStorageContextImpl :
NON_EXPORTED_BASE(public content::DOMStorageContext) {
public:
@@ -43,6 +41,7 @@ class CONTENT_EXPORT DOMStorageContextImpl :
virtual FilePath GetFilePath(const string16& origin_id) const OVERRIDE;
virtual void DeleteForOrigin(const string16& origin_id) OVERRIDE;
virtual void DeleteLocalStorageFile(const FilePath& file_path) OVERRIDE;
+ virtual void DeleteDataModifiedSince(const base::Time& cutoff) OVERRIDE;
// Invalid storage id. No storage session will ever report this value.
// Used in DOMStorageMessageFilter::OnStorageAreaId when coping with
@@ -81,12 +80,7 @@ class CONTENT_EXPORT DOMStorageContextImpl :
const MessageFilterSet* GetMessageFilterSet() const;
// Tells storage namespaces to purge any memory they do not need.
- virtual void PurgeMemory();
-
- // Delete any local storage files that have been touched since the cutoff
- // date that's supplied. Protected origins, per the SpecialStoragePolicy,
- // are not deleted by this method.
- void DeleteDataModifiedSince(const base::Time& cutoff);
+ void PurgeMemory();
// Deletes all local storage files.
void DeleteAllLocalStorageFiles();
@@ -97,7 +91,7 @@ class CONTENT_EXPORT DOMStorageContextImpl :
// The local storage file extension.
static const FilePath::CharType kLocalStorageExtension[];
- void set_clear_local_state_on_exit_(bool clear_local_state) {
+ void set_clear_local_state_on_exit(bool clear_local_state) {
clear_local_state_on_exit_ = clear_local_state;
}
diff --git a/content/browser/in_process_webkit/dom_storage_unittest.cc b/content/browser/in_process_webkit/dom_storage_unittest.cc
index 8e5d365..b8e26d9 100644
--- a/content/browser/in_process_webkit/dom_storage_unittest.cc
+++ b/content/browser/in_process_webkit/dom_storage_unittest.cc
@@ -107,7 +107,7 @@ TEST_F(DOMStorageTest, SaveSessionState) {
dom_storage_context();
dom_storage_context->special_storage_policy_ = special_storage_policy;
- dom_storage_context->set_clear_local_state_on_exit_(true);
+ dom_storage_context->set_clear_local_state_on_exit(true);
// Save session state. This should bypass the destruction-time deletion.
dom_storage_context->SaveSessionState();
diff --git a/content/browser/in_process_webkit/indexed_db_browsertest.cc b/content/browser/in_process_webkit/indexed_db_browsertest.cc
index a5f70b5..0e134f6 100644
--- a/content/browser/in_process_webkit/indexed_db_browsertest.cc
+++ b/content/browser/in_process_webkit/indexed_db_browsertest.cc
@@ -172,7 +172,7 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, MAYBE_ClearLocalState) {
ASSERT_TRUE(file_util::CreateDirectory(unprotected_path));
// Setup to clear all unprotected origins on exit.
- webkit_context->set_clear_local_state_on_exit(true);
+ idb_context->set_clear_local_state_on_exit(true);
}
// Make sure we wait until the destructor has run.
diff --git a/content/browser/in_process_webkit/webkit_context.cc b/content/browser/in_process_webkit/webkit_context.cc
index c4df675..678f903 100644
--- a/content/browser/in_process_webkit/webkit_context.cc
+++ b/content/browser/in_process_webkit/webkit_context.cc
@@ -15,12 +15,10 @@ using content::BrowserThread;
WebKitContext::WebKitContext(
bool is_incognito, const FilePath& data_path,
quota::SpecialStoragePolicy* special_storage_policy,
- bool clear_local_state_on_exit,
quota::QuotaManagerProxy* quota_manager_proxy,
base::MessageLoopProxy* webkit_thread_loop)
: data_path_(is_incognito ? FilePath() : data_path),
is_incognito_(is_incognito),
- clear_local_state_on_exit_(clear_local_state_on_exit),
ALLOW_THIS_IN_INITIALIZER_LIST(
dom_storage_context_(new DOMStorageContextImpl(
this, special_storage_policy))),
@@ -34,8 +32,6 @@ WebKitContext::~WebKitContext() {
// If the WebKit thread was ever spun up, delete the object there. The task
// will just get deleted if the WebKit thread isn't created (which only
// happens during testing).
- dom_storage_context_->set_clear_local_state_on_exit_(
- clear_local_state_on_exit_);
DOMStorageContextImpl* dom_storage_context = dom_storage_context_.release();
if (!BrowserThread::ReleaseSoon(
BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, dom_storage_context)) {
@@ -43,45 +39,4 @@ WebKitContext::~WebKitContext() {
// freeing the DOMStorageContext, so delete it manually.
dom_storage_context->Release();
}
-
- indexed_db_context_->set_clear_local_state_on_exit(
- clear_local_state_on_exit_);
-}
-
-void WebKitContext::PurgeMemory() {
- if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)) {
- BrowserThread::PostTask(
- BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
- base::Bind(&WebKitContext::PurgeMemory, this));
- return;
- }
-
- dom_storage_context_->PurgeMemory();
-}
-
-void WebKitContext::SetDOMStorageContextForTesting(
- DOMStorageContextImpl* dom_storage_context) {
- dom_storage_context_ = dom_storage_context;
-}
-
-void WebKitContext::DeleteDataModifiedSince(const base::Time& cutoff) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)) {
- BrowserThread::PostTask(
- BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
- base::Bind(&WebKitContext::DeleteDataModifiedSince, this, cutoff));
- return;
- }
-
- dom_storage_context_->DeleteDataModifiedSince(cutoff);
-}
-
-void WebKitContext::SaveSessionState() {
- if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)) {
- BrowserThread::PostTask(
- BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
- base::Bind(&WebKitContext::SaveSessionState, this));
- return;
- }
- dom_storage_context_->SaveSessionState();
- indexed_db_context_->SaveSessionState();
}
diff --git a/content/browser/in_process_webkit/webkit_context.h b/content/browser/in_process_webkit/webkit_context.h
index 747a6da..286235e 100644
--- a/content/browser/in_process_webkit/webkit_context.h
+++ b/content/browser/in_process_webkit/webkit_context.h
@@ -11,7 +11,6 @@
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/time.h"
#include "content/common/content_export.h"
class DOMStorageContextImpl;
@@ -38,7 +37,6 @@ class CONTENT_EXPORT WebKitContext
public:
WebKitContext(bool is_incognito, const FilePath& data_path,
quota::SpecialStoragePolicy* special_storage_policy,
- bool clear_local_state_on_exit,
quota::QuotaManagerProxy* quota_manager_proxy,
base::MessageLoopProxy* webkit_thread_loop);
@@ -48,25 +46,6 @@ class CONTENT_EXPORT WebKitContext
DOMStorageContextImpl* dom_storage_context() { return dom_storage_context_; }
IndexedDBContextImpl* indexed_db_context() { return indexed_db_context_; }
- void set_clear_local_state_on_exit(bool clear_local_state) {
- clear_local_state_on_exit_ = clear_local_state;
- }
-
- // For unit tests, allow specifying a DOMStorageContext directly so it can be
- // mocked.
- void SetDOMStorageContextForTesting(
- DOMStorageContextImpl* dom_storage_context);
-
- // Tells the DOMStorageContext to purge any memory it does not need.
- void PurgeMemory();
-
- // Tell all children (where applicable) to delete any objects that were
- // last modified on or after the following time.
- void DeleteDataModifiedSince(const base::Time& cutoff);
-
- // Tells all children to not do delete data when destructed.
- void SaveSessionState();
-
private:
friend class base::RefCountedThreadSafe<WebKitContext>;
virtual ~WebKitContext();
@@ -75,9 +54,6 @@ class CONTENT_EXPORT WebKitContext
const FilePath data_path_;
const bool is_incognito_;
- // True if the destructors of context objects should delete their files.
- bool clear_local_state_on_exit_;
-
scoped_refptr<DOMStorageContextImpl> dom_storage_context_;
scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
diff --git a/content/browser/in_process_webkit/webkit_context_unittest.cc b/content/browser/in_process_webkit/webkit_context_unittest.cc
deleted file mode 100644
index dc35354..0000000
--- a/content/browser/in_process_webkit/webkit_context_unittest.cc
+++ /dev/null
@@ -1,77 +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.
-
-#include "content/browser/browser_thread_impl.h"
-#include "content/browser/in_process_webkit/dom_storage_context_impl.h"
-#include "content/browser/in_process_webkit/webkit_context.h"
-#include "content/test/test_browser_context.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using content::BrowserThread;
-using content::BrowserThreadImpl;
-
-class MockDOMStorageContext : public DOMStorageContextImpl {
- public:
- MockDOMStorageContext(WebKitContext* webkit_context,
- quota::SpecialStoragePolicy* special_storage_policy)
- : DOMStorageContextImpl(webkit_context, special_storage_policy),
- purge_count_(0) {
- }
-
- virtual void PurgeMemory() {
- EXPECT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::UI));
- EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- ++purge_count_;
- }
-
- int purge_count() const { return purge_count_; }
-
- private:
- int purge_count_;
-};
-
-TEST(WebKitContextTest, Basic) {
- TestBrowserContext browser_context;
- scoped_refptr<WebKitContext> context1(new WebKitContext(
- browser_context.IsOffTheRecord(), browser_context.GetPath(),
- NULL, false, NULL, NULL));
- EXPECT_TRUE(browser_context.GetPath() == context1->data_path());
- EXPECT_TRUE(browser_context.IsOffTheRecord() == context1->is_incognito());
-
- scoped_refptr<WebKitContext> context2(new WebKitContext(
- browser_context.IsOffTheRecord(), browser_context.GetPath(),
- NULL, false, NULL, NULL));
- EXPECT_TRUE(context1->data_path() == context2->data_path());
- EXPECT_TRUE(context1->is_incognito() == context2->is_incognito());
-}
-
-TEST(WebKitContextTest, PurgeMemory) {
- // Start up a WebKit thread for the WebKitContext to call the
- // DOMStorageContext on.
- MessageLoop message_loop(MessageLoop::TYPE_DEFAULT);
- BrowserThreadImpl webkit_thread(BrowserThread::WEBKIT_DEPRECATED,
- &message_loop);
-
- {
- // Create the contexts.
- TestBrowserContext browser_context;
- scoped_refptr<WebKitContext> context(new WebKitContext(
- browser_context.IsOffTheRecord(), browser_context.GetPath(),
- NULL, false, NULL, NULL));
- MockDOMStorageContext* mock_context = new MockDOMStorageContext(
- context.get(), NULL);
- // Takes ownership.
- context->SetDOMStorageContextForTesting(mock_context);
-
- // Ensure PurgeMemory() calls our mock object on the right thread.
- EXPECT_EQ(0, mock_context->purge_count());
- context->PurgeMemory();
- MessageLoop::current()->RunAllPending();
- EXPECT_EQ(1, mock_context->purge_count());
- }
- // WebKitContext's destructor posts stuff to the webkit thread. Let
- // WebKitContext go out of scope here before processing WebKitContext's
- // clean-up tasks.
- MessageLoop::current()->RunAllPending();
-}