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_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" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "content/browser/appcache/chrome_appcache_service.h" | 12 #include "content/browser/appcache/chrome_appcache_service.h" |
13 #include "content/browser/resource_context_impl.h" | 13 #include "content/browser/resource_context_impl.h" |
14 #include "content/browser/storage_partition.h" | 14 #include "content/browser/storage_partition_impl.h" |
15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/common/content_constants.h" | 17 #include "content/public/common/content_constants.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 // Dirname for storing persistent data for renderers with isolated storage. | 21 // Dirname for storing persistent data for renderers with isolated storage. |
22 const FilePath::CharType kStoragePartitionDirName[] = | 22 const FilePath::CharType kStoragePartitionDirName[] = |
23 FILE_PATH_LITERAL("Storage Partitions"); | 23 FILE_PATH_LITERAL("Storage Partitions"); |
24 | 24 |
25 StoragePartitionMap::StoragePartitionMap( | 25 StoragePartitionImplMap::StoragePartitionImplMap( |
26 BrowserContext* browser_context) | 26 BrowserContext* browser_context) |
27 : browser_context_(browser_context) { | 27 : browser_context_(browser_context) { |
28 } | 28 } |
29 | 29 |
30 StoragePartitionMap::~StoragePartitionMap() { | 30 StoragePartitionImplMap::~StoragePartitionImplMap() { |
31 STLDeleteContainerPairSecondPointers(partitions_.begin(), | 31 STLDeleteContainerPairSecondPointers(partitions_.begin(), |
32 partitions_.end()); | 32 partitions_.end()); |
33 } | 33 } |
34 | 34 |
35 StoragePartition* StoragePartitionMap::Get(const std::string& partition_id) { | 35 StoragePartitionImpl* StoragePartitionImplMap::Get( |
| 36 const std::string& partition_id) { |
36 // Find the previously created partition if it's available. | 37 // Find the previously created partition if it's available. |
37 std::map<std::string, StoragePartition*>::const_iterator it = | 38 std::map<std::string, StoragePartitionImpl*>::const_iterator it = |
38 partitions_.find(partition_id); | 39 partitions_.find(partition_id); |
39 if (it != partitions_.end()) | 40 if (it != partitions_.end()) |
40 return it->second; | 41 return it->second; |
41 | 42 |
42 // There was no previous partition, so let's make a new one. | 43 // There was no previous partition, so let's make a new one. |
43 FilePath partition_path = browser_context_->GetPath(); | 44 FilePath partition_path = browser_context_->GetPath(); |
44 if (!partition_id.empty()) { | 45 if (!partition_id.empty()) { |
45 // TODO(ajwong): This should check the pth is valid? | 46 // TODO(ajwong): This should check the path is valid? |
46 CHECK(IsStringASCII(partition_id)); | 47 CHECK(IsStringASCII(partition_id)); |
47 partition_path = partition_path.Append(kStoragePartitionDirName) | 48 partition_path = partition_path.Append(kStoragePartitionDirName) |
48 .AppendASCII(partition_id); | 49 .AppendASCII(partition_id); |
49 } | 50 } |
50 | 51 |
51 StoragePartition* storage_partition = | 52 StoragePartitionImpl* storage_partition = |
52 StoragePartition::Create(browser_context_, partition_path); | 53 StoragePartitionImpl::Create(browser_context_, partition_path); |
53 partitions_[partition_id] = storage_partition; | 54 partitions_[partition_id] = storage_partition; |
54 | 55 |
55 PostCreateInitialization(storage_partition, partition_path); | 56 PostCreateInitialization(storage_partition, partition_path); |
56 | 57 |
57 // TODO(ajwong): We need to remove this conditional by making | 58 // TODO(ajwong): We need to remove this conditional by making |
58 // InitializeResourceContext() understand having different partition data | 59 // InitializeResourceContext() understand having different partition data |
59 // based on the renderer_id. | 60 // based on the renderer_id. |
60 if (partition_id.empty()) { | 61 if (partition_id.empty()) { |
61 InitializeResourceContext(browser_context_); | 62 InitializeResourceContext(browser_context_); |
62 } | 63 } |
63 | 64 |
64 return storage_partition; | 65 return storage_partition; |
65 } | 66 } |
66 | 67 |
67 void StoragePartitionMap::ForEach( | 68 void StoragePartitionImplMap::ForEach( |
68 const base::Callback<void(StoragePartition*)>& callback) { | 69 const BrowserContext::StoragePartitionCallback& callback) { |
69 for (std::map<std::string, StoragePartition*>::const_iterator it = | 70 for (std::map<std::string, StoragePartitionImpl*>::const_iterator it = |
70 partitions_.begin(); | 71 partitions_.begin(); |
71 it != partitions_.end(); | 72 it != partitions_.end(); |
72 ++it) { | 73 ++it) { |
73 callback.Run(it->second); | 74 callback.Run(it->first, it->second); |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
77 void StoragePartitionMap::PostCreateInitialization( | 78 void StoragePartitionImplMap::PostCreateInitialization( |
78 StoragePartition* partition, | 79 StoragePartitionImpl* partition, |
79 const FilePath& partition_path) { | 80 const FilePath& partition_path) { |
80 // Check first to avoid memory leak in unittests. | 81 // Check first to avoid memory leak in unittests. |
81 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 82 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
82 BrowserThread::PostTask( | 83 BrowserThread::PostTask( |
83 BrowserThread::IO, FROM_HERE, | 84 BrowserThread::IO, FROM_HERE, |
84 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 85 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
85 partition->appcache_service(), | 86 partition->GetAppCacheService(), |
86 browser_context_->IsOffTheRecord() ? FilePath() : | 87 browser_context_->IsOffTheRecord() ? FilePath() : |
87 partition_path.Append(kAppCacheDirname), | 88 partition_path.Append(kAppCacheDirname), |
88 browser_context_->GetResourceContext(), | 89 browser_context_->GetResourceContext(), |
89 make_scoped_refptr( | 90 make_scoped_refptr( |
90 browser_context_->GetSpecialStoragePolicy()))); | 91 browser_context_->GetSpecialStoragePolicy()))); |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 } // namespace content | 95 } // namespace content |
OLD | NEW |