Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1086)

Side by Side Diff: content/browser/storage_partition_impl_map.cc

Issue 11234032: Webview tag creation should be using storage partitions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added IndexedDB test. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 const bool& in_memory) {
203 if (!resource_context_initialized_) {
awong 2012/11/02 21:56:13 If you're planning on moving out this, add TODO?
nasko 2012/11/03 00:36:24 Meant to keep the original TODO. Thanks for the ca
204 resource_context_initialized_ = true;
205 InitializeResourceContext(browser_context_);
206 }
207
208 bool in_memory_only = false;
awong 2012/11/02 21:56:13 why not: bool in_memory_only = in_memory || brows
nasko 2012/11/03 00:36:24 Done.
209 if (in_memory || browser_context_->IsOffTheRecord())
210 in_memory_only = true;
211
212 // TODO(nasko): Webview tags with named partitions will have both
213 // partition_domain and partition_name set. In this case, mark them in-memory
214 // until the on-disk storage code has landed.
215 if (!partition_domain.empty() && !partition_name.empty())
awong 2012/11/02 21:56:13 Maybe move this into the calling function? That w
nasko 2012/11/03 00:36:24 The caller of this is BrowserContext. Since the ch
awong 2012/11/05 18:00:33 But this way the API is more complicated because t
awong 2012/11/05 20:11:18 For instance, doesn't content browser client ultim
nasko 2012/11/05 23:06:58 This is temporary until you fix the on-disk code,
216 in_memory_only = true;
217
200 // Find the previously created partition if it's available. 218 // Find the previously created partition if it's available.
201 std::map<std::string, StoragePartitionImpl*>::const_iterator it = 219 StoragePartitionImpl::StoragePartitionDescriptor partition_descriptor(
202 partitions_.find(partition_id); 220 partition_domain, partition_name, in_memory_only);
221
222 PartitionsMap::const_iterator it = partitions_.find(partition_descriptor);
203 if (it != partitions_.end()) 223 if (it != partitions_.end())
204 return it->second; 224 return it->second;
205 225
206 // There was no previous partition, so let's make a new one. 226 // There was no previous partition, so let's make a new one.
207 StoragePartitionImpl* partition = 227 StoragePartitionImpl* partition =
208 StoragePartitionImpl::Create(browser_context_, partition_id, 228 StoragePartitionImpl::Create(browser_context_, partition_descriptor,
209 browser_context_->GetPath()); 229 browser_context_->GetPath());
210 partitions_[partition_id] = partition; 230 partitions_[partition_descriptor] = partition;
211 231
212 // These calls must happen after StoragePartitionImpl::Create(). 232 // These calls must happen after StoragePartitionImpl::Create().
213 partition->SetURLRequestContext( 233 partition->SetURLRequestContext(
214 partition_id.empty() ? 234 partition_domain.empty() ?
215 browser_context_->GetRequestContext() : 235 browser_context_->GetRequestContext() :
216 browser_context_->GetRequestContextForStoragePartition( 236 browser_context_->GetRequestContextForStoragePartition(
217 partition->GetPath(), false)); 237 partition->GetPath(), in_memory_only));
218 partition->SetMediaURLRequestContext( 238 partition->SetMediaURLRequestContext(
219 partition_id.empty() ? 239 partition_domain.empty() ?
220 browser_context_->GetMediaRequestContext() : 240 browser_context_->GetMediaRequestContext() :
221 browser_context_->GetMediaRequestContextForStoragePartition( 241 browser_context_->GetMediaRequestContextForStoragePartition(
222 partition->GetPath(), false)); 242 partition->GetPath(), in_memory_only));
223 243
224 PostCreateInitialization(partition); 244 PostCreateInitialization(partition);
225 245
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; 246 return partition;
235 } 247 }
236 248
237 void StoragePartitionImplMap::ForEach( 249 void StoragePartitionImplMap::ForEach(
238 const BrowserContext::StoragePartitionCallback& callback) { 250 const BrowserContext::StoragePartitionCallback& callback) {
239 for (std::map<std::string, StoragePartitionImpl*>::const_iterator it = 251 for (PartitionsMap::const_iterator it = partitions_.begin();
240 partitions_.begin();
241 it != partitions_.end(); 252 it != partitions_.end();
242 ++it) { 253 ++it) {
243 callback.Run(it->first, it->second); 254 callback.Run(it->second);
244 } 255 }
245 } 256 }
246 257
247 void StoragePartitionImplMap::PostCreateInitialization( 258 void StoragePartitionImplMap::PostCreateInitialization(
248 StoragePartitionImpl* partition) { 259 StoragePartitionImpl* partition) {
249 // Check first to avoid memory leak in unittests. 260 // Check first to avoid memory leak in unittests.
250 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { 261 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
251 BrowserThread::PostTask( 262 BrowserThread::PostTask(
252 BrowserThread::IO, FROM_HERE, 263 BrowserThread::IO, FROM_HERE,
253 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, 264 base::Bind(&ChromeAppCacheService::InitializeOnIOThread,
(...skipping 18 matching lines...) Expand all
272 283
273 // We do not call InitializeURLRequestContext() for media contexts because, 284 // We do not call InitializeURLRequestContext() for media contexts because,
274 // other than the HTTP cache, the media contexts share the same backing 285 // other than the HTTP cache, the media contexts share the same backing
275 // objects as their associated "normal" request context. Thus, the previous 286 // objects as their associated "normal" request context. Thus, the previous
276 // call serves to initialize the media request context for this storage 287 // call serves to initialize the media request context for this storage
277 // partition as well. 288 // partition as well.
278 } 289 }
279 } 290 }
280 291
281 } // namespace content 292 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698