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

Side by Side Diff: webkit/dom_storage/dom_storage_context.cc

Issue 9817011: DomStorage data deletion and memory purging. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « webkit/dom_storage/dom_storage_context.h ('k') | webkit/dom_storage/dom_storage_database.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "webkit/dom_storage/dom_storage_context.h" 5 #include "webkit/dom_storage/dom_storage_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/location.h"
10 #include "base/time.h" 11 #include "base/time.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
13 #include "webkit/dom_storage/dom_storage_area.h" 12 #include "webkit/dom_storage/dom_storage_area.h"
14 #include "webkit/dom_storage/dom_storage_namespace.h" 13 #include "webkit/dom_storage/dom_storage_namespace.h"
15 #include "webkit/dom_storage/dom_storage_task_runner.h" 14 #include "webkit/dom_storage/dom_storage_task_runner.h"
16 #include "webkit/dom_storage/dom_storage_types.h" 15 #include "webkit/dom_storage/dom_storage_types.h"
17 #include "webkit/glue/webkit_glue.h"
18 #include "webkit/quota/special_storage_policy.h" 16 #include "webkit/quota/special_storage_policy.h"
19 17
20 using file_util::FileEnumerator; 18 using file_util::FileEnumerator;
21 19
22 namespace dom_storage { 20 namespace dom_storage {
23 21
24 DomStorageContext::UsageInfo::UsageInfo() {} 22 DomStorageContext::UsageInfo::UsageInfo() : data_size(0) {}
25 DomStorageContext::UsageInfo::~UsageInfo() {} 23 DomStorageContext::UsageInfo::~UsageInfo() {}
26 24
27 DomStorageContext::DomStorageContext( 25 DomStorageContext::DomStorageContext(
28 const FilePath& directory, 26 const FilePath& directory,
29 quota::SpecialStoragePolicy* special_storage_policy, 27 quota::SpecialStoragePolicy* special_storage_policy,
30 DomStorageTaskRunner* task_runner) 28 DomStorageTaskRunner* task_runner)
31 : directory_(directory), 29 : directory_(directory),
32 task_runner_(task_runner), 30 task_runner_(task_runner),
33 is_shutdown_(false), 31 is_shutdown_(false),
34 clear_local_state_(false), 32 clear_local_state_(false),
(...skipping 18 matching lines...) Expand all
53 DomStorageNamespace* local = 51 DomStorageNamespace* local =
54 new DomStorageNamespace(directory_, task_runner_); 52 new DomStorageNamespace(directory_, task_runner_);
55 namespaces_[kLocalStorageNamespaceId] = local; 53 namespaces_[kLocalStorageNamespaceId] = local;
56 return local; 54 return local;
57 } 55 }
58 return NULL; 56 return NULL;
59 } 57 }
60 return found->second; 58 return found->second;
61 } 59 }
62 60
63 void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos) { 61 void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos,
62 bool include_file_info) {
63 if (directory_.empty())
64 return;
64 FileEnumerator enumerator(directory_, false, FileEnumerator::FILES); 65 FileEnumerator enumerator(directory_, false, FileEnumerator::FILES);
65 for (FilePath path = enumerator.Next(); !path.empty(); 66 for (FilePath path = enumerator.Next(); !path.empty();
66 path = enumerator.Next()) { 67 path = enumerator.Next()) {
67 if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) { 68 if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) {
68 UsageInfo info; 69 UsageInfo info;
69 70 info.origin = DomStorageArea::OriginFromDatabaseFileName(path);
70 // Extract origin id from the path and construct a GURL. 71 if (include_file_info) {
71 WebKit::WebString origin_id = webkit_glue::FilePathToWebString( 72 FileEnumerator::FindInfo find_info;
72 path.BaseName().RemoveExtension()); 73 enumerator.GetFindInfo(&find_info);
73 info.origin = GURL(WebKit::WebSecurityOrigin:: 74 info.data_size = FileEnumerator::GetFilesize(find_info);
74 createFromDatabaseIdentifier(origin_id).toString()); 75 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info);
75 76 }
76 FileEnumerator::FindInfo find_info;
77 enumerator.GetFindInfo(&find_info);
78 info.data_size = FileEnumerator::GetFilesize(find_info);
79 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info);
80
81 infos->push_back(info); 77 infos->push_back(info);
82 } 78 }
83 } 79 }
84 } 80 }
85 81
86 void DomStorageContext::DeleteOrigin(const GURL& origin) { 82 void DomStorageContext::DeleteOrigin(const GURL& origin) {
87 // TODO(michaeln): write me 83 DCHECK(!is_shutdown_);
84 DomStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId);
85 local->DeleteOrigin(origin);
88 } 86 }
89 87
90 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { 88 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) {
91 // TODO(michaeln): write me 89 std::vector<UsageInfo> infos;
90 const bool kIncludeFileInfo = true;
91 GetUsageInfo(&infos, kIncludeFileInfo);
92 for (size_t i = 0; i < infos.size(); ++i) {
93 if (infos[i].last_modified > cutoff) {
94 if (!special_storage_policy_ ||
95 !special_storage_policy_->IsStorageProtected(infos[i].origin)) {
96 DeleteOrigin(infos[i].origin);
97 }
98 }
99 }
92 } 100 }
93 101
94 void DomStorageContext::PurgeMemory() { 102 void DomStorageContext::PurgeMemory() {
95 // We can only purge memory from the local storage namespace 103 // We can only purge memory from the local storage namespace
96 // which is backed by disk. 104 // which is backed by disk.
97 StorageNamespaceMap::iterator found = 105 StorageNamespaceMap::iterator found =
98 namespaces_.find(kLocalStorageNamespaceId); 106 namespaces_.find(kLocalStorageNamespaceId);
99 if (found != namespaces_.end()) 107 if (found != namespaces_.end())
100 found->second->PurgeMemory(); 108 found->second->PurgeMemory();
101 } 109 }
102 110
103 void DomStorageContext::Shutdown() { 111 void DomStorageContext::Shutdown() {
104 is_shutdown_ = true; 112 is_shutdown_ = true;
105 StorageNamespaceMap::const_iterator it = namespaces_.begin(); 113 StorageNamespaceMap::const_iterator it = namespaces_.begin();
106 for (; it != namespaces_.end(); ++it) 114 for (; it != namespaces_.end(); ++it)
107 it->second->Shutdown(); 115 it->second->Shutdown();
116
117 if (directory_.empty())
118 return;
119
120 // Respect the content policy settings about what to
121 // keep and what to discard.
122 if (save_session_state_)
123 return; // Keep everything.
124
125 bool has_session_only_origins =
126 special_storage_policy_.get() &&
127 special_storage_policy_->HasSessionOnlyOrigins();
128
129 if (clear_local_state_ || has_session_only_origins) {
130 // We may have to delete something. We continue on the
131 // commit sequence after area shutdown tasks have cycled
132 // thru that sequence (and closed their database files).
133 bool success = task_runner_->PostShutdownBlockingTask(
134 FROM_HERE,
135 DomStorageTaskRunner::COMMIT_SEQUENCE,
136 base::Bind(&DomStorageContext::ClearLocalStateInCommitSequence, this));
137 DCHECK(success);
138 }
108 } 139 }
109 140
110 void DomStorageContext::AddEventObserver(EventObserver* observer) { 141 void DomStorageContext::AddEventObserver(EventObserver* observer) {
111 event_observers_.AddObserver(observer); 142 event_observers_.AddObserver(observer);
112 } 143 }
113 144
114 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { 145 void DomStorageContext::RemoveEventObserver(EventObserver* observer) {
115 event_observers_.RemoveObserver(observer); 146 event_observers_.RemoveObserver(observer);
116 } 147 }
117 148
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return; 197 return;
167 DCHECK_NE(kLocalStorageNamespaceId, existing_id); 198 DCHECK_NE(kLocalStorageNamespaceId, existing_id);
168 DCHECK_NE(kLocalStorageNamespaceId, new_id); 199 DCHECK_NE(kLocalStorageNamespaceId, new_id);
169 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); 200 StorageNamespaceMap::iterator found = namespaces_.find(existing_id);
170 if (found != namespaces_.end()) 201 if (found != namespaces_.end())
171 namespaces_[new_id] = found->second->Clone(new_id); 202 namespaces_[new_id] = found->second->Clone(new_id);
172 else 203 else
173 CreateSessionNamespace(new_id); 204 CreateSessionNamespace(new_id);
174 } 205 }
175 206
207 void DomStorageContext::ClearLocalStateInCommitSequence() {
208 std::vector<UsageInfo> infos;
209 const bool kDontIncludeFileInfo = false;
210 GetUsageInfo(&infos, kDontIncludeFileInfo);
211 for (size_t i = 0; i < infos.size(); ++i) {
212 const GURL& origin = infos[i].origin;
213 if (special_storage_policy_ &&
214 special_storage_policy_->IsStorageProtected(origin))
215 continue;
216 if (!clear_local_state_ &&
217 !special_storage_policy_->IsStorageSessionOnly(origin))
218 continue;
219
220 const bool kNotRecursive = false;
221 FilePath database_file_path = directory_.Append(
222 DomStorageArea::DatabaseFileNameFromOrigin(origin));
223 file_util::Delete(database_file_path, kNotRecursive);
224 file_util::Delete(
225 DomStorageDatabase::GetJournalFilePath(database_file_path),
226 kNotRecursive);
227 }
228 }
229
176 } // namespace dom_storage 230 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/dom_storage/dom_storage_context.h ('k') | webkit/dom_storage/dom_storage_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698