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 "base/file_path.h" | |
8 #include "base/stl_util.h" | |
7 #include "content/browser/appcache/chrome_appcache_service.h" | 9 #include "content/browser/appcache/chrome_appcache_service.h" |
8 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 10 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
9 #include "content/browser/download/download_file_manager.h" | 11 #include "content/browser/download/download_file_manager.h" |
10 #include "content/browser/download/download_manager_impl.h" | 12 #include "content/browser/download/download_manager_impl.h" |
11 #include "content/browser/fileapi/browser_file_system_helper.h" | 13 #include "content/browser/fileapi/browser_file_system_helper.h" |
12 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" | 14 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" |
13 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 15 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
14 #include "content/browser/resource_context_impl.h" | 16 #include "content/browser/resource_context_impl.h" |
17 #include "content/common/child_process_host_impl.h" | |
15 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
17 #include "content/public/common/content_constants.h" | 20 #include "content/public/common/content_constants.h" |
18 #include "net/base/server_bound_cert_service.h" | 21 #include "net/base/server_bound_cert_service.h" |
19 #include "net/base/server_bound_cert_store.h" | 22 #include "net/base/server_bound_cert_store.h" |
20 #include "net/cookies/cookie_monster.h" | 23 #include "net/cookies/cookie_monster.h" |
21 #include "net/cookies/cookie_store.h" | 24 #include "net/cookies/cookie_store.h" |
22 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
23 #include "webkit/database/database_tracker.h" | 26 #include "webkit/database/database_tracker.h" |
24 #include "webkit/quota/quota_manager.h" | 27 #include "webkit/quota/quota_manager.h" |
25 | 28 |
26 using appcache::AppCacheService; | 29 using appcache::AppCacheService; |
27 using base::UserDataAdapter; | 30 using base::UserDataAdapter; |
28 using content::BrowserThread; | 31 using content::BrowserThread; |
29 using fileapi::FileSystemContext; | 32 using fileapi::FileSystemContext; |
30 using quota::QuotaManager; | 33 using quota::QuotaManager; |
31 using webkit_database::DatabaseTracker; | 34 using webkit_database::DatabaseTracker; |
32 | 35 |
33 // Key names on BrowserContext. | 36 // Key names on BrowserContext. |
34 static const char* kAppCacheServicKeyName = "content_appcache_service_tracker"; | |
35 static const char* kDatabaseTrackerKeyName = "content_database_tracker"; | |
36 static const char* kDOMStorageContextKeyName = "content_dom_storage_context"; | |
37 static const char* kDownloadManagerKeyName = "download_manager"; | 37 static const char* kDownloadManagerKeyName = "download_manager"; |
38 static const char* kFileSystemContextKeyName = "content_file_system_context"; | 38 static const char* kStorageParitionMapKeyName = "content_storage_partition_map"; |
39 static const char* kIndexedDBContextKeyName = "content_indexed_db_context"; | 39 |
40 static const char* kQuotaManagerKeyName = "content_quota_manager"; | 40 // Dirname for storing persistent data for renderers with partitioned storage. |
Charlie Reis
2012/07/02 23:21:23
partitioned -> isolated
I think this would be mor
awong
2012/07/09 20:37:43
sgtm.
| |
41 const FilePath::CharType kStoragePartitionDirName[] = | |
42 FILE_PATH_LITERAL("Storage Partitions"); | |
41 | 43 |
42 namespace content { | 44 namespace content { |
43 | 45 |
44 namespace { | 46 namespace { |
45 | 47 |
46 void CreateQuotaManagerAndClients(BrowserContext* context) { | 48 class StoragePartition { |
Charlie Reis
2012/07/02 23:21:23
Please give this a class-level comment.
awong
2012/07/09 20:37:43
Done.
| |
47 if (context->GetUserData(kQuotaManagerKeyName)) { | 49 public: |
48 DCHECK(context->GetUserData(kDatabaseTrackerKeyName)); | 50 ~StoragePartition() { |
49 DCHECK(context->GetUserData(kDOMStorageContextKeyName)); | 51 // These message loop checks are just to avoid leaks in unittests. |
50 DCHECK(context->GetUserData(kFileSystemContextKeyName)); | 52 if (database_tracker() && |
51 DCHECK(context->GetUserData(kIndexedDBContextKeyName)); | 53 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
54 BrowserThread::PostTask( | |
55 BrowserThread::FILE, FROM_HERE, | |
56 base::Bind(&webkit_database::DatabaseTracker::Shutdown, | |
57 database_tracker())); | |
58 } | |
59 | |
60 if (dom_storage_context()) | |
61 dom_storage_context()->Shutdown(); | |
62 } | |
63 | |
64 static StoragePartition* Create(BrowserContext* context, | |
65 FilePath partition_path) { | |
66 // All of the clients have to be created and registered with the | |
67 // QuotaManager prior to the QuotaManger being used. So we do them | |
68 // all together here prior to handing out a reference to anything | |
69 // that utlizes the QuotaManager. | |
Charlie Reis
2012/07/02 23:21:23
nits: Drop the "So", and utlizes -> utilizes
I do
awong
2012/07/09 20:37:43
Done.
| |
70 scoped_refptr<QuotaManager> quota_manager = new quota::QuotaManager( | |
71 context->IsOffTheRecord(), partition_path, | |
72 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | |
73 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | |
74 context->GetSpecialStoragePolicy()); | |
75 | |
76 // Each consumer is responsible for registering its QuotaClient during | |
77 // its construction. | |
78 scoped_refptr<FileSystemContext> filesystem_context = | |
79 CreateFileSystemContext(partition_path, context->IsOffTheRecord(), | |
80 context->GetSpecialStoragePolicy(), | |
81 quota_manager->proxy()); | |
82 | |
83 scoped_refptr<DatabaseTracker> database_tracker = new DatabaseTracker( | |
84 partition_path, context->IsOffTheRecord(), | |
85 context->GetSpecialStoragePolicy(), quota_manager->proxy(), | |
86 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | |
87 | |
88 FilePath path = context->IsOffTheRecord() ? FilePath() : partition_path; | |
89 scoped_refptr<DOMStorageContextImpl> dom_storage_context = | |
90 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); | |
91 | |
92 scoped_refptr<IndexedDBContextImpl> indexed_db_context = | |
93 new IndexedDBContextImpl(path, context->GetSpecialStoragePolicy(), | |
94 quota_manager->proxy(), | |
95 BrowserThread::GetMessageLoopProxyForThread( | |
96 BrowserThread::WEBKIT_DEPRECATED)); | |
97 | |
98 scoped_refptr<ChromeAppCacheService> appcache_service = | |
99 new ChromeAppCacheService(quota_manager->proxy()); | |
100 | |
101 return new StoragePartition(context, | |
102 partition_path, | |
103 quota_manager, | |
104 appcache_service, | |
105 filesystem_context, | |
106 database_tracker, | |
107 dom_storage_context, | |
108 indexed_db_context); | |
109 } | |
110 | |
111 quota::QuotaManager* quota_manager() { | |
112 return quota_manager_; | |
113 } | |
114 ChromeAppCacheService* appcache_service() { | |
115 return appcache_service_; | |
116 } | |
117 fileapi::FileSystemContext* filesystem_context() { | |
118 return filesystem_context_; | |
119 } | |
120 webkit_database::DatabaseTracker* database_tracker() { | |
121 return database_tracker_; | |
122 } | |
123 DOMStorageContextImpl* dom_storage_context() { | |
124 return dom_storage_context_; | |
125 } | |
126 IndexedDBContext* indexed_db_context() { | |
127 return indexed_db_context_; | |
128 } | |
129 | |
130 private: | |
131 // TODO(ajwong): Break the direct dependency on browser_context. We only | |
132 // need 2 pieces of info from it for use in the Initialize() function. | |
133 StoragePartition(BrowserContext* browser_context, | |
134 const FilePath& partition_path, | |
135 quota::QuotaManager* quota_manager, | |
136 ChromeAppCacheService* appcache_service, | |
137 fileapi::FileSystemContext* filesystem_context, | |
138 webkit_database::DatabaseTracker* database_tracker, | |
139 DOMStorageContextImpl* dom_storage_context, | |
140 IndexedDBContext* indexed_db_context) | |
141 : browser_context_(browser_context), | |
142 partition_path_(partition_path), | |
143 quota_manager_(quota_manager), | |
144 appcache_service_(appcache_service), | |
145 filesystem_context_(filesystem_context), | |
146 database_tracker_(database_tracker), | |
147 dom_storage_context_(dom_storage_context), | |
148 indexed_db_context_(indexed_db_context) { | |
149 } | |
150 | |
151 BrowserContext* browser_context_; | |
152 FilePath partition_path_; | |
153 scoped_refptr<quota::QuotaManager> quota_manager_; | |
154 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
155 scoped_refptr<fileapi::FileSystemContext> filesystem_context_; | |
156 scoped_refptr<webkit_database::DatabaseTracker> database_tracker_; | |
157 scoped_refptr<DOMStorageContextImpl> dom_storage_context_; | |
158 scoped_refptr<IndexedDBContext> indexed_db_context_; | |
159 }; | |
160 | |
161 class StoragePartitionMap : public base::SupportsUserData::Data { | |
Charlie Reis
2012/07/02 23:21:23
Class level comment.
awong
2012/07/09 20:37:43
Done.
| |
162 public: | |
163 explicit StoragePartitionMap(BrowserContext* browser_context) | |
164 : browser_context_(browser_context) { | |
165 } | |
166 | |
167 virtual ~StoragePartitionMap() { | |
168 STLDeleteContainerPairSecondPointers(partitions_.begin(), | |
169 partitions_.end()); | |
170 } | |
171 | |
172 StoragePartition* Get(const std::string& partition_id) { | |
173 // Find the previously created partition if it's available. | |
174 std::map<std::string, StoragePartition*>::const_iterator it = | |
175 partitions_.find(partition_id); | |
176 if (it != partitions_.end()) { | |
Charlie Reis
2012/07/02 23:21:23
nit: No braces.
awong
2012/07/09 20:37:43
Done.
| |
177 return it->second; | |
178 } | |
179 | |
180 // There was no previous partition, so let's make a new one. | |
181 FilePath partition_path = browser_context_->GetPath(); | |
182 if (!partition_id.empty()) { | |
183 CHECK(IsStringASCII(partition_id)); | |
Charlie Reis
2012/07/02 23:21:23
Are we ever taking this in from an untrusted conte
awong
2012/07/09 20:37:43
We aren't taking it from an untrusted context now,
| |
184 partition_path = partition_path.Append(kStoragePartitionDirName) | |
185 .AppendASCII(partition_id); | |
186 } | |
187 | |
188 StoragePartition* storage_partition = | |
189 StoragePartition::Create(browser_context_, partition_path); | |
190 partitions_[partition_id] = storage_partition; | |
191 | |
192 PostAddInitialization(storage_partition, partition_path); | |
193 | |
194 // TODO(ajwong): We need to remove this conditional by making | |
195 // InitializeResourceContext() understand having different parition data | |
Charlie Reis
2012/07/02 23:21:23
nit: partition
awong
2012/07/09 20:37:43
Done.
| |
196 // based on the renderer_id. | |
197 if (partition_id.empty()) { | |
198 InitializeResourceContext(browser_context_); | |
199 } | |
200 | |
201 return storage_partition; | |
202 } | |
203 | |
204 void ForEach(const base::Callback<void(StoragePartition*)>& callback) { | |
205 for (std::map<std::string, StoragePartition*>::const_iterator it = | |
206 partitions_.begin(); | |
207 it != partitions_.end(); | |
208 ++it) { | |
209 callback.Run(it->second); | |
210 } | |
211 } | |
212 | |
213 private: | |
214 // TODO(ajwong): This must always be called *after* it's been added to the | |
215 // partition map. This feels dangerous. Should this not be in this class? | |
216 void PostAddInitialization(StoragePartition* partition, | |
Charlie Reis
2012/07/02 23:21:23
PostCreateInitialization? Seems more consistent t
awong
2012/07/09 20:37:43
Good point. Done.
I hate this function BTW. It's
| |
217 const FilePath& partition_path) { | |
218 // Check first to avoid memory leak in unittests. | |
219 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | |
220 BrowserThread::PostTask( | |
221 BrowserThread::IO, FROM_HERE, | |
222 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | |
223 partition->appcache_service(), | |
224 browser_context_->IsOffTheRecord() ? FilePath() : | |
225 partition_path.Append(content::kAppCacheDirname), | |
226 browser_context_->GetResourceContext(), | |
227 make_scoped_refptr( | |
228 browser_context_->GetSpecialStoragePolicy()))); | |
229 } | |
230 } | |
231 | |
232 BrowserContext* browser_context_; | |
233 std::map<std::string, StoragePartition*> partitions_; | |
234 }; | |
235 | |
236 StoragePartition* GetStoragePartition(BrowserContext* browser_context, | |
237 int renderer_child_id) { | |
238 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( | |
239 browser_context->GetUserData(kStorageParitionMapKeyName)); | |
240 if (!partition_map) { | |
241 partition_map = new StoragePartitionMap(browser_context); | |
242 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); | |
243 } | |
244 | |
245 const std::string& partition_id = | |
246 GetContentClient()->browser()->GetStoragePartitionForChildProcess( | |
247 browser_context, | |
248 renderer_child_id); | |
249 | |
250 return partition_map->Get(partition_id); | |
251 } | |
252 | |
253 void ForEachStoragePartition( | |
254 BrowserContext* browser_context, | |
255 const base::Callback<void(StoragePartition*)>& callback) { | |
256 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( | |
257 browser_context->GetUserData(kStorageParitionMapKeyName)); | |
258 if (!partition_map) { | |
52 return; | 259 return; |
53 } | 260 } |
54 | 261 |
55 // All of the clients have to be created and registered with the | 262 partition_map->ForEach(callback); |
56 // QuotaManager prior to the QuotaManger being used. So we do them | 263 } |
57 // all together here prior to handing out a reference to anything | 264 |
58 // that utlizes the QuotaManager. | 265 void DomStorageAdapter( |
Charlie Reis
2012/07/02 23:21:23
These three names aren't making sense to me. If t
awong
2012/07/09 20:37:43
Called this one ProcessDomStorageContext().
As fo
Charlie Reis
2012/07/10 21:37:48
Thanks. ForEach* is ok.
| |
59 scoped_refptr<QuotaManager> quota_manager = new quota::QuotaManager( | 266 const base::Callback<void(DOMStorageContextImpl*)>& callback, |
60 context->IsOffTheRecord(), context->GetPath(), | 267 StoragePartition* partition) { |
61 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 268 callback.Run(partition->dom_storage_context()); |
62 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 269 } |
63 context->GetSpecialStoragePolicy()); | 270 |
64 context->SetUserData(kQuotaManagerKeyName, | 271 void DOMStorageContextForEach( |
nasko
2012/06/29 23:08:56
nit: In ForEachStoragePartition the "ForEach" part
awong
2012/07/09 20:37:43
Done.
| |
65 new UserDataAdapter<QuotaManager>(quota_manager)); | 272 BrowserContext* browser_context, |
66 | 273 const base::Callback<void(DOMStorageContextImpl*)>& callback) { |
67 // Each consumer is responsible for registering its QuotaClient during | 274 ForEachStoragePartition(browser_context, |
68 // its construction. | 275 base::Bind(&DomStorageAdapter, callback)); |
69 scoped_refptr<FileSystemContext> filesystem_context = CreateFileSystemContext( | |
70 context->GetPath(), context->IsOffTheRecord(), | |
71 context->GetSpecialStoragePolicy(), quota_manager->proxy()); | |
72 context->SetUserData( | |
73 kFileSystemContextKeyName, | |
74 new UserDataAdapter<FileSystemContext>(filesystem_context)); | |
75 | |
76 scoped_refptr<DatabaseTracker> db_tracker = new DatabaseTracker( | |
77 context->GetPath(), context->IsOffTheRecord(), | |
78 context->GetSpecialStoragePolicy(), quota_manager->proxy(), | |
79 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | |
80 context->SetUserData(kDatabaseTrackerKeyName, | |
81 new UserDataAdapter<DatabaseTracker>(db_tracker)); | |
82 | |
83 FilePath path = context->IsOffTheRecord() ? FilePath() : context->GetPath(); | |
84 scoped_refptr<DOMStorageContextImpl> dom_storage_context = | |
85 new DOMStorageContextImpl(path, context->GetSpecialStoragePolicy()); | |
86 context->SetUserData( | |
87 kDOMStorageContextKeyName, | |
88 new UserDataAdapter<DOMStorageContextImpl>(dom_storage_context)); | |
89 | |
90 scoped_refptr<IndexedDBContext> indexed_db_context = new IndexedDBContextImpl( | |
91 path, context->GetSpecialStoragePolicy(), quota_manager->proxy(), | |
92 BrowserThread::GetMessageLoopProxyForThread( | |
93 BrowserThread::WEBKIT_DEPRECATED)); | |
94 context->SetUserData( | |
95 kIndexedDBContextKeyName, | |
96 new UserDataAdapter<IndexedDBContext>(indexed_db_context)); | |
97 | |
98 scoped_refptr<ChromeAppCacheService> appcache_service = | |
99 new ChromeAppCacheService(quota_manager->proxy()); | |
100 context->SetUserData( | |
101 kAppCacheServicKeyName, | |
102 new UserDataAdapter<ChromeAppCacheService>(appcache_service)); | |
103 | |
104 InitializeResourceContext(context); | |
105 | |
106 // Check first to avoid memory leak in unittests. | |
107 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | |
108 BrowserThread::PostTask( | |
109 BrowserThread::IO, FROM_HERE, | |
110 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | |
111 appcache_service, | |
112 context->IsOffTheRecord() ? FilePath() : | |
113 context->GetPath().Append(content::kAppCacheDirname), | |
114 context->GetResourceContext(), | |
115 make_scoped_refptr(context->GetSpecialStoragePolicy()))); | |
116 } | |
117 } | 276 } |
118 | 277 |
119 void SaveSessionStateOnIOThread(ResourceContext* resource_context) { | 278 void SaveSessionStateOnIOThread(ResourceContext* resource_context) { |
120 resource_context->GetRequestContext()->cookie_store()->GetCookieMonster()-> | 279 resource_context->GetRequestContext()->cookie_store()->GetCookieMonster()-> |
121 SetForceKeepSessionState(); | 280 SetForceKeepSessionState(); |
122 resource_context->GetRequestContext()->server_bound_cert_service()-> | 281 resource_context->GetRequestContext()->server_bound_cert_service()-> |
123 GetCertStore()->SetForceKeepSessionState(); | 282 GetCertStore()->SetForceKeepSessionState(); |
124 ResourceContext::GetAppCacheService(resource_context)-> | 283 ResourceContext::GetAppCacheService(resource_context)-> |
125 set_force_keep_session_state(); | 284 set_force_keep_session_state(); |
126 } | 285 } |
127 | 286 |
128 void SaveSessionStateOnWebkitThread( | 287 void SaveSessionStateOnWebkitThread( |
129 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { | 288 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { |
130 indexed_db_context->SetForceKeepSessionState(); | 289 indexed_db_context->SetForceKeepSessionState(); |
131 } | 290 } |
132 | 291 |
133 void PurgeMemoryOnIOThread(ResourceContext* resource_context) { | 292 void PurgeMemoryOnIOThread(ResourceContext* resource_context) { |
134 ResourceContext::GetAppCacheService(resource_context)->PurgeMemory(); | 293 ResourceContext::GetAppCacheService(resource_context)->PurgeMemory(); |
135 } | 294 } |
136 | 295 |
137 DOMStorageContextImpl* GetDOMStorageContextImpl(BrowserContext* context) { | 296 DOMStorageContextImpl* GetDefaultDOMStorageContextImpl( |
297 BrowserContext* context) { | |
138 return static_cast<DOMStorageContextImpl*>( | 298 return static_cast<DOMStorageContextImpl*>( |
139 BrowserContext::GetDOMStorageContext(context)); | 299 BrowserContext::GetDefaultDOMStorageContext(context)); |
140 } | 300 } |
141 | 301 |
142 } // namespace | 302 } // namespace |
143 | 303 |
144 DownloadManager* BrowserContext::GetDownloadManager( | 304 DownloadManager* BrowserContext::GetDownloadManager( |
145 BrowserContext* context) { | 305 BrowserContext* context) { |
146 if (!context->GetUserData(kDownloadManagerKeyName)) { | 306 if (!context->GetUserData(kDownloadManagerKeyName)) { |
147 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 307 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
148 DCHECK(rdh); | 308 DCHECK(rdh); |
149 DownloadFileManager* file_manager = rdh->download_file_manager(); | 309 DownloadFileManager* file_manager = rdh->download_file_manager(); |
150 DCHECK(file_manager); | 310 DCHECK(file_manager); |
151 scoped_refptr<DownloadManager> download_manager = | 311 scoped_refptr<DownloadManager> download_manager = |
152 new DownloadManagerImpl( | 312 new DownloadManagerImpl( |
153 file_manager, | 313 file_manager, |
154 scoped_ptr<DownloadItemFactory>(), | 314 scoped_ptr<DownloadItemFactory>(), |
155 GetContentClient()->browser()->GetNetLog()); | 315 GetContentClient()->browser()->GetNetLog()); |
156 | 316 |
157 context->SetUserData( | 317 context->SetUserData( |
158 kDownloadManagerKeyName, | 318 kDownloadManagerKeyName, |
159 new UserDataAdapter<DownloadManager>(download_manager)); | 319 new UserDataAdapter<DownloadManager>(download_manager)); |
160 download_manager->SetDelegate(context->GetDownloadManagerDelegate()); | 320 download_manager->SetDelegate(context->GetDownloadManagerDelegate()); |
161 download_manager->Init(context); | 321 download_manager->Init(context); |
162 } | 322 } |
163 | 323 |
164 return UserDataAdapter<DownloadManager>::Get( | 324 return UserDataAdapter<DownloadManager>::Get( |
165 context, kDownloadManagerKeyName); | 325 context, kDownloadManagerKeyName); |
166 } | 326 } |
167 | 327 |
168 QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) { | 328 QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* browser_context) { |
Charlie Reis
2012/07/02 23:21:23
Should this be GetDefaultQuotaManager? Or do we n
awong
2012/07/09 20:37:43
There should be no "Default" anythings, but the tr
| |
169 CreateQuotaManagerAndClients(context); | 329 StoragePartition* partition = |
170 return UserDataAdapter<QuotaManager>::Get(context, kQuotaManagerKeyName); | 330 GetStoragePartition(browser_context, |
331 ChildProcessHostImpl::kInvalidChildProcessId); | |
Charlie Reis
2012/07/02 23:21:23
This looks odd to me, but I suppose it makes sense
awong
2012/07/09 20:37:43
I think we actually want ContentBrowserClient to d
| |
332 return partition->quota_manager(); | |
333 } | |
334 | |
335 DOMStorageContext* BrowserContext::GetDefaultDOMStorageContext( | |
336 BrowserContext* browser_context) { | |
337 return GetDOMStorageContext(browser_context, | |
338 ChildProcessHostImpl::kInvalidChildProcessId); | |
171 } | 339 } |
172 | 340 |
173 DOMStorageContext* BrowserContext::GetDOMStorageContext( | 341 DOMStorageContext* BrowserContext::GetDOMStorageContext( |
174 BrowserContext* context) { | 342 BrowserContext* browser_context, |
175 CreateQuotaManagerAndClients(context); | 343 int render_child_id) { |
176 return UserDataAdapter<DOMStorageContextImpl>::Get( | 344 StoragePartition* partition = |
177 context, kDOMStorageContextKeyName); | 345 GetStoragePartition(browser_context, render_child_id); |
346 return partition->dom_storage_context(); | |
178 } | 347 } |
179 | 348 |
180 IndexedDBContext* BrowserContext::GetIndexedDBContext(BrowserContext* context) { | 349 IndexedDBContext* BrowserContext::GetIndexedDBContext( |
181 CreateQuotaManagerAndClients(context); | 350 BrowserContext* browser_context) { |
182 return UserDataAdapter<IndexedDBContext>::Get( | 351 StoragePartition* partition = |
183 context, kIndexedDBContextKeyName); | 352 GetStoragePartition(browser_context, |
353 ChildProcessHostImpl::kInvalidChildProcessId); | |
354 return partition->indexed_db_context(); | |
184 } | 355 } |
185 | 356 |
186 DatabaseTracker* BrowserContext::GetDatabaseTracker(BrowserContext* context) { | 357 DatabaseTracker* BrowserContext::GetDatabaseTracker( |
187 CreateQuotaManagerAndClients(context); | 358 BrowserContext* browser_context) { |
188 return UserDataAdapter<DatabaseTracker>::Get( | 359 StoragePartition* partition = |
189 context, kDatabaseTrackerKeyName); | 360 GetStoragePartition(browser_context, |
361 ChildProcessHostImpl::kInvalidChildProcessId); | |
362 return partition->database_tracker(); | |
190 } | 363 } |
191 | 364 |
192 AppCacheService* BrowserContext::GetAppCacheService( | 365 AppCacheService* BrowserContext::GetAppCacheService( |
193 BrowserContext* browser_context) { | 366 BrowserContext* browser_context) { |
194 CreateQuotaManagerAndClients(browser_context); | 367 StoragePartition* partition = |
195 return UserDataAdapter<ChromeAppCacheService>::Get( | 368 GetStoragePartition(browser_context, |
196 browser_context, kAppCacheServicKeyName); | 369 ChildProcessHostImpl::kInvalidChildProcessId); |
370 return partition->appcache_service(); | |
197 } | 371 } |
198 | 372 |
199 FileSystemContext* BrowserContext::GetFileSystemContext( | 373 FileSystemContext* BrowserContext::GetFileSystemContext( |
200 BrowserContext* browser_context) { | 374 BrowserContext* browser_context) { |
201 CreateQuotaManagerAndClients(browser_context); | 375 StoragePartition* partition = |
202 return UserDataAdapter<FileSystemContext>::Get( | 376 GetStoragePartition(browser_context, |
203 browser_context, kFileSystemContextKeyName); | 377 ChildProcessHostImpl::kInvalidChildProcessId); |
378 return partition->filesystem_context(); | |
204 } | 379 } |
205 | 380 |
206 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { | 381 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { |
207 // This will be enough to tickle initialization of BrowserContext if | 382 // This will be enough to tickle initialization of BrowserContext if |
208 // necessary, which initializes ResourceContext. The reason we don't call | 383 // necessary, which initializes ResourceContext. The reason we don't call |
209 // ResourceContext::InitializeResourceContext directly here is that if | 384 // ResourceContext::InitializeResourceContext directly here is that if |
210 // ResourceContext ends up initializing it will call back into BrowserContext | 385 // ResourceContext ends up initializing it will call back into BrowserContext |
211 // and when that call return it'll end rewriting its UserData map (with the | 386 // and when that call returns it'll end rewriting its UserData map (with the |
212 // same value) but this causes a race condition. See http://crbug.com/115678. | 387 // same value) but this causes a race condition. See http://crbug.com/115678. |
213 CreateQuotaManagerAndClients(context); | 388 GetStoragePartition(context, ChildProcessHostImpl::kInvalidChildProcessId); |
214 } | 389 } |
215 | 390 |
216 void BrowserContext::SaveSessionState(BrowserContext* browser_context) { | 391 void BrowserContext::SaveSessionState(BrowserContext* browser_context) { |
217 GetDatabaseTracker(browser_context)->SetForceKeepSessionState(); | 392 GetDatabaseTracker(browser_context)->SetForceKeepSessionState(); |
218 | 393 |
219 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 394 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
220 BrowserThread::PostTask( | 395 BrowserThread::PostTask( |
221 BrowserThread::IO, FROM_HERE, | 396 BrowserThread::IO, FROM_HERE, |
222 base::Bind(&SaveSessionStateOnIOThread, | 397 base::Bind(&SaveSessionStateOnIOThread, |
223 browser_context->GetResourceContext())); | 398 browser_context->GetResourceContext())); |
224 } | 399 } |
225 | 400 |
226 GetDOMStorageContextImpl(browser_context)->SetForceKeepSessionState(); | 401 // TODO(ajwong): This is the only usage of GetDefaultDOMStorageContextImpl(). |
402 // After we migrate this to support multiple DOMStorageContexts, don't forget | |
403 // to remove the GetDefaultDOMStorageContextImpl() function as well. | |
404 GetDefaultDOMStorageContextImpl(browser_context)->SetForceKeepSessionState(); | |
227 | 405 |
228 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { | 406 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { |
229 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( | 407 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( |
230 GetIndexedDBContext(browser_context)); | 408 GetIndexedDBContext(browser_context)); |
231 BrowserThread::PostTask( | 409 BrowserThread::PostTask( |
232 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 410 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
233 base::Bind(&SaveSessionStateOnWebkitThread, | 411 base::Bind(&SaveSessionStateOnWebkitThread, |
234 make_scoped_refptr(indexed_db))); | 412 make_scoped_refptr(indexed_db))); |
235 } | 413 } |
236 } | 414 } |
237 | 415 |
238 void BrowserContext::PurgeMemory(BrowserContext* browser_context) { | 416 void BrowserContext::PurgeMemory(BrowserContext* browser_context) { |
239 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 417 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
240 BrowserThread::PostTask( | 418 BrowserThread::PostTask( |
241 BrowserThread::IO, FROM_HERE, | 419 BrowserThread::IO, FROM_HERE, |
242 base::Bind(&PurgeMemoryOnIOThread, | 420 base::Bind(&PurgeMemoryOnIOThread, |
243 browser_context->GetResourceContext())); | 421 browser_context->GetResourceContext())); |
244 } | 422 } |
245 | 423 |
246 GetDOMStorageContextImpl(browser_context)->PurgeMemory(); | 424 DOMStorageContextForEach(browser_context, |
425 base::Bind(&DOMStorageContextImpl::PurgeMemory)); | |
247 } | 426 } |
248 | 427 |
249 BrowserContext::~BrowserContext() { | 428 BrowserContext::~BrowserContext() { |
250 // These message loop checks are just to avoid leaks in unittests. | |
251 if (GetUserData(kDatabaseTrackerKeyName) && | |
252 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { | |
253 BrowserThread::PostTask( | |
254 BrowserThread::FILE, FROM_HERE, | |
255 base::Bind(&webkit_database::DatabaseTracker::Shutdown, | |
256 GetDatabaseTracker(this))); | |
257 } | |
258 | |
259 if (GetUserData(kDOMStorageContextKeyName)) | |
260 GetDOMStorageContextImpl(this)->Shutdown(); | |
261 | |
262 if (GetUserData(kDownloadManagerKeyName)) | 429 if (GetUserData(kDownloadManagerKeyName)) |
263 GetDownloadManager(this)->Shutdown(); | 430 GetDownloadManager(this)->Shutdown(); |
264 } | 431 } |
265 | 432 |
266 } // namespace content | 433 } // namespace content |
OLD | NEW |