| 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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 StoragePartitionImpl* StoragePartitionImplMap::Get( | 32 StoragePartitionImpl* StoragePartitionImplMap::Get( |
| 33 const std::string& partition_id) { | 33 const std::string& partition_id) { |
| 34 // Find the previously created partition if it's available. | 34 // Find the previously created partition if it's available. |
| 35 std::map<std::string, StoragePartitionImpl*>::const_iterator it = | 35 std::map<std::string, StoragePartitionImpl*>::const_iterator it = |
| 36 partitions_.find(partition_id); | 36 partitions_.find(partition_id); |
| 37 if (it != partitions_.end()) | 37 if (it != partitions_.end()) |
| 38 return it->second; | 38 return it->second; |
| 39 | 39 |
| 40 // There was no previous partition, so let's make a new one. | 40 // There was no previous partition, so let's make a new one. |
| 41 FilePath partition_path = browser_context_->GetPath(); | |
| 42 if (!partition_id.empty()) { | |
| 43 // TODO(ajwong): This should check the path is valid? | |
| 44 CHECK(IsStringASCII(partition_id)); | |
| 45 partition_path = partition_path.Append(kStoragePartitionDirname) | |
| 46 .AppendASCII(partition_id); | |
| 47 } | |
| 48 | |
| 49 StoragePartitionImpl* storage_partition = | 41 StoragePartitionImpl* storage_partition = |
| 50 StoragePartitionImpl::Create(browser_context_, partition_path); | 42 StoragePartitionImpl::Create(browser_context_, |
| 43 partition_id, |
| 44 browser_context_->GetPath()); |
| 51 partitions_[partition_id] = storage_partition; | 45 partitions_[partition_id] = storage_partition; |
| 52 | 46 |
| 53 net::URLRequestContextGetter* request_context = partition_id.empty() ? | 47 net::URLRequestContextGetter* request_context = partition_id.empty() ? |
| 54 browser_context_->GetRequestContext() : | 48 browser_context_->GetRequestContext() : |
| 55 browser_context_->GetRequestContextForStoragePartition(partition_id); | 49 browser_context_->GetRequestContextForStoragePartition(partition_id); |
| 56 | 50 |
| 57 PostCreateInitialization(storage_partition, partition_path, request_context); | 51 PostCreateInitialization(storage_partition, request_context); |
| 58 | 52 |
| 59 // TODO(ajwong): We need to remove this conditional by making | 53 // TODO(ajwong): We need to remove this conditional by making |
| 60 // InitializeResourceContext() understand having different partition data | 54 // InitializeResourceContext() understand having different partition data |
| 61 // based on the renderer_id. | 55 // based on the renderer_id. |
| 62 if (partition_id.empty()) { | 56 if (partition_id.empty()) { |
| 63 InitializeResourceContext(browser_context_); | 57 InitializeResourceContext(browser_context_); |
| 64 } | 58 } |
| 65 | 59 |
| 66 return storage_partition; | 60 return storage_partition; |
| 67 } | 61 } |
| 68 | 62 |
| 69 void StoragePartitionImplMap::ForEach( | 63 void StoragePartitionImplMap::ForEach( |
| 70 const BrowserContext::StoragePartitionCallback& callback) { | 64 const BrowserContext::StoragePartitionCallback& callback) { |
| 71 for (std::map<std::string, StoragePartitionImpl*>::const_iterator it = | 65 for (std::map<std::string, StoragePartitionImpl*>::const_iterator it = |
| 72 partitions_.begin(); | 66 partitions_.begin(); |
| 73 it != partitions_.end(); | 67 it != partitions_.end(); |
| 74 ++it) { | 68 ++it) { |
| 75 callback.Run(it->first, it->second); | 69 callback.Run(it->first, it->second); |
| 76 } | 70 } |
| 77 } | 71 } |
| 78 | 72 |
| 79 void StoragePartitionImplMap::PostCreateInitialization( | 73 void StoragePartitionImplMap::PostCreateInitialization( |
| 80 StoragePartitionImpl* partition, | 74 StoragePartitionImpl* partition, |
| 81 const FilePath& partition_path, | |
| 82 net::URLRequestContextGetter* request_context_getter) { | 75 net::URLRequestContextGetter* request_context_getter) { |
| 83 // Check first to avoid memory leak in unittests. | 76 // Check first to avoid memory leak in unittests. |
| 84 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 77 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 85 BrowserThread::PostTask( | 78 BrowserThread::PostTask( |
| 86 BrowserThread::IO, FROM_HERE, | 79 BrowserThread::IO, FROM_HERE, |
| 87 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 80 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
| 88 partition->GetAppCacheService(), | 81 partition->GetAppCacheService(), |
| 89 browser_context_->IsOffTheRecord() ? FilePath() : | 82 browser_context_->IsOffTheRecord() ? FilePath() : |
| 90 partition_path.Append(kAppCacheDirname), | 83 partition->GetPath().Append(kAppCacheDirname), |
| 91 browser_context_->GetResourceContext(), | 84 browser_context_->GetResourceContext(), |
| 92 make_scoped_refptr(request_context_getter), | 85 make_scoped_refptr(request_context_getter), |
| 93 make_scoped_refptr( | 86 make_scoped_refptr( |
| 94 browser_context_->GetSpecialStoragePolicy()))); | 87 browser_context_->GetSpecialStoragePolicy()))); |
| 95 } | 88 } |
| 96 } | 89 } |
| 97 | 90 |
| 98 } // namespace content | 91 } // namespace content |
| OLD | NEW |