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