| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/browser/browser_context.h" | 5 #include "content/public/browser/browser_context.h" |
| 6 | 6 |
| 7 #include "content/browser/appcache/chrome_appcache_service.h" | 7 #include "content/browser/appcache/chrome_appcache_service.h" |
| 8 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 8 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 9 #include "content/browser/fileapi/browser_file_system_helper.h" | 9 #include "content/browser/fileapi/browser_file_system_helper.h" |
| 10 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" | 10 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" |
| 11 #include "content/browser/resource_context_impl.h" | 11 #include "content/browser/resource_context_impl.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/common/content_constants.h" | 13 #include "content/public/common/content_constants.h" |
| 14 #include "net/base/server_bound_cert_service.h" |
| 15 #include "net/base/server_bound_cert_store.h" |
| 14 #include "net/cookies/cookie_monster.h" | 16 #include "net/cookies/cookie_monster.h" |
| 15 #include "net/cookies/cookie_store.h" | 17 #include "net/cookies/cookie_store.h" |
| 16 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
| 17 #include "webkit/database/database_tracker.h" | 19 #include "webkit/database/database_tracker.h" |
| 18 #include "webkit/quota/quota_manager.h" | 20 #include "webkit/quota/quota_manager.h" |
| 19 | 21 |
| 20 using appcache::AppCacheService; | 22 using appcache::AppCacheService; |
| 21 using base::UserDataAdapter; | 23 using base::UserDataAdapter; |
| 22 using content::BrowserThread; | 24 using content::BrowserThread; |
| 23 using fileapi::FileSystemContext; | 25 using fileapi::FileSystemContext; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 appcache_service, | 106 appcache_service, |
| 105 context->IsOffTheRecord() ? FilePath() : | 107 context->IsOffTheRecord() ? FilePath() : |
| 106 context->GetPath().Append(content::kAppCacheDirname), | 108 context->GetPath().Append(content::kAppCacheDirname), |
| 107 context->GetResourceContext(), | 109 context->GetResourceContext(), |
| 108 make_scoped_refptr(context->GetSpecialStoragePolicy()))); | 110 make_scoped_refptr(context->GetSpecialStoragePolicy()))); |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 | 113 |
| 112 void SaveSessionStateOnIOThread(ResourceContext* resource_context) { | 114 void SaveSessionStateOnIOThread(ResourceContext* resource_context) { |
| 113 resource_context->GetRequestContext()->cookie_store()->GetCookieMonster()-> | 115 resource_context->GetRequestContext()->cookie_store()->GetCookieMonster()-> |
| 114 SaveSessionCookies(); | 116 SetForceKeepSessionState(); |
| 115 ResourceContext::GetAppCacheService(resource_context)->set_save_session_state( | 117 resource_context->GetRequestContext()->server_bound_cert_service()-> |
| 116 true); | 118 GetCertStore()->SetForceKeepSessionState(); |
| 119 ResourceContext::GetAppCacheService(resource_context)-> |
| 120 set_force_keep_session_state(); |
| 117 } | 121 } |
| 118 | 122 |
| 119 void SaveSessionStateOnWebkitThread( | 123 void SaveSessionStateOnWebkitThread( |
| 120 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { | 124 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { |
| 121 indexed_db_context->SaveSessionState(); | 125 indexed_db_context->SetForceKeepSessionState(); |
| 122 } | 126 } |
| 123 | 127 |
| 124 void PurgeMemoryOnIOThread(ResourceContext* resource_context) { | 128 void PurgeMemoryOnIOThread(ResourceContext* resource_context) { |
| 125 ResourceContext::GetAppCacheService(resource_context)->PurgeMemory(); | 129 ResourceContext::GetAppCacheService(resource_context)->PurgeMemory(); |
| 126 } | 130 } |
| 127 | 131 |
| 128 DOMStorageContextImpl* GetDOMStorageContextImpl(BrowserContext* context) { | 132 DOMStorageContextImpl* GetDOMStorageContextImpl(BrowserContext* context) { |
| 129 return static_cast<DOMStorageContextImpl*>( | 133 return static_cast<DOMStorageContextImpl*>( |
| 130 BrowserContext::GetDOMStorageContext(context)); | 134 BrowserContext::GetDOMStorageContext(context)); |
| 131 } | 135 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // This will be enough to tickle initialization of BrowserContext if | 178 // This will be enough to tickle initialization of BrowserContext if |
| 175 // necessary, which initializes ResourceContext. The reason we don't call | 179 // necessary, which initializes ResourceContext. The reason we don't call |
| 176 // ResourceContext::InitializeResourceContext directly here is that if | 180 // ResourceContext::InitializeResourceContext directly here is that if |
| 177 // ResourceContext ends up initializing it will call back into BrowserContext | 181 // ResourceContext ends up initializing it will call back into BrowserContext |
| 178 // and when that call return it'll end rewriting its UserData map (with the | 182 // and when that call return it'll end rewriting its UserData map (with the |
| 179 // same value) but this causes a race condition. See http://crbug.com/115678. | 183 // same value) but this causes a race condition. See http://crbug.com/115678. |
| 180 CreateQuotaManagerAndClients(context); | 184 CreateQuotaManagerAndClients(context); |
| 181 } | 185 } |
| 182 | 186 |
| 183 void BrowserContext::SaveSessionState(BrowserContext* browser_context) { | 187 void BrowserContext::SaveSessionState(BrowserContext* browser_context) { |
| 184 GetDatabaseTracker(browser_context)->SaveSessionState(); | 188 GetDatabaseTracker(browser_context)->SetForceKeepSessionState(); |
| 185 | 189 |
| 186 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 190 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 187 BrowserThread::PostTask( | 191 BrowserThread::PostTask( |
| 188 BrowserThread::IO, FROM_HERE, | 192 BrowserThread::IO, FROM_HERE, |
| 189 base::Bind(&SaveSessionStateOnIOThread, | 193 base::Bind(&SaveSessionStateOnIOThread, |
| 190 browser_context->GetResourceContext())); | 194 browser_context->GetResourceContext())); |
| 191 } | 195 } |
| 192 | 196 |
| 193 GetDOMStorageContextImpl(browser_context)->SaveSessionState(); | 197 GetDOMStorageContextImpl(browser_context)->SetForceKeepSessionState(); |
| 194 | 198 |
| 195 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { | 199 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { |
| 196 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( | 200 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( |
| 197 GetIndexedDBContext(browser_context)); | 201 GetIndexedDBContext(browser_context)); |
| 198 BrowserThread::PostTask( | 202 BrowserThread::PostTask( |
| 199 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 203 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
| 200 base::Bind(&SaveSessionStateOnWebkitThread, | 204 base::Bind(&SaveSessionStateOnWebkitThread, |
| 201 make_scoped_refptr(indexed_db))); | 205 make_scoped_refptr(indexed_db))); |
| 202 } | 206 } |
| 203 } | 207 } |
| 204 | 208 |
| 205 void BrowserContext::ClearLocalOnDestruction(BrowserContext* browser_context) { | |
| 206 GetDOMStorageContextImpl(browser_context)->SetClearLocalState(true); | |
| 207 | |
| 208 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( | |
| 209 GetIndexedDBContext(browser_context)); | |
| 210 indexed_db->set_clear_local_state_on_exit(true); | |
| 211 | |
| 212 GetDatabaseTracker(browser_context)->SetClearLocalStateOnExit(true); | |
| 213 | |
| 214 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | |
| 215 BrowserThread::PostTask( | |
| 216 BrowserThread::IO, FROM_HERE, | |
| 217 base::Bind(&appcache::AppCacheService::set_clear_local_state_on_exit, | |
| 218 base::Unretained(GetAppCacheService(browser_context)), true)); | |
| 219 } | |
| 220 } | |
| 221 | |
| 222 void BrowserContext::PurgeMemory(BrowserContext* browser_context) { | 209 void BrowserContext::PurgeMemory(BrowserContext* browser_context) { |
| 223 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 210 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 224 BrowserThread::PostTask( | 211 BrowserThread::PostTask( |
| 225 BrowserThread::IO, FROM_HERE, | 212 BrowserThread::IO, FROM_HERE, |
| 226 base::Bind(&PurgeMemoryOnIOThread, | 213 base::Bind(&PurgeMemoryOnIOThread, |
| 227 browser_context->GetResourceContext())); | 214 browser_context->GetResourceContext())); |
| 228 } | 215 } |
| 229 | 216 |
| 230 GetDOMStorageContextImpl(browser_context)->PurgeMemory(); | 217 GetDOMStorageContextImpl(browser_context)->PurgeMemory(); |
| 231 } | 218 } |
| 232 | 219 |
| 233 BrowserContext::~BrowserContext() { | 220 BrowserContext::~BrowserContext() { |
| 234 // These message loop checks are just to avoid leaks in unittests. | 221 // These message loop checks are just to avoid leaks in unittests. |
| 235 if (GetUserData(kDatabaseTrackerKeyName) && | 222 if (GetUserData(kDatabaseTrackerKeyName) && |
| 236 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { | 223 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
| 237 BrowserThread::PostTask( | 224 BrowserThread::PostTask( |
| 238 BrowserThread::FILE, FROM_HERE, | 225 BrowserThread::FILE, FROM_HERE, |
| 239 base::Bind(&webkit_database::DatabaseTracker::Shutdown, | 226 base::Bind(&webkit_database::DatabaseTracker::Shutdown, |
| 240 GetDatabaseTracker(this))); | 227 GetDatabaseTracker(this))); |
| 241 } | 228 } |
| 242 | 229 |
| 243 if (GetUserData(kDOMStorageContextKeyName)) | 230 if (GetUserData(kDOMStorageContextKeyName)) |
| 244 GetDOMStorageContextImpl(this)->Shutdown(); | 231 GetDOMStorageContextImpl(this)->Shutdown(); |
| 245 } | 232 } |
| 246 | 233 |
| 247 } // namespace content | 234 } // namespace content |
| OLD | NEW |