Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: content/browser/dom_storage/dom_storage_context_impl.h

Issue 1953703004: Purge browser cache for dom storage in a smarter way (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dom_storage
Patch Set: Fix limit and description for UMA. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // all contained Areas, the shallow copies refer to the same refcounted Map, 58 // all contained Areas, the shallow copies refer to the same refcounted Map,
59 // and does a deep copy-on-write if needed. 59 // and does a deep copy-on-write if needed.
60 // 60 //
61 // Classes intended to be used by an embedder are DOMStorageContextImpl, 61 // Classes intended to be used by an embedder are DOMStorageContextImpl,
62 // DOMStorageHost, and DOMStorageSession. The other classes are for 62 // DOMStorageHost, and DOMStorageSession. The other classes are for
63 // internal consumption. 63 // internal consumption.
64 class CONTENT_EXPORT DOMStorageContextImpl 64 class CONTENT_EXPORT DOMStorageContextImpl
65 : public base::RefCountedThreadSafe<DOMStorageContextImpl>, 65 : public base::RefCountedThreadSafe<DOMStorageContextImpl>,
66 public base::trace_event::MemoryDumpProvider { 66 public base::trace_event::MemoryDumpProvider {
67 public: 67 public:
68 typedef std::map<int64_t, scoped_refptr<DOMStorageNamespace>>
69 StorageNamespaceMap;
70
68 // An interface for observing Local and Session Storage events on the 71 // An interface for observing Local and Session Storage events on the
69 // background thread. 72 // background thread.
70 class EventObserver { 73 class EventObserver {
71 public: 74 public:
72 // |old_value| may be null on initial insert. 75 // |old_value| may be null on initial insert.
73 virtual void OnDOMStorageItemSet( 76 virtual void OnDOMStorageItemSet(
74 const DOMStorageArea* area, 77 const DOMStorageArea* area,
75 const base::string16& key, 78 const base::string16& key,
76 const base::string16& new_value, 79 const base::string16& new_value,
77 const base::NullableString16& old_value, 80 const base::NullableString16& old_value,
78 const GURL& page_url) = 0; 81 const GURL& page_url) = 0;
79 virtual void OnDOMStorageItemRemoved( 82 virtual void OnDOMStorageItemRemoved(
80 const DOMStorageArea* area, 83 const DOMStorageArea* area,
81 const base::string16& key, 84 const base::string16& key,
82 const base::string16& old_value, 85 const base::string16& old_value,
83 const GURL& page_url) = 0; 86 const GURL& page_url) = 0;
84 virtual void OnDOMStorageAreaCleared( 87 virtual void OnDOMStorageAreaCleared(
85 const DOMStorageArea* area, 88 const DOMStorageArea* area,
86 const GURL& page_url) = 0; 89 const GURL& page_url) = 0;
87 90
88 protected: 91 protected:
89 virtual ~EventObserver() {} 92 virtual ~EventObserver() {}
90 }; 93 };
91 94
95 // Option for PurgeMemory.
96 enum PurgeOption {
97 // Determines if purging is required based on the usage and the platform.
98 PURGE_IF_NEEDED,
99
100 // Purge unopened areas only.
101 PURGE_UNOPENED,
102
103 // Purge aggressively, i.e. discard cache even for areas that have
104 // non-zero open count.
105 PURGE_AGGRESSIVE,
106 };
107
92 // |localstorage_directory| and |sessionstorage_directory| may be empty 108 // |localstorage_directory| and |sessionstorage_directory| may be empty
93 // for incognito browser contexts. 109 // for incognito browser contexts.
94 DOMStorageContextImpl(const base::FilePath& localstorage_directory, 110 DOMStorageContextImpl(const base::FilePath& localstorage_directory,
95 const base::FilePath& sessionstorage_directory, 111 const base::FilePath& sessionstorage_directory,
96 storage::SpecialStoragePolicy* special_storage_policy, 112 storage::SpecialStoragePolicy* special_storage_policy,
97 DOMStorageTaskRunner* task_runner); 113 DOMStorageTaskRunner* task_runner);
98 114
99 // Returns the directory path for localStorage, or an empty directory, if 115 // Returns the directory path for localStorage, or an empty directory, if
100 // there is no backing on disk. 116 // there is no backing on disk.
101 const base::FilePath& localstorage_directory() { 117 const base::FilePath& localstorage_directory() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 184
169 // Starts backing sessionStorage on disk. This function must be called right 185 // Starts backing sessionStorage on disk. This function must be called right
170 // after DOMStorageContextImpl is created, before it's used. 186 // after DOMStorageContextImpl is created, before it's used.
171 void SetSaveSessionStorageOnDisk(); 187 void SetSaveSessionStorageOnDisk();
172 188
173 // Deletes all namespaces which don't have an associated DOMStorageNamespace 189 // Deletes all namespaces which don't have an associated DOMStorageNamespace
174 // alive. This function is used for deleting possible leftover data after an 190 // alive. This function is used for deleting possible leftover data after an
175 // unclean exit. 191 // unclean exit.
176 void StartScavengingUnusedSessionStorage(); 192 void StartScavengingUnusedSessionStorage();
177 193
194 // Frees up memory when possible. Purges caches and schedules commits
195 // depending on the given |purge_option|.
196 void PurgeMemory(PurgeOption purge_option);
197
178 // base::trace_event::MemoryDumpProvider implementation. 198 // base::trace_event::MemoryDumpProvider implementation.
179 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 199 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
180 base::trace_event::ProcessMemoryDump* pmd) override; 200 base::trace_event::ProcessMemoryDump* pmd) override;
181 201
182 private: 202 private:
183 friend class DOMStorageContextImplTest; 203 friend class DOMStorageContextImplTest;
184 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, Basics); 204 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, Basics);
185 friend class base::RefCountedThreadSafe<DOMStorageContextImpl>; 205 friend class base::RefCountedThreadSafe<DOMStorageContextImpl>;
186 typedef std::map<int64_t, scoped_refptr<DOMStorageNamespace>>
187 StorageNamespaceMap;
188 206
189 ~DOMStorageContextImpl() override; 207 ~DOMStorageContextImpl() override;
190 208
191 void ClearSessionOnlyOrigins(); 209 void ClearSessionOnlyOrigins();
192 210
193 // For scavenging unused sessionStorages. 211 // For scavenging unused sessionStorages.
194 void FindUnusedNamespaces(); 212 void FindUnusedNamespaces();
195 void FindUnusedNamespacesInCommitSequence( 213 void FindUnusedNamespacesInCommitSequence(
196 const std::set<std::string>& namespace_ids_in_use, 214 const std::set<std::string>& namespace_ids_in_use,
197 const std::set<std::string>& protected_persistent_session_ids); 215 const std::set<std::string>& protected_persistent_session_ids);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 bool scavenging_started_; 249 bool scavenging_started_;
232 std::vector<std::string> deletable_persistent_namespace_ids_; 250 std::vector<std::string> deletable_persistent_namespace_ids_;
233 251
234 // Persistent namespace IDs to protect from gradual deletion (they will 252 // Persistent namespace IDs to protect from gradual deletion (they will
235 // be needed for session restore). 253 // be needed for session restore).
236 std::set<std::string> protected_persistent_session_ids_; 254 std::set<std::string> protected_persistent_session_ids_;
237 255
238 // Mapping between persistent namespace IDs and namespace IDs for 256 // Mapping between persistent namespace IDs and namespace IDs for
239 // sessionStorage. 257 // sessionStorage.
240 std::map<std::string, int64_t> persistent_namespace_id_to_namespace_id_; 258 std::map<std::string, int64_t> persistent_namespace_id_to_namespace_id_;
259
260 // For cleaning up unused databases more aggressively.
261 bool is_low_end_device_;
241 }; 262 };
242 263
243 } // namespace content 264 } // namespace content
244 265
245 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ 266 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_area.h ('k') | content/browser/dom_storage/dom_storage_context_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698