diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-24 18:10:36 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-24 18:10:36 +0000 |
commit | 6e2d3d229024a3a0038c8a5c169bfd948a5c4939 (patch) | |
tree | b9f37d0c4fc5758e2c0d4b4c407c3059ca59dd68 | |
parent | aee7b0822009cda31b7aea2922263a0b5adc6c9a (diff) | |
download | chromium_src-6e2d3d229024a3a0038c8a5c169bfd948a5c4939.zip chromium_src-6e2d3d229024a3a0038c8a5c169bfd948a5c4939.tar.gz chromium_src-6e2d3d229024a3a0038c8a5c169bfd948a5c4939.tar.bz2 |
Remove usage of WebKitContext from chrome. This also cleans up the chrome code so that it only calls profile-wide operations (i.e. saving session/purging memory/clearing local state on exit) on the BrowserContext. The content layer takes care of calling the necessary objects on the right thread.
WebKitContext now does almost nothing and I'll remove it completely in the next change.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9462007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123509 0039d316-1c4b-4281-b951-d872f2087c98
19 files changed, 140 insertions, 224 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 838fe4c..5882a06 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -50,7 +50,6 @@ include_rules = [ "+content/browser/find_pasteboard.h", "+content/browser/font_list_async.h", "+content/browser/geolocation/wifi_data_provider_common.h", - "+content/browser/in_process_webkit/webkit_context.h", "+content/browser/intents/intent_injector.h", "+content/browser/load_notification_details.h", "+content/browser/mac/closure_blocks_leopard_compat.h", diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc index caf4c8c..8653ef0 100644 --- a/chrome/browser/browsing_data_remover.cc +++ b/chrome/browser/browsing_data_remover.cc @@ -41,8 +41,8 @@ #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" -#include "content/browser/in_process_webkit/webkit_context.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/dom_storage_context.h" #include "content/public/browser/download_manager.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/plugin_data_remover.h" @@ -61,6 +61,7 @@ using content::BrowserContext; using content::BrowserThread; +using content::DOMStorageContext; using content::DownloadManager; using content::UserMetricsAction; @@ -300,14 +301,14 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask, } } - if (remove_mask & REMOVE_LOCAL_STORAGE) { - // Remove data such as local databases, STS state, etc. These only can - // be removed if a WEBKIT thread exists, so check that first: - if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { - // We assume the end time is now. - BrowserContext::GetWebKitContext(profile_)-> - DeleteDataModifiedSince(delete_begin_); - } + if (remove_mask & REMOVE_LOCAL_STORAGE && + BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { + DOMStorageContext* context = + DOMStorageContext::GetForBrowserContext(profile_); + BrowserThread::PostTask( + BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, + base::Bind(&BrowsingDataRemover::ClearDOMStorageOnWebKitThread, + base::Unretained(this), make_scoped_refptr(context))); } if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL || @@ -436,6 +437,12 @@ base::Time BrowsingDataRemover::CalculateBeginDeleteTime( return delete_begin_time - diff; } +void BrowsingDataRemover::ClearDOMStorageOnWebKitThread( + scoped_refptr<DOMStorageContext> dom_storage_context) { + // We assume the end time is now. + dom_storage_context->DeleteDataModifiedSince(delete_begin_); +} + void BrowsingDataRemover::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { diff --git a/chrome/browser/browsing_data_remover.h b/chrome/browser/browsing_data_remover.h index d156716..f07fbf2 100644 --- a/chrome/browser/browsing_data_remover.h +++ b/chrome/browser/browsing_data_remover.h @@ -25,6 +25,7 @@ class IOThread; class Profile; namespace content { +class DOMStorageContext; class PluginDataRemover; } @@ -244,6 +245,10 @@ class BrowsingDataRemover : public content::NotificationObserver, // Calculate the begin time for the deletion range specified by |time_period|. base::Time CalculateBeginDeleteTime(TimePeriod time_period); + // Invoked on the WEBKIT thread to clear local storage. + void ClearDOMStorageOnWebKitThread( + scoped_refptr<content::DOMStorageContext> dom_storage_context); + // Returns true if we're all done. bool all_done() { return registrar_.IsEmpty() && !waiting_for_clear_cache_ && diff --git a/chrome/browser/memory_purger.cc b/chrome/browser/memory_purger.cc index 1401651..2222d81 100644 --- a/chrome/browser/memory_purger.cc +++ b/chrome/browser/memory_purger.cc @@ -15,7 +15,6 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/common/render_messages.h" -#include "content/browser/in_process_webkit/webkit_context.h" #include "content/browser/renderer_host/backing_store_manager.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/resource_context.h" @@ -24,7 +23,6 @@ #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" -#include "webkit/appcache/appcache_service.h" using content::BrowserContext; using content::BrowserThread; @@ -45,15 +43,12 @@ class PurgeMemoryIOHelper void AddRequestContextGetter( scoped_refptr<net::URLRequestContextGetter> request_context_getter); - void AddResourceContext(content::ResourceContext* resource_context); - void PurgeMemoryOnIOThread(); private: typedef scoped_refptr<net::URLRequestContextGetter> RequestContextGetter; std::vector<RequestContextGetter> request_context_getters_; - std::vector<content::ResourceContext*> resource_contexts_; scoped_refptr<SafeBrowsingService> safe_browsing_service_; DISALLOW_COPY_AND_ASSIGN(PurgeMemoryIOHelper); @@ -64,11 +59,6 @@ void PurgeMemoryIOHelper::AddRequestContextGetter( request_context_getters_.push_back(request_context_getter); } -void PurgeMemoryIOHelper::AddResourceContext( - content::ResourceContext* resource_context) { - resource_contexts_.push_back(resource_context); -} - void PurgeMemoryIOHelper::PurgeMemoryOnIOThread() { // Ask ProxyServices to purge any memory they can (generally garbage in the // wrapped ProxyResolver's JS engine). @@ -77,9 +67,6 @@ void PurgeMemoryIOHelper::PurgeMemoryOnIOThread() { PurgeMemory(); } - for (size_t i = 0; i < resource_contexts_.size(); ++i) - ResourceContext::GetAppCacheService(resource_contexts_[i])->PurgeMemory(); - safe_browsing_service_->PurgeMemory(); } @@ -108,8 +95,6 @@ void MemoryPurger::PurgeBrowser() { for (size_t i = 0; i < profiles.size(); ++i) { purge_memory_io_helper->AddRequestContextGetter( make_scoped_refptr(profiles[i]->GetRequestContext())); - purge_memory_io_helper->AddResourceContext( - profiles[i]->GetResourceContext()); // NOTE: Some objects below may be duplicates across profiles. We could // conceivably put all these in sets and then iterate over the sets. @@ -128,10 +113,7 @@ void MemoryPurger::PurgeBrowser() { if (web_data_service) web_data_service->UnloadDatabase(); - // Ask all WebKitContexts to purge memory (freeing memory used to cache - // the LocalStorage sqlite DB). WebKitContext creation is basically free so - // we don't bother with a "...WithoutCreating()" function. - BrowserContext::GetWebKitContext(profiles[i])->PurgeMemory(); + BrowserContext::PurgeMemory(profiles[i]); } BrowserThread::PostTask( diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 3f6f5f4..e1e55c1 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -452,9 +452,6 @@ class Profile : public content::BrowserContext { // Returns the home page for this profile. virtual GURL GetHomePage() = 0; - // Makes the session state, e.g., cookies, persistent across the next restart. - virtual void SaveSessionState() {} - std::string GetDebugName(); // Returns whether it is a guest session. diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index cfd981a..7b1c953 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -91,7 +91,6 @@ #include "chrome/common/json_pref_store.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" -#include "content/browser/in_process_webkit/webkit_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/host_zoom_map.h" #include "content/public/browser/notification_service.h" @@ -171,15 +170,6 @@ FilePath GetMediaCachePath(const FilePath& base) { return base.Append(chrome::kMediaCacheDirname); } -void SaveSessionStateOnIOThread( - net::URLRequestContextGetter* url_request_context_getter, - appcache::AppCacheService* appcache_service) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - url_request_context_getter->GetURLRequestContext()->cookie_store()-> - GetCookieMonster()->SaveSessionCookies(); - appcache_service->set_save_session_state(true); -} - } // namespace // static @@ -570,14 +560,10 @@ ProfileImpl::~ProfileImpl() { // next startup. SessionStartupPref pref = SessionStartupPref::GetStartupPref(this); if (pref.type == SessionStartupPref::LAST) { - SaveSessionState(); + if (session_restore_enabled_) + BrowserContext::SaveSessionState(this); } else if (clear_local_state_on_exit_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&appcache::AppCacheService::set_clear_local_state_on_exit, - base::Unretained(BrowserContext::GetAppCacheService(this)), true)); - BrowserContext::GetWebKitContext(this)->set_clear_local_state_on_exit(true); - BrowserContext::GetDatabaseTracker(this)->SetClearLocalStateOnExit(true); + BrowserContext::ClearLocalOnDestruction(this); } StopCreateSessionServiceTimer(); @@ -1433,19 +1419,6 @@ GURL ProfileImpl::GetHomePage() { return home_page; } -void ProfileImpl::SaveSessionState() { - if (!session_restore_enabled_) - return; - BrowserContext::GetWebKitContext(this)->SaveSessionState(); - BrowserContext::GetDatabaseTracker(this)->SaveSessionState(); - - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&SaveSessionStateOnIOThread, - make_scoped_refptr(GetRequestContext()), - BrowserContext::GetAppCacheService(this))); -} - void ProfileImpl::UpdateProfileUserNameCache() { ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index e7fa462..1e63fc6 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -123,7 +123,6 @@ class ProfileImpl : public Profile, virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE; virtual void ClearNetworkingHistorySince(base::Time time) OVERRIDE; virtual GURL GetHomePage() OVERRIDE; - virtual void SaveSessionState() OVERRIDE; #if defined(OS_CHROMEOS) virtual void ChangeAppLocale(const std::string& locale, diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc index 2ebcc00..7bb5736 100644 --- a/chrome/browser/ui/browser_list.cc +++ b/chrome/browser/ui/browser_list.cc @@ -522,7 +522,7 @@ void BrowserList::AttemptRestart() { switches::kEnableRestoreSessionState)) { BrowserVector::const_iterator it; for (it = begin(); it != end(); ++it) - (*it)->profile()->SaveSessionState(); + content::BrowserContext::SaveSessionState((*it)->profile()); } PrefService* pref_service = g_browser_process->local_state(); 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(); -} diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 7064833..fa10f86 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -221,7 +221,6 @@ 'browser/host_zoom_map_impl_unittest.cc', 'browser/in_process_webkit/dom_storage_unittest.cc', 'browser/in_process_webkit/indexed_db_quota_client_unittest.cc', - 'browser/in_process_webkit/webkit_context_unittest.cc', 'browser/in_process_webkit/webkit_thread_unittest.cc', 'browser/mac/closure_blocks_leopard_compat_unittest.cc', 'browser/mach_broker_mac_unittest.cc', diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h index badf64c..5a93af0 100644 --- a/content/public/browser/browser_context.h +++ b/content/public/browser/browser_context.h @@ -62,6 +62,16 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { // that the ResourceContext is ready. static void EnsureResourceContextInitialized(BrowserContext* browser_context); + // Tells the HTML5 objects on this context to persist their session state + // across the next restart. + static void SaveSessionState(BrowserContext* browser_context); + + // Tells the HTML5 objects on this context to clear their data on destruction. + static void ClearLocalOnDestruction(BrowserContext* browser_context); + + // Tells the HTML5 objects on this context to purge any uneeded memory. + static void PurgeMemory(BrowserContext* browser_context); + virtual ~BrowserContext(); // Returns the path of the directory where this context's data is stored. diff --git a/content/public/browser/dom_storage_context.h b/content/public/browser/dom_storage_context.h index 74cb516..d94aa21 100644 --- a/content/public/browser/dom_storage_context.h +++ b/content/public/browser/dom_storage_context.h @@ -14,6 +14,10 @@ class FilePath; +namespace base { +class Time; +} + namespace content { class BrowserContext; @@ -38,6 +42,11 @@ class DOMStorageContext : public base::RefCountedThreadSafe<DOMStorageContext> { // Deletes a single local storage file. virtual void DeleteLocalStorageFile(const FilePath& file_path) = 0; + + // 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. + virtual void DeleteDataModifiedSince(const base::Time& cutoff) = 0; }; } // namespace content |