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 #ifndef CONTENT_BROWSER_STORAGE_PARTITION_MAP_H_ | 5 #ifndef CONTENT_BROWSER_STORAGE_PARTITION_MAP_H_ |
6 #define CONTENT_BROWSER_STORAGE_PARTITION_MAP_H_ | 6 #define CONTENT_BROWSER_STORAGE_PARTITION_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... | |
27 virtual ~StoragePartitionImplMap(); | 27 virtual ~StoragePartitionImplMap(); |
28 | 28 |
29 // This map retains ownership of the returned StoragePartition objects. | 29 // This map retains ownership of the returned StoragePartition objects. |
30 StoragePartitionImpl* Get(const std::string& partition_domain, | 30 StoragePartitionImpl* Get(const std::string& partition_domain, |
31 const std::string& partition_name, | 31 const std::string& partition_name, |
32 bool in_memory); | 32 bool in_memory); |
33 | 33 |
34 void ForEach(const BrowserContext::StoragePartitionCallback& callback); | 34 void ForEach(const BrowserContext::StoragePartitionCallback& callback); |
35 | 35 |
36 private: | 36 private: |
37 typedef std::map<StoragePartitionImpl::StoragePartitionDescriptor, | 37 // Each StoragePartition is uniquely identified by which partition domain |
38 // it belongs to (such as an app or the browser itself), the user supplied | |
39 // partition name and the bit indicating whether it should be persisted on | |
40 // disk or not. This structure contains those elements and is used as | |
41 // uniqueness key to lookup StoragePartition objects in the global map. | |
42 // | |
43 // TODO(nasko): It is equivalent, though not identical to the same structure | |
44 // that lives in chrome profiles. The difference is that this one has | |
45 // partition_domain and partition_name separate, while the latter one has | |
46 // the path produced by combining the two pieces together. | |
47 // The fix for http://crbug.com/159193 will remove the chrome version. | |
48 struct StoragePartitionDescriptor { | |
nasko
2012/11/08 05:03:54
Just FYI, I've renamed the Descriptor to Config in
awong
2012/11/09 02:51:22
Merged.
| |
49 const std::string partition_domain; | |
50 const std::string partition_name; | |
51 const bool in_memory; | |
52 | |
53 StoragePartitionDescriptor(const std::string& domain, | |
54 const std::string& partition, | |
55 const bool& in_memory_only) | |
56 : partition_domain(domain), | |
57 partition_name(partition), | |
58 in_memory(in_memory_only) {} | |
59 }; | |
60 | |
61 // Functor for operator <. | |
62 struct StoragePartitionDescriptorLess { | |
63 bool operator()(const StoragePartitionDescriptor& lhs, | |
64 const StoragePartitionDescriptor& rhs) const { | |
65 if (lhs.partition_domain != rhs.partition_domain) | |
66 return lhs.partition_domain < rhs.partition_domain; | |
67 else if (lhs.partition_name != rhs.partition_name) | |
68 return lhs.partition_name < rhs.partition_name; | |
69 else if (lhs.in_memory != rhs.in_memory) | |
70 return lhs.in_memory < rhs.in_memory; | |
71 else | |
72 return false; | |
73 } | |
74 }; | |
75 | |
76 | |
77 typedef std::map<StoragePartitionDescriptor, | |
38 StoragePartitionImpl*, | 78 StoragePartitionImpl*, |
39 StoragePartitionImpl::StoragePartitionDescriptorLess> | 79 StoragePartitionDescriptorLess> |
40 PartitionsMap; | 80 PartitionsMap; |
41 | 81 |
82 // Returns the relative path from the profile's base directory, to the | |
83 // directory that holds all the state for storage contexts in | |
84 // |partition_descriptor|. | |
85 static FilePath GetStoragePartitionPath( | |
86 const StoragePartitionDescriptor& partition_descriptor); | |
87 | |
42 // This must always be called *after* |partition| has been added to the | 88 // This must always be called *after* |partition| has been added to the |
43 // partitions_. | 89 // partitions_. |
44 // | 90 // |
45 // TODO(ajwong): Is there a way to make it so that Get()'s implementation | 91 // TODO(ajwong): Is there a way to make it so that Get()'s implementation |
46 // doesn't need to be aware of this ordering? Revisit when refactoring | 92 // doesn't need to be aware of this ordering? Revisit when refactoring |
47 // ResourceContext and AppCache to respect storage partitions. | 93 // ResourceContext and AppCache to respect storage partitions. |
48 void PostCreateInitialization(StoragePartitionImpl* partition); | 94 void PostCreateInitialization(StoragePartitionImpl* partition); |
49 | 95 |
50 BrowserContext* browser_context_; // Not Owned. | 96 BrowserContext* browser_context_; // Not Owned. |
51 PartitionsMap partitions_; | 97 PartitionsMap partitions_; |
52 | 98 |
53 // Set to true when the ResourceContext for the associated |browser_context_| | 99 // Set to true when the ResourceContext for the associated |browser_context_| |
54 // is initialized. Can never return to false. | 100 // is initialized. Can never return to false. |
55 bool resource_context_initialized_; | 101 bool resource_context_initialized_; |
56 }; | 102 }; |
57 | 103 |
58 } // namespace content | 104 } // namespace content |
59 | 105 |
60 #endif // CONTENT_BROWSER_STORAGE_PARTITION_MAP_H_ | 106 #endif // CONTENT_BROWSER_STORAGE_PARTITION_MAP_H_ |
OLD | NEW |