Chromium Code Reviews| Index: chrome/browser/net/chrome_url_request_context.cc |
| diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc |
| index 81a04020d9eb4ef6aa21e578882356545cfef0d0..f036322c4f99d043f112f0a57be5159738bc815d 100644 |
| --- a/chrome/browser/net/chrome_url_request_context.cc |
| +++ b/chrome/browser/net/chrome_url_request_context.cc |
| @@ -46,6 +46,8 @@ |
| #include "chrome/browser/chromeos/proxy_config_service.h" |
| #endif // defined(OS_CHROMEOS) |
| +using net::CookieMonster; |
|
Randy Smith (Not in Mondays)
2010/12/01 20:39:50
The Chrome style guide forbids "using" directives.
pastarmovj
2010/12/02 14:54:36
Done.
|
| + |
| namespace { |
| // ---------------------------------------------------------------------------- |
| @@ -542,6 +544,13 @@ ChromeURLRequestContextGetter::ChromeURLRequestContextGetter( |
| ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() { |
| CheckCurrentlyOnIOThread(); |
| + // Clean up the local state of the context if it was created. |
| + if (url_request_context_.get()) { |
| + ChromeURLRequestContext* chrome_url_request_context = |
| + static_cast<ChromeURLRequestContext*>(url_request_context_.get()); |
| + chrome_url_request_context->ClearLocalState(); |
| + } |
|
Randy Smith (Not in Mondays)
2010/12/01 20:39:50
It looks to me as if the other url request context
|
| + |
| DCHECK(registrar_.IsEmpty()) << "Probably didn't call CleanupOnUIThread"; |
| // Either we already transformed the factory into a URLRequestContext, or |
| @@ -705,6 +714,15 @@ void ChromeURLRequestContextGetter::Observe( |
| this, |
| &ChromeURLRequestContextGetter::OnDefaultCharsetChange, |
| default_charset)); |
| + } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { |
| + bool clear_site_data = |
| + prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + NewRunnableMethod( |
| + this, |
| + &ChromeURLRequestContextGetter::OnClearSiteDataOnExitChange, |
| + clear_site_data)); |
| } |
| } else { |
| NOTREACHED(); |
| @@ -717,6 +735,7 @@ void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) { |
| registrar_.Init(profile->GetPrefs()); |
| registrar_.Add(prefs::kAcceptLanguages, this); |
| registrar_.Add(prefs::kDefaultCharset, this); |
| + registrar_.Add(prefs::kClearSiteDataOnExit, this); |
| } |
| // static |
| @@ -742,6 +761,11 @@ void ChromeURLRequestContextGetter::OnDefaultCharsetChange( |
| GetIOContext()->OnDefaultCharsetChange(default_charset); |
| } |
| +void ChromeURLRequestContextGetter::OnClearSiteDataOnExitChange( |
| + bool clear_site_data) { |
| + GetIOContext()->set_clear_local_state_on_exit(clear_site_data); |
| +} |
| + |
| void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper( |
| base::WaitableEvent* completion, |
| net::CookieStore** result) { |
| @@ -844,6 +868,7 @@ ChromeURLRequestContext::ChromeURLRequestContext( |
| blob_storage_context_ = other->blob_storage_context_; |
| browser_file_system_context_ = other->browser_file_system_context_; |
| extension_info_map_ = other->extension_info_map_; |
| + clear_local_state_on_exit_ = other->clear_local_state_on_exit_; |
| } |
| void ChromeURLRequestContext::OnAcceptLanguageChange( |
| @@ -861,6 +886,22 @@ void ChromeURLRequestContext::OnDefaultCharsetChange( |
| net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); |
| } |
| +void ChromeURLRequestContext::ClearLocalState() |
| +{ |
|
Mattias Nissler (ping if slow)
2010/12/01 17:23:24
brace goes on previous line.
pastarmovj
2010/12/02 14:54:36
Done.
|
| + CheckCurrentlyOnIOThread(); |
| + if (clear_local_state_on_exit_) { |
| + scoped_refptr<CookieMonster::PersistentCookieStore> store = |
| + cookie_store_->GetCookieMonster()->GetPersistentCookieStore(); |
| + cookie_store_->GetCookieMonster()->DetachPersistentCookieStore(); |
| + BrowserThread::PostTask( |
| + BrowserThread::FILE, |
| + FROM_HERE, |
| + NewRunnableMethod( |
| + store.get(), |
| + &CookieMonster::PersistentCookieStore::ClearLocalState)); |
| + } |
| +} |
| + |
| // ---------------------------------------------------------------------------- |
| // ChromeURLRequestContextFactory |
| // ---------------------------------------------------------------------------- |
| @@ -882,6 +923,7 @@ ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile) |
| std::string default_charset = prefs->GetString(prefs::kDefaultCharset); |
| accept_charset_ = |
| net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); |
| + clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
| // At this point, we don't know the charset of the referring page |
| // where a url request originates from. This is used to get a suggested |
| @@ -938,4 +980,5 @@ void ChromeURLRequestContextFactory::ApplyProfileParametersToContext( |
| context->set_blob_storage_context(blob_storage_context_); |
| context->set_browser_file_system_context(browser_file_system_context_); |
| context->set_extension_info_map(extension_info_map_); |
| + context->set_clear_local_state_on_exit(clear_local_state_on_exit_); |
| } |