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

Side by Side Diff: content/browser/dom_storage/dom_storage_area.cc

Issue 1953703004: Purge browser cache for dom storage in a smarter way (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dom_storage
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/dom_storage/dom_storage_area.h" 5 #include "content/browser/dom_storage/dom_storage_area.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> // for std::isalnum 8 #include <cctype> // for std::isalnum
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 296 }
297 map_ = new DOMStorageMap(kPerStorageAreaQuota + 297 map_ = new DOMStorageMap(kPerStorageAreaQuota +
298 kPerStorageAreaOverQuotaAllowance); 298 kPerStorageAreaOverQuotaAllowance);
299 if (backing_) { 299 if (backing_) {
300 is_initial_import_done_ = false; 300 is_initial_import_done_ = false;
301 backing_->Reset(); 301 backing_->Reset();
302 backing_->DeleteFiles(); 302 backing_->DeleteFiles();
303 } 303 }
304 } 304 }
305 305
306 void DOMStorageArea::TrimDatabase() {
307 if (backing_)
michaeln 2016/05/09 21:50:31 There are some complications that i think make thi
ssid 2016/05/10 02:04:15 Thanks, I didn't realize this issue. Yes, post tas
308 backing_->TrimDatabase();
309 }
310
306 void DOMStorageArea::PurgeMemory() { 311 void DOMStorageArea::PurgeMemory() {
307 DCHECK(!is_shutdown_); 312 DCHECK(!is_shutdown_);
308 // Purging sessionStorage is not supported; it won't work with FastClear. 313 // Purging sessionStorage is not supported; it won't work with FastClear.
309 DCHECK(!session_storage_backing_.get()); 314 DCHECK(!session_storage_backing_.get());
310 if (!is_initial_import_done_ || // We're not using any memory. 315 if (!is_initial_import_done_ || // We're not using any memory.
311 !backing_.get() || // We can't purge anything. 316 !backing_.get() || // We can't purge anything.
312 HasUncommittedChanges()) // We leave things alone with changes pending. 317 HasUncommittedChanges()) // We leave things alone with changes pending.
313 return; 318 return;
314 319
315 // Drop the in memory cache, we'll reload when needed. 320 // Drop the in memory cache, we'll reload when needed.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 368 }
364 369
365 void DOMStorageArea::InitialImportIfNeeded() { 370 void DOMStorageArea::InitialImportIfNeeded() {
366 if (is_initial_import_done_) 371 if (is_initial_import_done_)
367 return; 372 return;
368 373
369 DCHECK(backing_.get()); 374 DCHECK(backing_.get());
370 375
371 base::TimeTicks before = base::TimeTicks::Now(); 376 base::TimeTicks before = base::TimeTicks::Now();
372 DOMStorageValuesMap initial_values; 377 DOMStorageValuesMap initial_values;
373 backing_->ReadAllValues(&initial_values); 378 backing_->ReadAllValues(&initial_values);
michaeln 2016/05/09 21:50:31 so maybe call TrimDatabase() here
ssid 2016/05/10 02:04:15 Done. Made the trim non-aggressive in database.cc.
374 map_->SwapValues(&initial_values); 379 map_->SwapValues(&initial_values);
375 is_initial_import_done_ = true; 380 is_initial_import_done_ = true;
376 base::TimeDelta time_to_import = base::TimeTicks::Now() - before; 381 base::TimeDelta time_to_import = base::TimeTicks::Now() - before;
377 UMA_HISTOGRAM_TIMES("LocalStorage.BrowserTimeToPrimeLocalStorage", 382 UMA_HISTOGRAM_TIMES("LocalStorage.BrowserTimeToPrimeLocalStorage",
378 time_to_import); 383 time_to_import);
379 384
380 size_t local_storage_size_kb = map_->bytes_used() / 1024; 385 size_t local_storage_size_kb = map_->bytes_used() / 1024;
381 // Track localStorage size, from 0-6MB. Note that the maximum size should be 386 // Track localStorage size, from 0-6MB. Note that the maximum size should be
382 // 5MB, but we add some slop since we want to make sure the max size is always 387 // 5MB, but we add some slop since we want to make sure the max size is always
383 // above what we see in practice, since histograms can't change. 388 // above what we see in practice, since histograms can't change.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 base::Bind(&DOMStorageArea::CommitChanges, this, 473 base::Bind(&DOMStorageArea::CommitChanges, this,
469 base::Owned(commit_batch_.release()))); 474 base::Owned(commit_batch_.release())));
470 ++commit_batches_in_flight_; 475 ++commit_batches_in_flight_;
471 DCHECK(success); 476 DCHECK(success);
472 } 477 }
473 478
474 void DOMStorageArea::CommitChanges(const CommitBatch* commit_batch) { 479 void DOMStorageArea::CommitChanges(const CommitBatch* commit_batch) {
475 // This method executes on the commit sequence. 480 // This method executes on the commit sequence.
476 DCHECK(task_runner_->IsRunningOnCommitSequence()); 481 DCHECK(task_runner_->IsRunningOnCommitSequence());
477 backing_->CommitChanges(commit_batch->clear_all_first, 482 backing_->CommitChanges(commit_batch->clear_all_first,
478 commit_batch->changed_values); 483 commit_batch->changed_values);
michaeln 2016/05/09 21:50:31 and maybe call TrimMemory() here
ssid 2016/05/10 02:04:15 Done.
479 // TODO(michaeln): what if CommitChanges returns false (e.g., we're trying to 484 // TODO(michaeln): what if CommitChanges returns false (e.g., we're trying to
480 // commit to a DB which is in an inconsistent state?) 485 // commit to a DB which is in an inconsistent state?)
481 task_runner_->PostTask( 486 task_runner_->PostTask(
482 FROM_HERE, 487 FROM_HERE,
483 base::Bind(&DOMStorageArea::OnCommitComplete, this)); 488 base::Bind(&DOMStorageArea::OnCommitComplete, this));
484 } 489 }
485 490
486 void DOMStorageArea::OnCommitComplete() { 491 void DOMStorageArea::OnCommitComplete() {
487 // We're back on the primary sequence in this method. 492 // We're back on the primary sequence in this method.
488 DCHECK(task_runner_->IsRunningOnPrimarySequence()); 493 DCHECK(task_runner_->IsRunningOnPrimarySequence());
(...skipping 18 matching lines...) Expand all
507 commit_batch_->clear_all_first, 512 commit_batch_->clear_all_first,
508 commit_batch_->changed_values); 513 commit_batch_->changed_values);
509 DCHECK(success); 514 DCHECK(success);
510 } 515 }
511 commit_batch_.reset(); 516 commit_batch_.reset();
512 backing_.reset(); 517 backing_.reset();
513 session_storage_backing_ = NULL; 518 session_storage_backing_ = NULL;
514 } 519 }
515 520
516 } // namespace content 521 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698