OLD | NEW |
---|---|
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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 | 364 |
365 void DOMStorageArea::InitialImportIfNeeded() { | 365 void DOMStorageArea::InitialImportIfNeeded() { |
366 if (is_initial_import_done_) | 366 if (is_initial_import_done_) |
367 return; | 367 return; |
368 | 368 |
369 DCHECK(backing_.get()); | 369 DCHECK(backing_.get()); |
370 | 370 |
371 base::TimeTicks before = base::TimeTicks::Now(); | 371 base::TimeTicks before = base::TimeTicks::Now(); |
372 DOMStorageValuesMap initial_values; | 372 DOMStorageValuesMap initial_values; |
373 backing_->ReadAllValues(&initial_values); | 373 backing_->ReadAllValues(&initial_values); |
374 backing_->TrimMemory(); | |
374 map_->SwapValues(&initial_values); | 375 map_->SwapValues(&initial_values); |
375 is_initial_import_done_ = true; | 376 is_initial_import_done_ = true; |
376 base::TimeDelta time_to_import = base::TimeTicks::Now() - before; | 377 base::TimeDelta time_to_import = base::TimeTicks::Now() - before; |
377 UMA_HISTOGRAM_TIMES("LocalStorage.BrowserTimeToPrimeLocalStorage", | 378 UMA_HISTOGRAM_TIMES("LocalStorage.BrowserTimeToPrimeLocalStorage", |
378 time_to_import); | 379 time_to_import); |
379 | 380 |
380 size_t local_storage_size_kb = map_->bytes_used() / 1024; | 381 size_t local_storage_size_kb = map_->bytes_used() / 1024; |
381 // Track localStorage size, from 0-6MB. Note that the maximum size should be | 382 // 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 | 383 // 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. | 384 // above what we see in practice, since histograms can't change. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 base::Owned(commit_batch_.release()))); | 470 base::Owned(commit_batch_.release()))); |
470 ++commit_batches_in_flight_; | 471 ++commit_batches_in_flight_; |
471 DCHECK(success); | 472 DCHECK(success); |
472 } | 473 } |
473 | 474 |
474 void DOMStorageArea::CommitChanges(const CommitBatch* commit_batch) { | 475 void DOMStorageArea::CommitChanges(const CommitBatch* commit_batch) { |
475 // This method executes on the commit sequence. | 476 // This method executes on the commit sequence. |
476 DCHECK(task_runner_->IsRunningOnCommitSequence()); | 477 DCHECK(task_runner_->IsRunningOnCommitSequence()); |
477 backing_->CommitChanges(commit_batch->clear_all_first, | 478 backing_->CommitChanges(commit_batch->clear_all_first, |
478 commit_batch->changed_values); | 479 commit_batch->changed_values); |
480 backing_->TrimMemory(); | |
michaeln
2016/05/14 00:42:52
What i meant by not exposing this in public api wa
ssid
2016/05/16 20:51:56
Sorry, I was blind. Fixed this.
| |
481 | |
479 // TODO(michaeln): what if CommitChanges returns false (e.g., we're trying to | 482 // TODO(michaeln): what if CommitChanges returns false (e.g., we're trying to |
480 // commit to a DB which is in an inconsistent state?) | 483 // commit to a DB which is in an inconsistent state?) |
481 task_runner_->PostTask( | 484 task_runner_->PostTask( |
482 FROM_HERE, | 485 FROM_HERE, |
483 base::Bind(&DOMStorageArea::OnCommitComplete, this)); | 486 base::Bind(&DOMStorageArea::OnCommitComplete, this)); |
484 } | 487 } |
485 | 488 |
486 void DOMStorageArea::OnCommitComplete() { | 489 void DOMStorageArea::OnCommitComplete() { |
487 // We're back on the primary sequence in this method. | 490 // We're back on the primary sequence in this method. |
488 DCHECK(task_runner_->IsRunningOnPrimarySequence()); | 491 DCHECK(task_runner_->IsRunningOnPrimarySequence()); |
(...skipping 18 matching lines...) Expand all Loading... | |
507 commit_batch_->clear_all_first, | 510 commit_batch_->clear_all_first, |
508 commit_batch_->changed_values); | 511 commit_batch_->changed_values); |
509 DCHECK(success); | 512 DCHECK(success); |
510 } | 513 } |
511 commit_batch_.reset(); | 514 commit_batch_.reset(); |
512 backing_.reset(); | 515 backing_.reset(); |
513 session_storage_backing_ = NULL; | 516 session_storage_backing_ = NULL; |
514 } | 517 } |
515 | 518 |
516 } // namespace content | 519 } // namespace content |
OLD | NEW |