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

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

Powered by Google App Engine
This is Rietveld 408576698