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" |
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_impl.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 StoragePartitionImplMap::StoragePartitionImplMap( | 21 StoragePartitionImplMap::StoragePartitionImplMap( |
22 BrowserContext* browser_context) | 22 BrowserContext* browser_context) |
23 : browser_context_(browser_context) { | 23 : browser_context_(browser_context) { |
24 } | 24 } |
25 | 25 |
26 StoragePartitionImplMap::~StoragePartitionImplMap() { | 26 StoragePartitionImplMap::~StoragePartitionImplMap() { |
27 STLDeleteContainerPairSecondPointers(partitions_.begin(), | |
28 partitions_.end()); | |
29 } | 27 } |
30 | 28 |
31 StoragePartitionImpl* StoragePartitionImplMap::Get( | 29 StoragePartitionImpl* StoragePartitionImplMap::Get( |
32 const std::string& partition_id) { | 30 const std::string& partition_id) { |
33 // Find the previously created partition if it's available. | 31 // Find the previously created partition if it's available. |
34 std::map<std::string, StoragePartitionImpl*>::const_iterator it = | 32 Map::const_iterator it = partitions_.find(partition_id); |
35 partitions_.find(partition_id); | |
36 if (it != partitions_.end()) | 33 if (it != partitions_.end()) |
37 return it->second; | 34 return it->second; |
38 | 35 |
39 // There was no previous partition, so let's make a new one. | 36 // There was no previous partition, so let's make a new one. |
40 FilePath partition_path = browser_context_->GetPath(); | 37 FilePath partition_path = browser_context_->GetPath(); |
41 if (!partition_id.empty()) { | 38 if (!partition_id.empty()) { |
42 // TODO(ajwong): This should check the path is valid? | 39 // TODO(ajwong): This should check the path is valid? |
43 CHECK(IsStringASCII(partition_id)); | 40 CHECK(IsStringASCII(partition_id)); |
44 partition_path = partition_path.Append(kStoragePartitionDirname) | 41 partition_path = partition_path.Append(kStoragePartitionDirname) |
45 .AppendASCII(partition_id); | 42 .AppendASCII(partition_id); |
(...skipping 10 matching lines...) Expand all Loading... | |
56 // based on the renderer_id. | 53 // based on the renderer_id. |
57 if (partition_id.empty()) { | 54 if (partition_id.empty()) { |
58 InitializeResourceContext(browser_context_); | 55 InitializeResourceContext(browser_context_); |
59 } | 56 } |
60 | 57 |
61 return storage_partition; | 58 return storage_partition; |
62 } | 59 } |
63 | 60 |
64 void StoragePartitionImplMap::ForEach( | 61 void StoragePartitionImplMap::ForEach( |
65 const BrowserContext::StoragePartitionCallback& callback) { | 62 const BrowserContext::StoragePartitionCallback& callback) { |
66 for (std::map<std::string, StoragePartitionImpl*>::const_iterator it = | 63 for (Map::const_iterator it = partitions_.begin(); |
67 partitions_.begin(); | 64 it != partitions_.end(); ++it) { |
68 it != partitions_.end(); | |
69 ++it) { | |
70 callback.Run(it->first, it->second); | 65 callback.Run(it->first, it->second); |
71 } | 66 } |
72 } | 67 } |
73 | 68 |
74 void StoragePartitionImplMap::PostCreateInitialization( | 69 void StoragePartitionImplMap::PostCreateInitialization( |
75 StoragePartitionImpl* partition, | 70 StoragePartitionImpl* partition, |
76 const FilePath& partition_path) { | 71 const FilePath& partition_path) { |
77 // Check first to avoid memory leak in unittests. | 72 // Check first to avoid memory leak in unittests. |
78 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 73 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
79 BrowserThread::PostTask( | 74 BrowserThread::PostTask( |
80 BrowserThread::IO, FROM_HERE, | 75 BrowserThread::IO, FROM_HERE, |
81 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 76 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
82 partition->GetAppCacheService(), | 77 static_cast<ChromeAppCacheService*>( |
awong
2012/09/06 22:29:27
If we keep the covariant return, we don't need thi
| |
78 partition->GetAppCacheService()), | |
83 browser_context_->IsOffTheRecord() ? FilePath() : | 79 browser_context_->IsOffTheRecord() ? FilePath() : |
84 partition_path.Append(kAppCacheDirname), | 80 partition_path.Append(kAppCacheDirname), |
85 // TODO(michaeln): This is not right, appcache will be | 81 // TODO(michaeln): This is not right, appcache will be |
86 // using the cookies and cache of a the default | 82 // using the cookies and cache of a the default |
87 // partition when populating the cache. | 83 // partition when populating the cache. |
88 // http://crbug.com/85121 | 84 // http://crbug.com/85121 |
89 browser_context_->GetResourceContext(), | 85 browser_context_->GetResourceContext(), |
90 make_scoped_refptr( | 86 make_scoped_refptr( |
91 browser_context_->GetSpecialStoragePolicy()))); | 87 browser_context_->GetSpecialStoragePolicy()))); |
92 } | 88 } |
93 } | 89 } |
94 | 90 |
95 } // namespace content | 91 } // namespace content |
OLD | NEW |