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 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
15 #include "content/browser/storage_partition_impl.h" | 15 #include "content/browser/storage_partition_impl.h" |
16 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class FilePath; | 19 class FilePath; |
20 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
21 } // namespace base | 21 } // namespace base |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 class BrowserContext; | 25 class BrowserContext; |
26 | 26 |
27 // A std::string to StoragePartition map for use with SupportsUserData APIs. | 27 // A std::string to StoragePartition map for use with SupportsUserData APIs. |
28 class StoragePartitionImplMap : public base::SupportsUserData::Data { | 28 class StoragePartitionImplMap : public base::SupportsUserData::Data { |
29 public: | 29 public: |
30 explicit StoragePartitionImplMap(BrowserContext* browser_context); | 30 CONTENT_EXPORT explicit StoragePartitionImplMap( |
sky
2014/06/06 16:10:06
To my knowledge we generally don't export individu
tzik
2014/06/06 17:25:20
Just following StoragePartitionImpl does. I have n
| |
31 BrowserContext* browser_context); | |
31 | 32 |
32 virtual ~StoragePartitionImplMap(); | 33 CONTENT_EXPORT virtual ~StoragePartitionImplMap(); |
33 | 34 |
34 // This map retains ownership of the returned StoragePartition objects. | 35 // This map retains ownership of the returned StoragePartition objects. |
35 StoragePartitionImpl* Get(const std::string& partition_domain, | 36 StoragePartitionImpl* Get(const std::string& partition_domain, |
36 const std::string& partition_name, | 37 const std::string& partition_name, |
37 bool in_memory); | 38 bool in_memory); |
38 | 39 |
39 // Starts an asynchronous best-effort attempt to delete all on-disk storage | 40 // Starts an asynchronous best-effort attempt to delete all on-disk storage |
40 // related to |site|, avoiding any directories that are known to be in use. | 41 // related to |site|, avoiding any directories that are known to be in use. |
41 // | 42 // |
42 // |on_gc_required| is called if the AsyncObliterate() call was unable to | 43 // |on_gc_required| is called if the AsyncObliterate() call was unable to |
43 // fully clean the on-disk storage requiring a call to GarbageCollect() on | 44 // fully clean the on-disk storage requiring a call to GarbageCollect() on |
44 // the next browser start. | 45 // the next browser start. |
45 void AsyncObliterate(const GURL& site, const base::Closure& on_gc_required); | 46 void AsyncObliterate(const GURL& site, const base::Closure& on_gc_required); |
46 | 47 |
47 // Examines the on-disk storage and removes any entires that are not listed | 48 // Examines the on-disk storage and removes any entires that are not listed |
48 // in the |active_paths|, or in use by current entries in the storage | 49 // in the |active_paths|, or in use by current entries in the storage |
49 // partition. | 50 // partition. |
50 // | 51 // |
51 // The |done| closure is executed on the calling thread when garbage | 52 // The |done| closure is executed on the calling thread when garbage |
52 // collection is complete. | 53 // collection is complete. |
53 void GarbageCollect(scoped_ptr<base::hash_set<base::FilePath> > active_paths, | 54 CONTENT_EXPORT void GarbageCollect( |
54 const base::Closure& done); | 55 scoped_ptr<base::hash_set<base::FilePath> > active_paths, |
56 const base::Closure& done); | |
55 | 57 |
56 void ForEach(const BrowserContext::StoragePartitionCallback& callback); | 58 void ForEach(const BrowserContext::StoragePartitionCallback& callback); |
57 | 59 |
58 private: | 60 private: |
59 FRIEND_TEST_ALL_PREFIXES(StoragePartitionConfigTest, OperatorLess); | 61 FRIEND_TEST_ALL_PREFIXES(StoragePartitionConfigTest, OperatorLess); |
62 FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplMapTest, GarbageCollect); | |
60 | 63 |
61 // Each StoragePartition is uniquely identified by which partition domain | 64 // Each StoragePartition is uniquely identified by which partition domain |
62 // it belongs to (such as an app or the browser itself), the user supplied | 65 // it belongs to (such as an app or the browser itself), the user supplied |
63 // partition name and the bit indicating whether it should be persisted on | 66 // partition name and the bit indicating whether it should be persisted on |
64 // disk or not. This structure contains those elements and is used as | 67 // disk or not. This structure contains those elements and is used as |
65 // uniqueness key to lookup StoragePartition objects in the global map. | 68 // uniqueness key to lookup StoragePartition objects in the global map. |
66 // | 69 // |
67 // TODO(nasko): It is equivalent, though not identical to the same structure | 70 // TODO(nasko): It is equivalent, though not identical to the same structure |
68 // that lives in chrome profiles. The difference is that this one has | 71 // that lives in chrome profiles. The difference is that this one has |
69 // partition_domain and partition_name separate, while the latter one has | 72 // partition_domain and partition_name separate, while the latter one has |
(...skipping 28 matching lines...) Expand all Loading... | |
98 }; | 101 }; |
99 | 102 |
100 typedef std::map<StoragePartitionConfig, | 103 typedef std::map<StoragePartitionConfig, |
101 StoragePartitionImpl*, | 104 StoragePartitionImpl*, |
102 StoragePartitionConfigLess> | 105 StoragePartitionConfigLess> |
103 PartitionMap; | 106 PartitionMap; |
104 | 107 |
105 // Returns the relative path from the profile's base directory, to the | 108 // Returns the relative path from the profile's base directory, to the |
106 // directory that holds all the state for storage contexts in the given | 109 // directory that holds all the state for storage contexts in the given |
107 // |partition_domain| and |partition_name|. | 110 // |partition_domain| and |partition_name|. |
108 static base::FilePath GetStoragePartitionPath( | 111 CONTENT_EXPORT static base::FilePath GetStoragePartitionPath( |
109 const std::string& partition_domain, | 112 const std::string& partition_domain, |
110 const std::string& partition_name); | 113 const std::string& partition_name); |
111 | 114 |
112 // This must always be called *after* |partition| has been added to the | 115 // This must always be called *after* |partition| has been added to the |
113 // partitions_. | 116 // partitions_. |
114 // | 117 // |
115 // TODO(ajwong): Is there a way to make it so that Get()'s implementation | 118 // TODO(ajwong): Is there a way to make it so that Get()'s implementation |
116 // doesn't need to be aware of this ordering? Revisit when refactoring | 119 // doesn't need to be aware of this ordering? Revisit when refactoring |
117 // ResourceContext and AppCache to respect storage partitions. | 120 // ResourceContext and AppCache to respect storage partitions. |
118 void PostCreateInitialization(StoragePartitionImpl* partition, | 121 void PostCreateInitialization(StoragePartitionImpl* partition, |
119 bool in_memory); | 122 bool in_memory); |
120 | 123 |
121 BrowserContext* browser_context_; // Not Owned. | 124 BrowserContext* browser_context_; // Not Owned. |
122 scoped_refptr<base::SequencedTaskRunner> file_access_runner_; | 125 scoped_refptr<base::SequencedTaskRunner> file_access_runner_; |
123 PartitionMap partitions_; | 126 PartitionMap partitions_; |
124 | 127 |
125 // Set to true when the ResourceContext for the associated |browser_context_| | 128 // Set to true when the ResourceContext for the associated |browser_context_| |
126 // is initialized. Can never return to false. | 129 // is initialized. Can never return to false. |
127 bool resource_context_initialized_; | 130 bool resource_context_initialized_; |
128 }; | 131 }; |
129 | 132 |
130 } // namespace content | 133 } // namespace content |
131 | 134 |
132 #endif // CONTENT_BROWSER_STORAGE_PARTITION_MAP_H_ | 135 #endif // CONTENT_BROWSER_STORAGE_PARTITION_MAP_H_ |
OLD | NEW |