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/browser/storage_partition_impl_map.h" | 5 #include "content/browser/storage_partition_impl_map.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 new DeveloperProtocolHandler(appcache_service, | 180 new DeveloperProtocolHandler(appcache_service, |
181 blob_storage_context->controller())); | 181 blob_storage_context->controller())); |
182 | 182 |
183 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! | 183 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! |
184 } | 184 } |
185 | 185 |
186 } // namespace | 186 } // namespace |
187 | 187 |
188 StoragePartitionImplMap::StoragePartitionImplMap( | 188 StoragePartitionImplMap::StoragePartitionImplMap( |
189 BrowserContext* browser_context) | 189 BrowserContext* browser_context) |
190 : browser_context_(browser_context) { | 190 : browser_context_(browser_context), |
| 191 resource_context_initialized_(false) { |
191 } | 192 } |
192 | 193 |
193 StoragePartitionImplMap::~StoragePartitionImplMap() { | 194 StoragePartitionImplMap::~StoragePartitionImplMap() { |
194 STLDeleteContainerPairSecondPointers(partitions_.begin(), | 195 STLDeleteContainerPairSecondPointers(partitions_.begin(), |
195 partitions_.end()); | 196 partitions_.end()); |
196 } | 197 } |
197 | 198 |
198 StoragePartitionImpl* StoragePartitionImplMap::Get( | 199 StoragePartitionImpl* StoragePartitionImplMap::Get( |
199 const std::string& partition_id) { | 200 const std::string& partition_domain, |
| 201 const std::string& partition_name, |
| 202 bool in_memory) { |
| 203 // TODO(ajwong): ResourceContexts no longer have any storage related state. |
| 204 // We should move this into a place where it is called once per |
| 205 // BrowserContext creation rather than piggybacking off the default context |
| 206 // creation. |
| 207 if (!resource_context_initialized_) { |
| 208 resource_context_initialized_ = true; |
| 209 InitializeResourceContext(browser_context_); |
| 210 } |
| 211 |
| 212 bool in_memory_only = in_memory || browser_context_->IsOffTheRecord(); |
| 213 |
| 214 // TODO(nasko): Webview tags with named partitions will have both |
| 215 // partition_domain and partition_name set. In this case, mark them in-memory |
| 216 // until the on-disk storage code has landed. |
| 217 if (!partition_domain.empty() && !partition_name.empty()) |
| 218 in_memory_only = true; |
| 219 |
200 // Find the previously created partition if it's available. | 220 // Find the previously created partition if it's available. |
201 std::map<std::string, StoragePartitionImpl*>::const_iterator it = | 221 StoragePartitionImpl::StoragePartitionDescriptor partition_descriptor( |
202 partitions_.find(partition_id); | 222 partition_domain, partition_name, in_memory_only); |
| 223 |
| 224 PartitionsMap::const_iterator it = partitions_.find(partition_descriptor); |
203 if (it != partitions_.end()) | 225 if (it != partitions_.end()) |
204 return it->second; | 226 return it->second; |
205 | 227 |
206 // There was no previous partition, so let's make a new one. | 228 // There was no previous partition, so let's make a new one. |
207 StoragePartitionImpl* partition = | 229 StoragePartitionImpl* partition = |
208 StoragePartitionImpl::Create(browser_context_, partition_id, | 230 StoragePartitionImpl::Create(browser_context_, partition_descriptor, |
209 browser_context_->GetPath()); | 231 browser_context_->GetPath()); |
210 partitions_[partition_id] = partition; | 232 partitions_[partition_descriptor] = partition; |
211 | 233 |
212 // These calls must happen after StoragePartitionImpl::Create(). | 234 // These calls must happen after StoragePartitionImpl::Create(). |
213 partition->SetURLRequestContext( | 235 partition->SetURLRequestContext( |
214 partition_id.empty() ? | 236 partition_domain.empty() ? |
215 browser_context_->GetRequestContext() : | 237 browser_context_->GetRequestContext() : |
216 browser_context_->GetRequestContextForStoragePartition( | 238 browser_context_->GetRequestContextForStoragePartition( |
217 partition->GetPath(), false)); | 239 partition->GetPath(), in_memory_only)); |
218 partition->SetMediaURLRequestContext( | 240 partition->SetMediaURLRequestContext( |
219 partition_id.empty() ? | 241 partition_domain.empty() ? |
220 browser_context_->GetMediaRequestContext() : | 242 browser_context_->GetMediaRequestContext() : |
221 browser_context_->GetMediaRequestContextForStoragePartition( | 243 browser_context_->GetMediaRequestContextForStoragePartition( |
222 partition->GetPath(), false)); | 244 partition->GetPath(), in_memory_only)); |
223 | 245 |
224 PostCreateInitialization(partition); | 246 PostCreateInitialization(partition); |
225 | 247 |
226 // TODO(ajwong): ResourceContexts no longer have any storage related state. | |
227 // We should move this into a place where it is called once per | |
228 // BrowserContext creation rather than piggybacking off the default context | |
229 // creation. | |
230 if (partition_id.empty()) { | |
231 InitializeResourceContext(browser_context_); | |
232 } | |
233 | |
234 return partition; | 248 return partition; |
235 } | 249 } |
236 | 250 |
237 void StoragePartitionImplMap::ForEach( | 251 void StoragePartitionImplMap::ForEach( |
238 const BrowserContext::StoragePartitionCallback& callback) { | 252 const BrowserContext::StoragePartitionCallback& callback) { |
239 for (std::map<std::string, StoragePartitionImpl*>::const_iterator it = | 253 for (PartitionsMap::const_iterator it = partitions_.begin(); |
240 partitions_.begin(); | |
241 it != partitions_.end(); | 254 it != partitions_.end(); |
242 ++it) { | 255 ++it) { |
243 callback.Run(it->first, it->second); | 256 callback.Run(it->second); |
244 } | 257 } |
245 } | 258 } |
246 | 259 |
247 void StoragePartitionImplMap::PostCreateInitialization( | 260 void StoragePartitionImplMap::PostCreateInitialization( |
248 StoragePartitionImpl* partition) { | 261 StoragePartitionImpl* partition) { |
249 // Check first to avoid memory leak in unittests. | 262 // Check first to avoid memory leak in unittests. |
250 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 263 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
251 BrowserThread::PostTask( | 264 BrowserThread::PostTask( |
252 BrowserThread::IO, FROM_HERE, | 265 BrowserThread::IO, FROM_HERE, |
253 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 266 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
(...skipping 18 matching lines...) Expand all Loading... |
272 | 285 |
273 // We do not call InitializeURLRequestContext() for media contexts because, | 286 // We do not call InitializeURLRequestContext() for media contexts because, |
274 // other than the HTTP cache, the media contexts share the same backing | 287 // other than the HTTP cache, the media contexts share the same backing |
275 // objects as their associated "normal" request context. Thus, the previous | 288 // objects as their associated "normal" request context. Thus, the previous |
276 // call serves to initialize the media request context for this storage | 289 // call serves to initialize the media request context for this storage |
277 // partition as well. | 290 // partition as well. |
278 } | 291 } |
279 } | 292 } |
280 | 293 |
281 } // namespace content | 294 } // namespace content |
OLD | NEW |