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

Side by Side Diff: webkit/dom_storage/dom_storage_area.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_area.h" 5 #include "webkit/dom_storage/dom_storage_area.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 int64 namespace_id, const GURL& origin, 56 int64 namespace_id, const GURL& origin,
57 const FilePath& directory, DomStorageTaskRunner* task_runner) 57 const FilePath& directory, DomStorageTaskRunner* task_runner)
58 : namespace_id_(namespace_id), origin_(origin), 58 : namespace_id_(namespace_id), origin_(origin),
59 directory_(directory), 59 directory_(directory),
60 task_runner_(task_runner), 60 task_runner_(task_runner),
61 map_(new DomStorageMap(kPerAreaQuota)), 61 map_(new DomStorageMap(kPerAreaQuota)),
62 is_initial_import_done_(true), 62 is_initial_import_done_(true),
63 is_shutdown_(false) { 63 is_shutdown_(false) {
64 if (namespace_id == kLocalStorageNamespaceId && !directory.empty()) { 64 if (namespace_id == kLocalStorageNamespaceId && !directory.empty()) {
65 FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_)); 65 FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_));
66 backing_.reset(new DomStorageDatabase(path)); 66 backing_.reset(new LocalStorageDatabase(path));
67 is_initial_import_done_ = false; 67 is_initial_import_done_ = false;
68 } 68 }
69 } 69 }
70 70
71 DomStorageArea::~DomStorageArea() { 71 DomStorageArea::~DomStorageArea() {
72 } 72 }
73 73
74 unsigned DomStorageArea::Length() { 74 unsigned DomStorageArea::Length() {
75 if (is_shutdown_) 75 if (is_shutdown_)
76 return 0; 76 return 0;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 DCHECK(!is_shutdown_); 161 DCHECK(!is_shutdown_);
162 if (HasUncommittedChanges()) { 162 if (HasUncommittedChanges()) {
163 // TODO(michaeln): This logically deletes the data immediately, 163 // TODO(michaeln): This logically deletes the data immediately,
164 // and in a matter of a second, deletes the rows from the backing 164 // and in a matter of a second, deletes the rows from the backing
165 // database file, but the file itself will linger until shutdown 165 // database file, but the file itself will linger until shutdown
166 // or purge time. Ideally, this should delete the file more 166 // or purge time. Ideally, this should delete the file more
167 // quickly. 167 // quickly.
168 Clear(); 168 Clear();
169 return; 169 return;
170 } 170 }
171 // FIXME(marja): session storage here...
171 map_ = new DomStorageMap(kPerAreaQuota); 172 map_ = new DomStorageMap(kPerAreaQuota);
172 if (backing_.get()) { 173 if (backing_.get()) {
173 is_initial_import_done_ = false; 174 is_initial_import_done_ = false;
174 backing_.reset(new DomStorageDatabase(backing_->file_path())); 175 backing_.reset(new LocalStorageDatabase(backing_->file_path()));
175 file_util::Delete(backing_->file_path(), false); 176 file_util::Delete(backing_->file_path(), false);
176 file_util::Delete( 177 file_util::Delete(
177 DomStorageDatabase::GetJournalFilePath(backing_->file_path()), false); 178 LocalStorageDatabase::GetJournalFilePath(backing_->file_path()), false);
178 } 179 }
179 } 180 }
180 181
181 void DomStorageArea::PurgeMemory() { 182 void DomStorageArea::PurgeMemory() {
182 DCHECK(!is_shutdown_); 183 DCHECK(!is_shutdown_);
183 if (!is_initial_import_done_ || // We're not using any memory. 184 if (!is_initial_import_done_ || // We're not using any memory.
184 !backing_.get() || // We can't purge anything. 185 !backing_.get() || // We can't purge anything.
185 HasUncommittedChanges()) // We leave things alone with changes pending. 186 HasUncommittedChanges()) // We leave things alone with changes pending.
186 return; 187 return;
187 188
188 // Drop the in memory cache, we'll reload when needed. 189 // Drop the in memory cache, we'll reload when needed.
189 is_initial_import_done_ = false; 190 is_initial_import_done_ = false;
190 map_ = new DomStorageMap(kPerAreaQuota); 191 map_ = new DomStorageMap(kPerAreaQuota);
191 192
192 // Recreate the database object, this frees up the open sqlite connection 193 // Recreate the database object, this frees up the open sqlite connection
193 // and its page cache. 194 // and its page cache.
194 backing_.reset(new DomStorageDatabase(backing_->file_path())); 195 backing_.reset(new LocalStorageDatabase(backing_->file_path()));
195 } 196 }
196 197
197 void DomStorageArea::Shutdown() { 198 void DomStorageArea::Shutdown() {
198 DCHECK(!is_shutdown_); 199 DCHECK(!is_shutdown_);
199 is_shutdown_ = true; 200 is_shutdown_ = true;
200 map_ = NULL; 201 map_ = NULL;
201 if (!backing_.get()) 202 if (!backing_.get())
202 return; 203 return;
203 204
204 bool success = task_runner_->PostShutdownBlockingTask( 205 bool success = task_runner_->PostShutdownBlockingTask(
205 FROM_HERE, 206 FROM_HERE,
206 DomStorageTaskRunner::COMMIT_SEQUENCE, 207 DomStorageTaskRunner::COMMIT_SEQUENCE,
207 base::Bind(&DomStorageArea::ShutdownInCommitSequence, this)); 208 base::Bind(&DomStorageArea::ShutdownInCommitSequence, this));
208 DCHECK(success); 209 DCHECK(success);
209 } 210 }
210 211
211 void DomStorageArea::InitialImportIfNeeded() { 212 void DomStorageArea::InitialImportIfNeeded() {
212 if (is_initial_import_done_) 213 if (is_initial_import_done_)
213 return; 214 return;
214 215
215 DCHECK_EQ(kLocalStorageNamespaceId, namespace_id_); 216 DCHECK_EQ(kLocalStorageNamespaceId, namespace_id_);
216 DCHECK(backing_.get()); 217 DCHECK(backing_.get());
217 218
218 ValuesMap initial_values; 219 ValuesMap initial_values;
219 backing_->ReadAllValues(&initial_values); 220 backing_->ReadAllValues(namespace_id_, origin_, &initial_values);
220 map_->SwapValues(&initial_values); 221 map_->SwapValues(&initial_values);
221 is_initial_import_done_ = true; 222 is_initial_import_done_ = true;
222 } 223 }
223 224
224 DomStorageArea::CommitBatch* DomStorageArea::CreateCommitBatchIfNeeded() { 225 DomStorageArea::CommitBatch* DomStorageArea::CreateCommitBatchIfNeeded() {
225 DCHECK(!is_shutdown_); 226 DCHECK(!is_shutdown_);
226 if (!commit_batch_.get()) { 227 if (!commit_batch_.get()) {
227 commit_batch_.reset(new CommitBatch()); 228 commit_batch_.reset(new CommitBatch());
228 229
229 // Start a timer to commit any changes that accrue in the batch, 230 // Start a timer to commit any changes that accrue in the batch,
(...skipping 25 matching lines...) Expand all
255 FROM_HERE, 256 FROM_HERE,
256 DomStorageTaskRunner::COMMIT_SEQUENCE, 257 DomStorageTaskRunner::COMMIT_SEQUENCE,
257 base::Bind(&DomStorageArea::CommitChanges, this)); 258 base::Bind(&DomStorageArea::CommitChanges, this));
258 DCHECK(success); 259 DCHECK(success);
259 } 260 }
260 261
261 void DomStorageArea::CommitChanges() { 262 void DomStorageArea::CommitChanges() {
262 // This method executes on the commit sequence. 263 // This method executes on the commit sequence.
263 DCHECK(in_flight_commit_batch_.get()); 264 DCHECK(in_flight_commit_batch_.get());
264 bool success = backing_->CommitChanges( 265 bool success = backing_->CommitChanges(
266 namespace_id_, origin_,
265 in_flight_commit_batch_->clear_all_first, 267 in_flight_commit_batch_->clear_all_first,
266 in_flight_commit_batch_->changed_values); 268 in_flight_commit_batch_->changed_values);
267 DCHECK(success); // TODO(michaeln): what if it fails? 269 DCHECK(success); // TODO(michaeln): what if it fails?
268 task_runner_->PostTask( 270 task_runner_->PostTask(
269 FROM_HERE, 271 FROM_HERE,
270 base::Bind(&DomStorageArea::OnCommitComplete, this)); 272 base::Bind(&DomStorageArea::OnCommitComplete, this));
271 } 273 }
272 274
273 void DomStorageArea::OnCommitComplete() { 275 void DomStorageArea::OnCommitComplete() {
274 // We're back on the primary sequence in this method. 276 // We're back on the primary sequence in this method.
275 if (is_shutdown_) 277 if (is_shutdown_)
276 return; 278 return;
277 in_flight_commit_batch_.reset(); 279 in_flight_commit_batch_.reset();
278 if (commit_batch_.get()) { 280 if (commit_batch_.get()) {
279 // More changes have accrued, restart the timer. 281 // More changes have accrued, restart the timer.
280 task_runner_->PostDelayedTask( 282 task_runner_->PostDelayedTask(
281 FROM_HERE, 283 FROM_HERE,
282 base::Bind(&DomStorageArea::OnCommitTimer, this), 284 base::Bind(&DomStorageArea::OnCommitTimer, this),
283 base::TimeDelta::FromSeconds(kCommitTimerSeconds)); 285 base::TimeDelta::FromSeconds(kCommitTimerSeconds));
284 } 286 }
285 } 287 }
286 288
287 void DomStorageArea::ShutdownInCommitSequence() { 289 void DomStorageArea::ShutdownInCommitSequence() {
288 // This method executes on the commit sequence. 290 // This method executes on the commit sequence.
289 DCHECK(backing_.get()); 291 DCHECK(backing_.get());
290 if (commit_batch_.get()) { 292 if (commit_batch_.get()) {
291 // Commit any changes that accrued prior to the timer firing. 293 // Commit any changes that accrued prior to the timer firing.
292 bool success = backing_->CommitChanges( 294 bool success = backing_->CommitChanges(
295 namespace_id_, origin_,
293 commit_batch_->clear_all_first, 296 commit_batch_->clear_all_first,
294 commit_batch_->changed_values); 297 commit_batch_->changed_values);
295 DCHECK(success); 298 DCHECK(success);
296 } 299 }
297 commit_batch_.reset(); 300 commit_batch_.reset();
298 in_flight_commit_batch_.reset(); 301 in_flight_commit_batch_.reset();
299 backing_.reset(); 302 backing_.reset();
300 } 303 }
301 304
302 } // namespace dom_storage 305 } // namespace dom_storage
OLDNEW
« no previous file with comments | « no previous file | webkit/dom_storage/dom_storage_context.cc » ('j') | webkit/dom_storage/session_storage_database.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698