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