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 |
200 // Find the previously created partition if it's available. | 212 // Find the previously created partition if it's available. |
201 std::map<std::string, StoragePartitionImpl*>::const_iterator it = | 213 StoragePartitionImpl::StoragePartitionConfig partition_config( |
202 partitions_.find(partition_id); | 214 partition_domain, partition_name, in_memory); |
| 215 |
| 216 PartitionMap::const_iterator it = partitions_.find(partition_config); |
203 if (it != partitions_.end()) | 217 if (it != partitions_.end()) |
204 return it->second; | 218 return it->second; |
205 | 219 |
206 // There was no previous partition, so let's make a new one. | 220 // There was no previous partition, so let's make a new one. |
207 StoragePartitionImpl* partition = | 221 StoragePartitionImpl* partition = |
208 StoragePartitionImpl::Create(browser_context_, partition_id, | 222 StoragePartitionImpl::Create(browser_context_, partition_config, |
209 browser_context_->GetPath()); | 223 browser_context_->GetPath()); |
210 partitions_[partition_id] = partition; | 224 partitions_[partition_config] = partition; |
211 | 225 |
212 // These calls must happen after StoragePartitionImpl::Create(). | 226 // These calls must happen after StoragePartitionImpl::Create(). |
213 partition->SetURLRequestContext( | 227 partition->SetURLRequestContext( |
214 partition_id.empty() ? | 228 partition_domain.empty() ? |
215 browser_context_->GetRequestContext() : | 229 browser_context_->GetRequestContext() : |
216 browser_context_->GetRequestContextForStoragePartition( | 230 browser_context_->GetRequestContextForStoragePartition( |
217 partition->GetPath(), false)); | 231 partition->GetPath(), in_memory)); |
218 partition->SetMediaURLRequestContext( | 232 partition->SetMediaURLRequestContext( |
219 partition_id.empty() ? | 233 partition_domain.empty() ? |
220 browser_context_->GetMediaRequestContext() : | 234 browser_context_->GetMediaRequestContext() : |
221 browser_context_->GetMediaRequestContextForStoragePartition( | 235 browser_context_->GetMediaRequestContextForStoragePartition( |
222 partition->GetPath(), false)); | 236 partition->GetPath(), in_memory)); |
223 | 237 |
224 PostCreateInitialization(partition); | 238 PostCreateInitialization(partition); |
225 | 239 |
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; | 240 return partition; |
235 } | 241 } |
236 | 242 |
237 void StoragePartitionImplMap::ForEach( | 243 void StoragePartitionImplMap::ForEach( |
238 const BrowserContext::StoragePartitionCallback& callback) { | 244 const BrowserContext::StoragePartitionCallback& callback) { |
239 for (std::map<std::string, StoragePartitionImpl*>::const_iterator it = | 245 for (PartitionMap::const_iterator it = partitions_.begin(); |
240 partitions_.begin(); | |
241 it != partitions_.end(); | 246 it != partitions_.end(); |
242 ++it) { | 247 ++it) { |
243 callback.Run(it->first, it->second); | 248 callback.Run(it->second); |
244 } | 249 } |
245 } | 250 } |
246 | 251 |
247 void StoragePartitionImplMap::PostCreateInitialization( | 252 void StoragePartitionImplMap::PostCreateInitialization( |
248 StoragePartitionImpl* partition) { | 253 StoragePartitionImpl* partition) { |
249 // Check first to avoid memory leak in unittests. | 254 // Check first to avoid memory leak in unittests. |
250 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 255 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
251 BrowserThread::PostTask( | 256 BrowserThread::PostTask( |
252 BrowserThread::IO, FROM_HERE, | 257 BrowserThread::IO, FROM_HERE, |
253 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 258 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
(...skipping 18 matching lines...) Expand all Loading... |
272 | 277 |
273 // We do not call InitializeURLRequestContext() for media contexts because, | 278 // We do not call InitializeURLRequestContext() for media contexts because, |
274 // other than the HTTP cache, the media contexts share the same backing | 279 // other than the HTTP cache, the media contexts share the same backing |
275 // objects as their associated "normal" request context. Thus, the previous | 280 // objects as their associated "normal" request context. Thus, the previous |
276 // call serves to initialize the media request context for this storage | 281 // call serves to initialize the media request context for this storage |
277 // partition as well. | 282 // partition as well. |
278 } | 283 } |
279 } | 284 } |
280 | 285 |
281 } // namespace content | 286 } // namespace content |
OLD | NEW |