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

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)
michaeln 2012/03/22 05:34:40 ooops... i have to consult policy->IsStorageProtec
michaeln 2012/03/22 19:00:57 Done.
94 DeleteOrigin(infos[i].origin);
95 }
92 } 96 }
93 97
94 void DomStorageContext::PurgeMemory() { 98 void DomStorageContext::PurgeMemory() {
95 // We can only purge memory from the local storage namespace 99 // We can only purge memory from the local storage namespace
96 // which is backed by disk. 100 // which is backed by disk.
97 StorageNamespaceMap::iterator found = 101 StorageNamespaceMap::iterator found =
98 namespaces_.find(kLocalStorageNamespaceId); 102 namespaces_.find(kLocalStorageNamespaceId);
99 if (found != namespaces_.end()) 103 if (found != namespaces_.end())
100 found->second->PurgeMemory(); 104 found->second->PurgeMemory();
101 } 105 }
102 106
103 void DomStorageContext::Shutdown() { 107 void DomStorageContext::Shutdown() {
104 is_shutdown_ = true; 108 is_shutdown_ = true;
105 StorageNamespaceMap::const_iterator it = namespaces_.begin(); 109 StorageNamespaceMap::const_iterator it = namespaces_.begin();
106 for (; it != namespaces_.end(); ++it) 110 for (; it != namespaces_.end(); ++it)
107 it->second->Shutdown(); 111 it->second->Shutdown();
112
113 if (directory_.empty())
114 return;
115
116 // Respect the content policy settings about what to
117 // keep and what to discard.
118 if (save_session_state_)
119 return; // Keep everything.
120
121 bool has_session_only_origins =
122 special_storage_policy_.get() &&
123 special_storage_policy_->HasSessionOnlyOrigins();
124
125 if (clear_local_state_ || has_session_only_origins) {
126 // We may have to delete something. We continue on the
127 // commit sequence after area shutdown tasks have cycled
128 // thru that sequence (and closed their database files).
129 bool success = task_runner_->PostShutdownBlockingTask(
130 FROM_HERE,
131 DomStorageTaskRunner::COMMIT_SEQUENCE,
132 base::Bind(&DomStorageContext::ClearLocalStateInCommitSequence, this));
133 DCHECK(success);
134 }
108 } 135 }
109 136
110 void DomStorageContext::AddEventObserver(EventObserver* observer) { 137 void DomStorageContext::AddEventObserver(EventObserver* observer) {
111 event_observers_.AddObserver(observer); 138 event_observers_.AddObserver(observer);
112 } 139 }
113 140
114 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { 141 void DomStorageContext::RemoveEventObserver(EventObserver* observer) {
115 event_observers_.RemoveObserver(observer); 142 event_observers_.RemoveObserver(observer);
116 } 143 }
117 144
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return; 193 return;
167 DCHECK_NE(kLocalStorageNamespaceId, existing_id); 194 DCHECK_NE(kLocalStorageNamespaceId, existing_id);
168 DCHECK_NE(kLocalStorageNamespaceId, new_id); 195 DCHECK_NE(kLocalStorageNamespaceId, new_id);
169 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); 196 StorageNamespaceMap::iterator found = namespaces_.find(existing_id);
170 if (found != namespaces_.end()) 197 if (found != namespaces_.end())
171 namespaces_[new_id] = found->second->Clone(new_id); 198 namespaces_[new_id] = found->second->Clone(new_id);
172 else 199 else
173 CreateSessionNamespace(new_id); 200 CreateSessionNamespace(new_id);
174 } 201 }
175 202
203 void DomStorageContext::ClearLocalStateInCommitSequence() {
204 std::vector<UsageInfo> infos;
205 const bool kDontIncludeFileInfo = false;
206 GetUsageInfo(&infos, kDontIncludeFileInfo);
207 for (size_t i = 0; i < infos.size(); ++i) {
208 const GURL& origin = infos[i].origin;
209 if (special_storage_policy_ &&
210 special_storage_policy_->IsStorageProtected(origin))
211 continue;
212 if (!clear_local_state_ &&
213 !special_storage_policy_->IsStorageSessionOnly(origin))
214 continue;
215
216 const bool kNotRecursive = false;
217 FilePath database_file_path = directory_.Append(
218 DomStorageArea::DatabaseFileNameFromOrigin(origin));
219 file_util::Delete(database_file_path, kNotRecursive);
220 file_util::Delete(
221 DomStorageDatabase::GetJournalFilePath(database_file_path),
222 kNotRecursive);
223 }
224 }
225
176 } // namespace dom_storage 226 } // 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