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/file_system/browser_file_system_helper.h" | 8 #include "content/browser/file_system/browser_file_system_helper.h" |
9 #include "content/browser/in_process_webkit/dom_storage_context_impl.h" | 9 #include "content/browser/in_process_webkit/dom_storage_context_impl.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/in_process_webkit/webkit_context.h" | |
12 #include "content/browser/resource_context_impl.h" | 11 #include "content/browser/resource_context_impl.h" |
13 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/common/content_constants.h" | 13 #include "content/public/common/content_constants.h" |
15 #include "net/base/cookie_monster.h" | 14 #include "net/base/cookie_monster.h" |
16 #include "net/base/cookie_store.h" | 15 #include "net/base/cookie_store.h" |
17 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
18 #include "webkit/database/database_tracker.h" | 17 #include "webkit/database/database_tracker.h" |
19 #include "webkit/quota/quota_manager.h" | 18 #include "webkit/quota/quota_manager.h" |
20 | 19 |
21 using appcache::AppCacheService; | 20 using appcache::AppCacheService; |
22 using base::UserDataAdapter; | 21 using base::UserDataAdapter; |
23 using content::BrowserThread; | 22 using content::BrowserThread; |
24 using fileapi::FileSystemContext; | 23 using fileapi::FileSystemContext; |
25 using quota::QuotaManager; | 24 using quota::QuotaManager; |
26 using webkit_database::DatabaseTracker; | 25 using webkit_database::DatabaseTracker; |
27 | 26 |
28 // Key names on BrowserContext. | 27 // Key names on BrowserContext. |
29 static const char* kAppCacheServicKeyName = "content_appcache_service_tracker"; | 28 static const char* kAppCacheServicKeyName = "content_appcache_service_tracker"; |
30 static const char* kDatabaseTrackerKeyName = "content_database_tracker"; | 29 static const char* kDatabaseTrackerKeyName = "content_database_tracker"; |
| 30 static const char* kDOMStorageContextKeyName = "content_dom_storage_context"; |
31 static const char* kFileSystemContextKeyName = "content_file_system_context"; | 31 static const char* kFileSystemContextKeyName = "content_file_system_context"; |
| 32 static const char* kIndexedDBContextKeyName = "content_indexed_db_context"; |
32 static const char* kQuotaManagerKeyName = "content_quota_manager"; | 33 static const char* kQuotaManagerKeyName = "content_quota_manager"; |
33 static const char* kWebKitContextKeyName = "content_webkit_context"; | |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 | 36 |
37 void CreateQuotaManagerAndClients(BrowserContext* context) { | 37 void CreateQuotaManagerAndClients(BrowserContext* context) { |
38 if (context->GetUserData(kQuotaManagerKeyName)) { | 38 if (context->GetUserData(kQuotaManagerKeyName)) { |
39 DCHECK(context->GetUserData(kDatabaseTrackerKeyName)); | 39 DCHECK(context->GetUserData(kDatabaseTrackerKeyName)); |
| 40 DCHECK(context->GetUserData(kDOMStorageContextKeyName)); |
40 DCHECK(context->GetUserData(kFileSystemContextKeyName)); | 41 DCHECK(context->GetUserData(kFileSystemContextKeyName)); |
41 DCHECK(context->GetUserData(kWebKitContextKeyName)); | 42 DCHECK(context->GetUserData(kIndexedDBContextKeyName)); |
42 return; | 43 return; |
43 } | 44 } |
44 | 45 |
45 // All of the clients have to be created and registered with the | 46 // All of the clients have to be created and registered with the |
46 // QuotaManager prior to the QuotaManger being used. So we do them | 47 // QuotaManager prior to the QuotaManger being used. So we do them |
47 // all together here prior to handing out a reference to anything | 48 // all together here prior to handing out a reference to anything |
48 // that utlizes the QuotaManager. | 49 // that utlizes the QuotaManager. |
49 scoped_refptr<QuotaManager> quota_manager = new quota::QuotaManager( | 50 scoped_refptr<QuotaManager> quota_manager = new quota::QuotaManager( |
50 context->IsOffTheRecord(), context->GetPath(), | 51 context->IsOffTheRecord(), context->GetPath(), |
51 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 52 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
(...skipping 11 matching lines...) Expand all Loading... |
63 kFileSystemContextKeyName, | 64 kFileSystemContextKeyName, |
64 new UserDataAdapter<FileSystemContext>(filesystem_context)); | 65 new UserDataAdapter<FileSystemContext>(filesystem_context)); |
65 | 66 |
66 scoped_refptr<DatabaseTracker> db_tracker = new DatabaseTracker( | 67 scoped_refptr<DatabaseTracker> db_tracker = new DatabaseTracker( |
67 context->GetPath(), context->IsOffTheRecord(), false, | 68 context->GetPath(), context->IsOffTheRecord(), false, |
68 context->GetSpecialStoragePolicy(), quota_manager->proxy(), | 69 context->GetSpecialStoragePolicy(), quota_manager->proxy(), |
69 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 70 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
70 context->SetUserData(kDatabaseTrackerKeyName, | 71 context->SetUserData(kDatabaseTrackerKeyName, |
71 new UserDataAdapter<DatabaseTracker>(db_tracker)); | 72 new UserDataAdapter<DatabaseTracker>(db_tracker)); |
72 | 73 |
73 scoped_refptr<WebKitContext> webkit_context = new WebKitContext( | 74 FilePath path = context->IsOffTheRecord() ? FilePath() : context->GetPath(); |
74 context->IsOffTheRecord(), context->GetPath(), | 75 scoped_refptr<DOMStorageContext> dom_storage_context = |
75 context->GetSpecialStoragePolicy(), quota_manager->proxy(), | 76 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); |
| 77 context->SetUserData( |
| 78 kDOMStorageContextKeyName, |
| 79 new UserDataAdapter<DOMStorageContext>(dom_storage_context)); |
| 80 |
| 81 scoped_refptr<IndexedDBContext> indexed_db_context = new IndexedDBContextImpl( |
| 82 path, context->GetSpecialStoragePolicy(), quota_manager->proxy(), |
76 BrowserThread::GetMessageLoopProxyForThread( | 83 BrowserThread::GetMessageLoopProxyForThread( |
77 BrowserThread::WEBKIT_DEPRECATED)); | 84 BrowserThread::WEBKIT_DEPRECATED)); |
78 context->SetUserData(kWebKitContextKeyName, | 85 context->SetUserData( |
79 new UserDataAdapter<WebKitContext>(webkit_context)); | 86 kIndexedDBContextKeyName, |
| 87 new UserDataAdapter<IndexedDBContext>(indexed_db_context)); |
80 | 88 |
81 scoped_refptr<ChromeAppCacheService> appcache_service = | 89 scoped_refptr<ChromeAppCacheService> appcache_service = |
82 new ChromeAppCacheService(quota_manager->proxy()); | 90 new ChromeAppCacheService(quota_manager->proxy()); |
83 context->SetUserData( | 91 context->SetUserData( |
84 kAppCacheServicKeyName, | 92 kAppCacheServicKeyName, |
85 new UserDataAdapter<ChromeAppCacheService>(appcache_service)); | 93 new UserDataAdapter<ChromeAppCacheService>(appcache_service)); |
86 | 94 |
87 EnsureResourceContextInitialized(context); | 95 EnsureResourceContextInitialized(context); |
88 | 96 |
89 // Check first to avoid memory leak in unittests. | 97 // Check first to avoid memory leak in unittests. |
(...skipping 30 matching lines...) Expand all Loading... |
120 void PurgeMemoryOnWebkitThread( | 128 void PurgeMemoryOnWebkitThread( |
121 scoped_refptr<DOMStorageContextImpl> dom_storage_context) { | 129 scoped_refptr<DOMStorageContextImpl> dom_storage_context) { |
122 dom_storage_context->PurgeMemory(); | 130 dom_storage_context->PurgeMemory(); |
123 } | 131 } |
124 | 132 |
125 QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) { | 133 QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) { |
126 CreateQuotaManagerAndClients(context); | 134 CreateQuotaManagerAndClients(context); |
127 return UserDataAdapter<QuotaManager>::Get(context, kQuotaManagerKeyName); | 135 return UserDataAdapter<QuotaManager>::Get(context, kQuotaManagerKeyName); |
128 } | 136 } |
129 | 137 |
130 WebKitContext* BrowserContext::GetWebKitContext(BrowserContext* context) { | 138 DOMStorageContext* BrowserContext::GetDOMStorageContext( |
| 139 BrowserContext* context) { |
131 CreateQuotaManagerAndClients(context); | 140 CreateQuotaManagerAndClients(context); |
132 return UserDataAdapter<WebKitContext>::Get(context, kWebKitContextKeyName); | 141 return UserDataAdapter<DOMStorageContext>::Get( |
| 142 context, kDOMStorageContextKeyName); |
| 143 } |
| 144 |
| 145 IndexedDBContext* BrowserContext::GetIndexedDBContext(BrowserContext* context) { |
| 146 CreateQuotaManagerAndClients(context); |
| 147 return UserDataAdapter<IndexedDBContext>::Get( |
| 148 context, kIndexedDBContextKeyName); |
133 } | 149 } |
134 | 150 |
135 DatabaseTracker* BrowserContext::GetDatabaseTracker(BrowserContext* context) { | 151 DatabaseTracker* BrowserContext::GetDatabaseTracker(BrowserContext* context) { |
136 CreateQuotaManagerAndClients(context); | 152 CreateQuotaManagerAndClients(context); |
137 return UserDataAdapter<DatabaseTracker>::Get( | 153 return UserDataAdapter<DatabaseTracker>::Get( |
138 context, kDatabaseTrackerKeyName); | 154 context, kDatabaseTrackerKeyName); |
139 } | 155 } |
140 | 156 |
141 AppCacheService* BrowserContext::GetAppCacheService( | 157 AppCacheService* BrowserContext::GetAppCacheService( |
142 BrowserContext* browser_context) { | 158 BrowserContext* browser_context) { |
(...skipping 18 matching lines...) Expand all Loading... |
161 | 177 |
162 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 178 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
163 BrowserThread::PostTask( | 179 BrowserThread::PostTask( |
164 BrowserThread::IO, FROM_HERE, | 180 BrowserThread::IO, FROM_HERE, |
165 base::Bind(&SaveSessionStateOnIOThread, | 181 base::Bind(&SaveSessionStateOnIOThread, |
166 browser_context->GetResourceContext())); | 182 browser_context->GetResourceContext())); |
167 } | 183 } |
168 | 184 |
169 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { | 185 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { |
170 DOMStorageContextImpl* dom_context = static_cast<DOMStorageContextImpl*>( | 186 DOMStorageContextImpl* dom_context = static_cast<DOMStorageContextImpl*>( |
171 DOMStorageContextImpl::GetForBrowserContext(browser_context)); | 187 GetDOMStorageContext(browser_context)); |
172 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( | 188 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( |
173 IndexedDBContext::GetForBrowserContext(browser_context)); | 189 GetIndexedDBContext(browser_context)); |
174 BrowserThread::PostTask( | 190 BrowserThread::PostTask( |
175 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 191 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
176 base::Bind(&SaveSessionStateOnWebkitThread, | 192 base::Bind(&SaveSessionStateOnWebkitThread, |
177 make_scoped_refptr(dom_context), | 193 make_scoped_refptr(dom_context), |
178 make_scoped_refptr(indexed_db))); | 194 make_scoped_refptr(indexed_db))); |
179 } | 195 } |
180 } | 196 } |
181 | 197 |
182 void BrowserContext::ClearLocalOnDestruction(BrowserContext* browser_context) { | 198 void BrowserContext::ClearLocalOnDestruction(BrowserContext* browser_context) { |
183 DOMStorageContextImpl* dom_context = static_cast<DOMStorageContextImpl*>( | 199 DOMStorageContextImpl* dom_context = static_cast<DOMStorageContextImpl*>( |
184 DOMStorageContextImpl::GetForBrowserContext(browser_context)); | 200 GetDOMStorageContext(browser_context)); |
185 dom_context->set_clear_local_state_on_exit(true); | 201 dom_context->set_clear_local_state_on_exit(true); |
186 | 202 |
187 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( | 203 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( |
188 IndexedDBContext::GetForBrowserContext(browser_context)); | 204 GetIndexedDBContext(browser_context)); |
189 indexed_db->set_clear_local_state_on_exit(true); | 205 indexed_db->set_clear_local_state_on_exit(true); |
190 | 206 |
191 GetDatabaseTracker(browser_context)->SetClearLocalStateOnExit(true); | 207 GetDatabaseTracker(browser_context)->SetClearLocalStateOnExit(true); |
192 | 208 |
193 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 209 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
194 BrowserThread::PostTask( | 210 BrowserThread::PostTask( |
195 BrowserThread::IO, FROM_HERE, | 211 BrowserThread::IO, FROM_HERE, |
196 base::Bind(&appcache::AppCacheService::set_clear_local_state_on_exit, | 212 base::Bind(&appcache::AppCacheService::set_clear_local_state_on_exit, |
197 base::Unretained(GetAppCacheService(browser_context)), true)); | 213 base::Unretained(GetAppCacheService(browser_context)), true)); |
198 } | 214 } |
199 } | 215 } |
200 | 216 |
201 void BrowserContext::PurgeMemory(BrowserContext* browser_context) { | 217 void BrowserContext::PurgeMemory(BrowserContext* browser_context) { |
202 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 218 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
203 BrowserThread::PostTask( | 219 BrowserThread::PostTask( |
204 BrowserThread::IO, FROM_HERE, | 220 BrowserThread::IO, FROM_HERE, |
205 base::Bind(&PurgeMemoryOnIOThread, | 221 base::Bind(&PurgeMemoryOnIOThread, |
206 browser_context->GetResourceContext())); | 222 browser_context->GetResourceContext())); |
207 } | 223 } |
208 | 224 |
209 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { | 225 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { |
210 DOMStorageContextImpl* dom_context = static_cast<DOMStorageContextImpl*>( | 226 DOMStorageContextImpl* dom_context = static_cast<DOMStorageContextImpl*>( |
211 DOMStorageContextImpl::GetForBrowserContext(browser_context)); | 227 GetDOMStorageContext(browser_context)); |
212 BrowserThread::PostTask( | 228 BrowserThread::PostTask( |
213 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 229 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
214 base::Bind(&PurgeMemoryOnWebkitThread, | 230 base::Bind(&PurgeMemoryOnWebkitThread, |
215 make_scoped_refptr(dom_context))); | 231 make_scoped_refptr(dom_context))); |
216 } | 232 } |
217 } | 233 } |
218 | 234 |
219 BrowserContext::~BrowserContext() { | 235 BrowserContext::~BrowserContext() { |
| 236 // These message loop checks are just to avoid leaks in unittests. |
220 if (GetUserData(kDatabaseTrackerKeyName) && | 237 if (GetUserData(kDatabaseTrackerKeyName) && |
221 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { | 238 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
222 BrowserThread::PostTask( | 239 BrowserThread::PostTask( |
223 BrowserThread::FILE, FROM_HERE, | 240 BrowserThread::FILE, FROM_HERE, |
224 base::Bind(&webkit_database::DatabaseTracker::Shutdown, | 241 base::Bind(&webkit_database::DatabaseTracker::Shutdown, |
225 GetDatabaseTracker(this))); | 242 GetDatabaseTracker(this))); |
226 } | 243 } |
| 244 |
| 245 if (GetUserData(kDOMStorageContextKeyName) && |
| 246 BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { |
| 247 DOMStorageContext* dom_storage_context = |
| 248 (static_cast<UserDataAdapter<DOMStorageContext>*>( |
| 249 GetUserData(kDOMStorageContextKeyName)))->release(); |
| 250 BrowserThread::ReleaseSoon( |
| 251 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, dom_storage_context); |
| 252 } |
227 } | 253 } |
228 | 254 |
229 } // namespace content | 255 } // namespace content |
OLD | NEW |