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

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 GetUsageInfo(&infos, true);
91 for (size_t i = 0; i < infos.size(); ++i) {
92 if (infos[i].last_modified > cutoff)
93 DeleteOrigin(infos[i].origin);
94 }
92 } 95 }
93 96
94 void DomStorageContext::PurgeMemory() { 97 void DomStorageContext::PurgeMemory() {
95 // We can only purge memory from the local storage namespace 98 // We can only purge memory from the local storage namespace
96 // which is backed by disk. 99 // which is backed by disk.
97 StorageNamespaceMap::iterator found = 100 StorageNamespaceMap::iterator found =
98 namespaces_.find(kLocalStorageNamespaceId); 101 namespaces_.find(kLocalStorageNamespaceId);
99 if (found != namespaces_.end()) 102 if (found != namespaces_.end())
100 found->second->PurgeMemory(); 103 found->second->PurgeMemory();
101 } 104 }
102 105
103 void DomStorageContext::Shutdown() { 106 void DomStorageContext::Shutdown() {
104 is_shutdown_ = true; 107 is_shutdown_ = true;
105 StorageNamespaceMap::const_iterator it = namespaces_.begin(); 108 StorageNamespaceMap::const_iterator it = namespaces_.begin();
106 for (; it != namespaces_.end(); ++it) 109 for (; it != namespaces_.end(); ++it)
107 it->second->Shutdown(); 110 it->second->Shutdown();
111
112 if (directory_.empty())
113 return;
114
115 // Respect the content policy settings about what to
116 // keep and what to discard.
117 if (save_session_state_)
118 return; // Keep everything.
119
120 bool has_session_only_origins =
121 special_storage_policy_.get() &&
122 special_storage_policy_->HasSessionOnlyOrigins();
123 if (!clear_local_state_ && !has_session_only_origins)
jsbell 2012/03/22 00:27:46 Just for readability, perhaps change this to: if
michaeln 2012/03/22 00:53:17 Done.
124 return; // Only clearing session-only origins and there are none.
125
126 // We continue on the commit sequence so our ClearLocalState
127 // task executes after all areas have been shutdown (and closed
128 // 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);
108 } 134 }
109 135
110 void DomStorageContext::AddEventObserver(EventObserver* observer) { 136 void DomStorageContext::AddEventObserver(EventObserver* observer) {
111 event_observers_.AddObserver(observer); 137 event_observers_.AddObserver(observer);
112 } 138 }
113 139
114 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { 140 void DomStorageContext::RemoveEventObserver(EventObserver* observer) {
115 event_observers_.RemoveObserver(observer); 141 event_observers_.RemoveObserver(observer);
116 } 142 }
117 143
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return; 192 return;
167 DCHECK_NE(kLocalStorageNamespaceId, existing_id); 193 DCHECK_NE(kLocalStorageNamespaceId, existing_id);
168 DCHECK_NE(kLocalStorageNamespaceId, new_id); 194 DCHECK_NE(kLocalStorageNamespaceId, new_id);
169 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); 195 StorageNamespaceMap::iterator found = namespaces_.find(existing_id);
170 if (found != namespaces_.end()) 196 if (found != namespaces_.end())
171 namespaces_[new_id] = found->second->Clone(new_id); 197 namespaces_[new_id] = found->second->Clone(new_id);
172 else 198 else
173 CreateSessionNamespace(new_id); 199 CreateSessionNamespace(new_id);
174 } 200 }
175 201
202 void DomStorageContext::ClearLocalStateInCommitSequence() {
203 std::vector<UsageInfo> infos;
204 GetUsageInfo(&infos, false);
jsbell 2012/03/22 00:27:46 nit: named constant here?
michaeln 2012/03/22 00:53:17 Done.
205 for (size_t i = 0; i < infos.size(); ++i) {
206 const GURL& origin = infos[i].origin;
207 if (special_storage_policy_ &&
208 special_storage_policy_->IsStorageProtected(origin))
209 continue;
210 if (!clear_local_state_ &&
211 !special_storage_policy_->IsStorageSessionOnly(origin))
212 continue;
213
214 FilePath database_file_path = directory_.Append(
215 DomStorageArea::DatabaseFileNameFromOrigin(origin));
216 file_util::Delete(database_file_path, false);
jsbell 2012/03/22 00:27:46 nit: and here?
michaeln 2012/03/22 00:53:17 Done.
217 file_util::Delete(
218 DomStorageDatabase::GetJournalFilePath(database_file_path), false);
219 }
220 }
221
176 } // namespace dom_storage 222 } // 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