| 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_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ |
| 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ | 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/atomic_sequence_num.h" | 12 #include "base/atomic_sequence_num.h" |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "content/browser/dom_storage/dom_storage_namespace.h" | |
| 20 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 21 #include "content/public/browser/session_storage_namespace.h" | |
| 22 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 23 | 21 |
| 24 namespace base { | 22 namespace base { |
| 25 class FilePath; | 23 class FilePath; |
| 26 class NullableString16; | 24 class NullableString16; |
| 27 class Time; | 25 class Time; |
| 28 } | 26 } |
| 29 | 27 |
| 30 namespace storage { | 28 namespace storage { |
| 31 class SpecialStoragePolicy; | 29 class SpecialStoragePolicy; |
| 32 } | 30 } |
| 33 | 31 |
| 34 namespace content { | 32 namespace content { |
| 35 | 33 |
| 36 class DOMStorageArea; | 34 class DOMStorageArea; |
| 35 class DOMStorageNamespace; |
| 37 class DOMStorageSession; | 36 class DOMStorageSession; |
| 38 class DOMStorageTaskRunner; | 37 class DOMStorageTaskRunner; |
| 39 class SessionStorageDatabase; | 38 class SessionStorageDatabase; |
| 40 struct LocalStorageUsageInfo; | 39 struct LocalStorageUsageInfo; |
| 41 struct SessionStorageUsageInfo; | 40 struct SessionStorageUsageInfo; |
| 42 | 41 |
| 43 // The Context is the root of an object containment hierachy for | 42 // The Context is the root of an object containment hierachy for |
| 44 // Namespaces and Areas related to the owning profile. | 43 // Namespaces and Areas related to the owning profile. |
| 45 // One instance is allocated in the main process for each profile, | 44 // One instance is allocated in the main process for each profile, |
| 46 // instance methods should be called serially in the background as | 45 // instance methods should be called serially in the background as |
| (...skipping 27 matching lines...) Expand all Loading... |
| 74 const base::NullableString16& old_value, | 73 const base::NullableString16& old_value, |
| 75 const GURL& page_url) = 0; | 74 const GURL& page_url) = 0; |
| 76 virtual void OnDOMStorageItemRemoved( | 75 virtual void OnDOMStorageItemRemoved( |
| 77 const DOMStorageArea* area, | 76 const DOMStorageArea* area, |
| 78 const base::string16& key, | 77 const base::string16& key, |
| 79 const base::string16& old_value, | 78 const base::string16& old_value, |
| 80 const GURL& page_url) = 0; | 79 const GURL& page_url) = 0; |
| 81 virtual void OnDOMStorageAreaCleared( | 80 virtual void OnDOMStorageAreaCleared( |
| 82 const DOMStorageArea* area, | 81 const DOMStorageArea* area, |
| 83 const GURL& page_url) = 0; | 82 const GURL& page_url) = 0; |
| 84 // Indicates that cached values of the DOM Storage provided must be | |
| 85 // cleared and retrieved again. | |
| 86 virtual void OnDOMSessionStorageReset(int64 namespace_id) = 0; | |
| 87 | 83 |
| 88 protected: | 84 protected: |
| 89 virtual ~EventObserver() {} | 85 virtual ~EventObserver() {} |
| 90 }; | 86 }; |
| 91 | 87 |
| 92 // |localstorage_directory| and |sessionstorage_directory| may be empty | 88 // |localstorage_directory| and |sessionstorage_directory| may be empty |
| 93 // for incognito browser contexts. | 89 // for incognito browser contexts. |
| 94 DOMStorageContextImpl(const base::FilePath& localstorage_directory, | 90 DOMStorageContextImpl(const base::FilePath& localstorage_directory, |
| 95 const base::FilePath& sessionstorage_directory, | 91 const base::FilePath& sessionstorage_directory, |
| 96 storage::SpecialStoragePolicy* special_storage_policy, | 92 storage::SpecialStoragePolicy* special_storage_policy, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // Called when the owning BrowserContext is ending. | 124 // Called when the owning BrowserContext is ending. |
| 129 // Schedules the commit of any unsaved changes and will delete | 125 // Schedules the commit of any unsaved changes and will delete |
| 130 // and keep data on disk per the content settings and special storage | 126 // and keep data on disk per the content settings and special storage |
| 131 // policies. Contained areas and namespaces will stop functioning after | 127 // policies. Contained areas and namespaces will stop functioning after |
| 132 // this method has been called. | 128 // this method has been called. |
| 133 void Shutdown(); | 129 void Shutdown(); |
| 134 | 130 |
| 135 // Methods to add, remove, and notify EventObservers. | 131 // Methods to add, remove, and notify EventObservers. |
| 136 void AddEventObserver(EventObserver* observer); | 132 void AddEventObserver(EventObserver* observer); |
| 137 void RemoveEventObserver(EventObserver* observer); | 133 void RemoveEventObserver(EventObserver* observer); |
| 138 | |
| 139 void NotifyItemSet( | 134 void NotifyItemSet( |
| 140 const DOMStorageArea* area, | 135 const DOMStorageArea* area, |
| 141 const base::string16& key, | 136 const base::string16& key, |
| 142 const base::string16& new_value, | 137 const base::string16& new_value, |
| 143 const base::NullableString16& old_value, | 138 const base::NullableString16& old_value, |
| 144 const GURL& page_url); | 139 const GURL& page_url); |
| 145 void NotifyItemRemoved( | 140 void NotifyItemRemoved( |
| 146 const DOMStorageArea* area, | 141 const DOMStorageArea* area, |
| 147 const base::string16& key, | 142 const base::string16& key, |
| 148 const base::string16& old_value, | 143 const base::string16& old_value, |
| 149 const GURL& page_url); | 144 const GURL& page_url); |
| 150 void NotifyAreaCleared( | 145 void NotifyAreaCleared( |
| 151 const DOMStorageArea* area, | 146 const DOMStorageArea* area, |
| 152 const GURL& page_url); | 147 const GURL& page_url); |
| 153 void NotifyAliasSessionMerged( | |
| 154 int64 namespace_id, | |
| 155 DOMStorageNamespace* old_alias_master_namespace); | |
| 156 | 148 |
| 157 // May be called on any thread. | 149 // May be called on any thread. |
| 158 int64 AllocateSessionId() { | 150 int64 AllocateSessionId() { |
| 159 return session_id_sequence_.GetNext(); | 151 return session_id_sequence_.GetNext(); |
| 160 } | 152 } |
| 161 | 153 |
| 162 std::string AllocatePersistentSessionId(); | 154 std::string AllocatePersistentSessionId(); |
| 163 | 155 |
| 164 // Must be called on the background thread. | 156 // Must be called on the background thread. |
| 165 void CreateSessionNamespace(int64 namespace_id, | 157 void CreateSessionNamespace(int64 namespace_id, |
| 166 const std::string& persistent_namespace_id); | 158 const std::string& persistent_namespace_id); |
| 167 void DeleteSessionNamespace(int64 namespace_id, bool should_persist_data); | 159 void DeleteSessionNamespace(int64 namespace_id, bool should_persist_data); |
| 168 void CloneSessionNamespace(int64 existing_id, int64 new_id, | 160 void CloneSessionNamespace(int64 existing_id, int64 new_id, |
| 169 const std::string& new_persistent_id); | 161 const std::string& new_persistent_id); |
| 170 void CreateAliasSessionNamespace(int64 existing_id, int64 new_id, | |
| 171 const std::string& persistent_id); | |
| 172 | 162 |
| 173 // Starts backing sessionStorage on disk. This function must be called right | 163 // Starts backing sessionStorage on disk. This function must be called right |
| 174 // after DOMStorageContextImpl is created, before it's used. | 164 // after DOMStorageContextImpl is created, before it's used. |
| 175 void SetSaveSessionStorageOnDisk(); | 165 void SetSaveSessionStorageOnDisk(); |
| 176 | 166 |
| 177 // Deletes all namespaces which don't have an associated DOMStorageNamespace | 167 // Deletes all namespaces which don't have an associated DOMStorageNamespace |
| 178 // alive. This function is used for deleting possible leftover data after an | 168 // alive. This function is used for deleting possible leftover data after an |
| 179 // unclean exit. | 169 // unclean exit. |
| 180 void StartScavengingUnusedSessionStorage(); | 170 void StartScavengingUnusedSessionStorage(); |
| 181 | 171 |
| 182 void AddTransactionLogProcessId(int64 namespace_id, int process_id); | |
| 183 void RemoveTransactionLogProcessId(int64 namespace_id, int process_id); | |
| 184 | |
| 185 SessionStorageNamespace::MergeResult MergeSessionStorage( | |
| 186 int64 namespace1_id, bool actually_merge, int process_id, | |
| 187 int64 namespace2_id); | |
| 188 | |
| 189 private: | 172 private: |
| 190 friend class DOMStorageContextImplTest; | 173 friend class DOMStorageContextImplTest; |
| 191 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, Basics); | 174 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, Basics); |
| 192 friend class base::RefCountedThreadSafe<DOMStorageContextImpl>; | 175 friend class base::RefCountedThreadSafe<DOMStorageContextImpl>; |
| 193 typedef std::map<int64, scoped_refptr<DOMStorageNamespace> > | 176 typedef std::map<int64, scoped_refptr<DOMStorageNamespace> > |
| 194 StorageNamespaceMap; | 177 StorageNamespaceMap; |
| 195 | 178 |
| 196 virtual ~DOMStorageContextImpl(); | 179 ~DOMStorageContextImpl(); |
| 197 | 180 |
| 198 void ClearSessionOnlyOrigins(); | 181 void ClearSessionOnlyOrigins(); |
| 199 | 182 |
| 200 void MaybeShutdownSessionNamespace(DOMStorageNamespace* ns); | |
| 201 | |
| 202 // For scavenging unused sessionStorages. | 183 // For scavenging unused sessionStorages. |
| 203 void FindUnusedNamespaces(); | 184 void FindUnusedNamespaces(); |
| 204 void FindUnusedNamespacesInCommitSequence( | 185 void FindUnusedNamespacesInCommitSequence( |
| 205 const std::set<std::string>& namespace_ids_in_use, | 186 const std::set<std::string>& namespace_ids_in_use, |
| 206 const std::set<std::string>& protected_persistent_session_ids); | 187 const std::set<std::string>& protected_persistent_session_ids); |
| 207 void DeleteNextUnusedNamespace(); | 188 void DeleteNextUnusedNamespace(); |
| 208 void DeleteNextUnusedNamespaceInCommitSequence(); | 189 void DeleteNextUnusedNamespaceInCommitSequence(); |
| 209 | 190 |
| 210 // Collection of namespaces keyed by id. | 191 // Collection of namespaces keyed by id. |
| 211 StorageNamespaceMap namespaces_; | 192 StorageNamespaceMap namespaces_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 242 std::set<std::string> protected_persistent_session_ids_; | 223 std::set<std::string> protected_persistent_session_ids_; |
| 243 | 224 |
| 244 // Mapping between persistent namespace IDs and namespace IDs for | 225 // Mapping between persistent namespace IDs and namespace IDs for |
| 245 // sessionStorage. | 226 // sessionStorage. |
| 246 std::map<std::string, int64> persistent_namespace_id_to_namespace_id_; | 227 std::map<std::string, int64> persistent_namespace_id_to_namespace_id_; |
| 247 }; | 228 }; |
| 248 | 229 |
| 249 } // namespace content | 230 } // namespace content |
| 250 | 231 |
| 251 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ | 232 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ |
| OLD | NEW |