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

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

Issue 9963107: Persist sessionStorage on disk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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
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/location.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "webkit/dom_storage/dom_storage_area.h" 12 #include "webkit/dom_storage/dom_storage_area.h"
13 #include "webkit/dom_storage/dom_storage_namespace.h" 13 #include "webkit/dom_storage/dom_storage_namespace.h"
14 #include "webkit/dom_storage/dom_storage_task_runner.h" 14 #include "webkit/dom_storage/dom_storage_task_runner.h"
15 #include "webkit/dom_storage/dom_storage_types.h" 15 #include "webkit/dom_storage/dom_storage_types.h"
16 #include "webkit/dom_storage/session_storage_database.h"
16 #include "webkit/quota/special_storage_policy.h" 17 #include "webkit/quota/special_storage_policy.h"
17 18
18 using file_util::FileEnumerator; 19 using file_util::FileEnumerator;
19 20
20 namespace dom_storage { 21 namespace dom_storage {
21 22
22 DomStorageContext::UsageInfo::UsageInfo() : data_size(0) {} 23 DomStorageContext::UsageInfo::UsageInfo() : data_size(0) {}
23 DomStorageContext::UsageInfo::~UsageInfo() {} 24 DomStorageContext::UsageInfo::~UsageInfo() {}
24 25
25 DomStorageContext::DomStorageContext( 26 DomStorageContext::DomStorageContext(
26 const FilePath& directory, 27 const FilePath& directory,
27 quota::SpecialStoragePolicy* special_storage_policy, 28 quota::SpecialStoragePolicy* special_storage_policy,
28 DomStorageTaskRunner* task_runner) 29 DomStorageTaskRunner* task_runner)
29 : directory_(directory), 30 : directory_(directory),
30 task_runner_(task_runner), 31 task_runner_(task_runner),
31 is_shutdown_(false), 32 is_shutdown_(false),
32 clear_local_state_(false), 33 clear_local_state_(false),
33 save_session_state_(false), 34 save_session_state_(false),
34 special_storage_policy_(special_storage_policy) { 35 special_storage_policy_(special_storage_policy) {
35 // AtomicSequenceNum starts at 0 but we want to start session 36 // AtomicSequenceNum starts at 0 but we want to start session
36 // namespace ids at one since zero is reserved for the 37 // namespace ids at one since zero is reserved for the
37 // kLocalStorageNamespaceId. 38 // kLocalStorageNamespaceId.
38 session_id_sequence_.GetNext(); 39 session_id_sequence_.GetNext();
40 // FIXME(marja): hack.
41 if (!directory_.empty()) {
42 session_storage_database_ =
43 new SessionStorageDatabase(directory.Append("Session Storage"));
44 // Delete the possible leftover data from previous run from the session
45 // storage.
46 // TODO(marja): When doing a session restore, protect parts of the data from
47 // deletion and call this when we know if a session restore will happen.
48 session_storage_database_->DeleteLeftoverData();
michaeln 2012/04/12 01:48:46 This constructor is invoked on the UI thread in ch
marja 2012/04/19 10:20:50 Yes, this was wrong. If we crash, DeleteSessionNa
49 }
39 } 50 }
40 51
41 DomStorageContext::~DomStorageContext() { 52 DomStorageContext::~DomStorageContext() {
42 } 53 }
43 54
44 DomStorageNamespace* DomStorageContext::GetStorageNamespace( 55 DomStorageNamespace* DomStorageContext::GetStorageNamespace(
45 int64 namespace_id) { 56 int64 namespace_id) {
46 if (is_shutdown_) 57 if (is_shutdown_)
47 return NULL; 58 return NULL;
48 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); 59 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id);
(...skipping 28 matching lines...) Expand all
77 info.origin = DomStorageArea::OriginFromDatabaseFileName(path); 88 info.origin = DomStorageArea::OriginFromDatabaseFileName(path);
78 if (include_file_info) { 89 if (include_file_info) {
79 FileEnumerator::FindInfo find_info; 90 FileEnumerator::FindInfo find_info;
80 enumerator.GetFindInfo(&find_info); 91 enumerator.GetFindInfo(&find_info);
81 info.data_size = FileEnumerator::GetFilesize(find_info); 92 info.data_size = FileEnumerator::GetFilesize(find_info);
82 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); 93 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info);
83 } 94 }
84 infos->push_back(info); 95 infos->push_back(info);
85 } 96 }
86 } 97 }
98 // FIXME(marja): Get usage infos for sessionStorage.
michaeln 2012/04/12 01:48:46 The content settings ui doesn't show anything abou
marja 2012/04/19 10:20:50 Done. crbug.com/123599
87 } 99 }
88 100
89 void DomStorageContext::DeleteOrigin(const GURL& origin) { 101 void DomStorageContext::DeleteOrigin(const GURL& origin) {
90 DCHECK(!is_shutdown_); 102 DCHECK(!is_shutdown_);
91 DomStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); 103 DomStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId);
92 local->DeleteOrigin(origin); 104 local->DeleteOrigin(origin);
93 } 105 }
94 106
95 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { 107 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) {
96 std::vector<UsageInfo> infos; 108 std::vector<UsageInfo> infos;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 EventObserver, event_observers_, 193 EventObserver, event_observers_,
182 OnDomStorageAreaCleared(area, page_url)); 194 OnDomStorageAreaCleared(area, page_url));
183 } 195 }
184 196
185 void DomStorageContext::CreateSessionNamespace( 197 void DomStorageContext::CreateSessionNamespace(
186 int64 namespace_id) { 198 int64 namespace_id) {
187 if (is_shutdown_) 199 if (is_shutdown_)
188 return; 200 return;
189 DCHECK(namespace_id != kLocalStorageNamespaceId); 201 DCHECK(namespace_id != kLocalStorageNamespaceId);
190 DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); 202 DCHECK(namespaces_.find(namespace_id) == namespaces_.end());
191 namespaces_[namespace_id] = new DomStorageNamespace( 203 if (session_storage_database_.get()) {
192 namespace_id, task_runner_); 204 // Session storage with backing.
205 namespaces_[namespace_id] = new DomStorageNamespace(
206 namespace_id, session_storage_database_.get(), task_runner_);
207 } else {
208 // Session storage without backing.
209 namespaces_[namespace_id] = new DomStorageNamespace(
210 namespace_id, task_runner_);
211 }
193 } 212 }
194 213
195 void DomStorageContext::DeleteSessionNamespace( 214 void DomStorageContext::DeleteSessionNamespace(
196 int64 namespace_id) { 215 int64 namespace_id) {
197 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); 216 DCHECK_NE(kLocalStorageNamespaceId, namespace_id);
198 namespaces_.erase(namespace_id); 217 namespaces_.erase(namespace_id);
michaeln 2012/04/12 01:48:46 This might be a better place to trigger deletion f
marja 2012/04/19 10:20:50 Done.
199 } 218 }
200 219
201 void DomStorageContext::CloneSessionNamespace( 220 void DomStorageContext::CloneSessionNamespace(
202 int64 existing_id, int64 new_id) { 221 int64 existing_id, int64 new_id) {
203 if (is_shutdown_) 222 if (is_shutdown_)
204 return; 223 return;
205 DCHECK_NE(kLocalStorageNamespaceId, existing_id); 224 DCHECK_NE(kLocalStorageNamespaceId, existing_id);
206 DCHECK_NE(kLocalStorageNamespaceId, new_id); 225 DCHECK_NE(kLocalStorageNamespaceId, new_id);
207 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); 226 StorageNamespaceMap::iterator found = namespaces_.find(existing_id);
208 if (found != namespaces_.end()) 227 if (found != namespaces_.end())
(...skipping 13 matching lines...) Expand all
222 continue; 241 continue;
223 if (!clear_local_state_ && 242 if (!clear_local_state_ &&
224 !special_storage_policy_->IsStorageSessionOnly(origin)) 243 !special_storage_policy_->IsStorageSessionOnly(origin))
225 continue; 244 continue;
226 245
227 const bool kNotRecursive = false; 246 const bool kNotRecursive = false;
228 FilePath database_file_path = directory_.Append( 247 FilePath database_file_path = directory_.Append(
229 DomStorageArea::DatabaseFileNameFromOrigin(origin)); 248 DomStorageArea::DatabaseFileNameFromOrigin(origin));
230 file_util::Delete(database_file_path, kNotRecursive); 249 file_util::Delete(database_file_path, kNotRecursive);
231 file_util::Delete( 250 file_util::Delete(
232 DomStorageDatabase::GetJournalFilePath(database_file_path), 251 LocalStorageDatabase::GetJournalFilePath(database_file_path),
233 kNotRecursive); 252 kNotRecursive);
234 } 253 }
235 } 254 }
236 255
237 } // namespace dom_storage 256 } // namespace dom_storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698