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 <inttypes.h> | 7 #include <inttypes.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cctype> // for std::isalnum | 10 #include <cctype> // for std::isalnum |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 return; | 339 return; |
340 | 340 |
341 bool success = task_runner_->PostShutdownBlockingTask( | 341 bool success = task_runner_->PostShutdownBlockingTask( |
342 FROM_HERE, | 342 FROM_HERE, |
343 DOMStorageTaskRunner::COMMIT_SEQUENCE, | 343 DOMStorageTaskRunner::COMMIT_SEQUENCE, |
344 base::Bind(&DOMStorageArea::ShutdownInCommitSequence, this)); | 344 base::Bind(&DOMStorageArea::ShutdownInCommitSequence, this)); |
345 DCHECK(success); | 345 DCHECK(success); |
346 } | 346 } |
347 | 347 |
348 void DOMStorageArea::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { | 348 void DOMStorageArea::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { |
349 DCHECK(task_runner_->IsRunningOnPrimarySequence()); | 349 task_runner_->AssertIsRunningOnPrimarySequence(); |
350 if (!is_initial_import_done_) | 350 if (!is_initial_import_done_) |
351 return; | 351 return; |
352 | 352 |
353 // Limit the url length to 50 and strip special characters. | 353 // Limit the url length to 50 and strip special characters. |
354 std::string url = origin_.spec().substr(0, 50); | 354 std::string url = origin_.spec().substr(0, 50); |
355 for (size_t index = 0; index < url.size(); ++index) { | 355 for (size_t index = 0; index < url.size(); ++index) { |
356 if (!std::isalnum(url[index])) | 356 if (!std::isalnum(url[index])) |
357 url[index] = '_'; | 357 url[index] = '_'; |
358 } | 358 } |
359 std::string name = | 359 std::string name = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 if (!commit_batch_) { | 428 if (!commit_batch_) { |
429 commit_batch_.reset(new CommitBatch()); | 429 commit_batch_.reset(new CommitBatch()); |
430 BrowserThread::PostAfterStartupTask( | 430 BrowserThread::PostAfterStartupTask( |
431 FROM_HERE, task_runner_, | 431 FROM_HERE, task_runner_, |
432 base::Bind(&DOMStorageArea::StartCommitTimer, this)); | 432 base::Bind(&DOMStorageArea::StartCommitTimer, this)); |
433 } | 433 } |
434 return commit_batch_.get(); | 434 return commit_batch_.get(); |
435 } | 435 } |
436 | 436 |
437 void DOMStorageArea::PopulateCommitBatchValues() { | 437 void DOMStorageArea::PopulateCommitBatchValues() { |
438 DCHECK(task_runner_->IsRunningOnPrimarySequence()); | 438 task_runner_->AssertIsRunningOnPrimarySequence(); |
439 for (auto& key_value : commit_batch_->changed_values) | 439 for (auto& key_value : commit_batch_->changed_values) |
440 key_value.second = map_->GetItem(key_value.first); | 440 key_value.second = map_->GetItem(key_value.first); |
441 } | 441 } |
442 | 442 |
443 void DOMStorageArea::StartCommitTimer() { | 443 void DOMStorageArea::StartCommitTimer() { |
444 if (is_shutdown_ || !commit_batch_) | 444 if (is_shutdown_ || !commit_batch_) |
445 return; | 445 return; |
446 | 446 |
447 // Start a timer to commit any changes that accrue in the batch, but only if | 447 // Start a timer to commit any changes that accrue in the batch, but only if |
448 // no commits are currently in flight. In that case the timer will be | 448 // no commits are currently in flight. In that case the timer will be |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 return; | 485 return; |
486 | 486 |
487 DCHECK(backing_.get()); | 487 DCHECK(backing_.get()); |
488 | 488 |
489 PopulateCommitBatchValues(); | 489 PopulateCommitBatchValues(); |
490 commit_rate_limiter_.add_samples(1); | 490 commit_rate_limiter_.add_samples(1); |
491 data_rate_limiter_.add_samples(commit_batch_->GetDataSize()); | 491 data_rate_limiter_.add_samples(commit_batch_->GetDataSize()); |
492 | 492 |
493 // This method executes on the primary sequence, we schedule | 493 // This method executes on the primary sequence, we schedule |
494 // a task for immediate execution on the commit sequence. | 494 // a task for immediate execution on the commit sequence. |
495 DCHECK(task_runner_->IsRunningOnPrimarySequence()); | 495 task_runner_->AssertIsRunningOnPrimarySequence(); |
496 bool success = task_runner_->PostShutdownBlockingTask( | 496 bool success = task_runner_->PostShutdownBlockingTask( |
497 FROM_HERE, | 497 FROM_HERE, |
498 DOMStorageTaskRunner::COMMIT_SEQUENCE, | 498 DOMStorageTaskRunner::COMMIT_SEQUENCE, |
499 base::Bind(&DOMStorageArea::CommitChanges, this, | 499 base::Bind(&DOMStorageArea::CommitChanges, this, |
500 base::Owned(commit_batch_.release()))); | 500 base::Owned(commit_batch_.release()))); |
501 ++commit_batches_in_flight_; | 501 ++commit_batches_in_flight_; |
502 DCHECK(success); | 502 DCHECK(success); |
503 } | 503 } |
504 | 504 |
505 void DOMStorageArea::CommitChanges(const CommitBatch* commit_batch) { | 505 void DOMStorageArea::CommitChanges(const CommitBatch* commit_batch) { |
506 // This method executes on the commit sequence. | 506 // This method executes on the commit sequence. |
507 DCHECK(task_runner_->IsRunningOnCommitSequence()); | 507 task_runner_->AssertIsRunningOnCommitSequence(); |
508 backing_->CommitChanges(commit_batch->clear_all_first, | 508 backing_->CommitChanges(commit_batch->clear_all_first, |
509 commit_batch->changed_values); | 509 commit_batch->changed_values); |
510 // TODO(michaeln): what if CommitChanges returns false (e.g., we're trying to | 510 // TODO(michaeln): what if CommitChanges returns false (e.g., we're trying to |
511 // commit to a DB which is in an inconsistent state?) | 511 // commit to a DB which is in an inconsistent state?) |
512 task_runner_->PostTask( | 512 task_runner_->PostTask( |
513 FROM_HERE, | 513 FROM_HERE, |
514 base::Bind(&DOMStorageArea::OnCommitComplete, this)); | 514 base::Bind(&DOMStorageArea::OnCommitComplete, this)); |
515 } | 515 } |
516 | 516 |
517 void DOMStorageArea::OnCommitComplete() { | 517 void DOMStorageArea::OnCommitComplete() { |
518 // We're back on the primary sequence in this method. | 518 // We're back on the primary sequence in this method. |
519 DCHECK(task_runner_->IsRunningOnPrimarySequence()); | 519 task_runner_->AssertIsRunningOnPrimarySequence(); |
520 --commit_batches_in_flight_; | 520 --commit_batches_in_flight_; |
521 if (is_shutdown_) | 521 if (is_shutdown_) |
522 return; | 522 return; |
523 if (commit_batch_.get() && !commit_batches_in_flight_) { | 523 if (commit_batch_.get() && !commit_batches_in_flight_) { |
524 // More changes have accrued, restart the timer. | 524 // More changes have accrued, restart the timer. |
525 task_runner_->PostDelayedTask( | 525 task_runner_->PostDelayedTask( |
526 FROM_HERE, base::Bind(&DOMStorageArea::OnCommitTimer, this), | 526 FROM_HERE, base::Bind(&DOMStorageArea::OnCommitTimer, this), |
527 ComputeCommitDelay()); | 527 ComputeCommitDelay()); |
528 } | 528 } |
529 } | 529 } |
530 | 530 |
531 void DOMStorageArea::ShutdownInCommitSequence() { | 531 void DOMStorageArea::ShutdownInCommitSequence() { |
532 // This method executes on the commit sequence. | 532 // This method executes on the commit sequence. |
533 DCHECK(task_runner_->IsRunningOnCommitSequence()); | 533 task_runner_->AssertIsRunningOnCommitSequence(); |
534 DCHECK(backing_.get()); | 534 DCHECK(backing_.get()); |
535 if (commit_batch_) { | 535 if (commit_batch_) { |
536 // Commit any changes that accrued prior to the timer firing. | 536 // Commit any changes that accrued prior to the timer firing. |
537 bool success = backing_->CommitChanges( | 537 bool success = backing_->CommitChanges( |
538 commit_batch_->clear_all_first, | 538 commit_batch_->clear_all_first, |
539 commit_batch_->changed_values); | 539 commit_batch_->changed_values); |
540 DCHECK(success); | 540 DCHECK(success); |
541 } | 541 } |
542 commit_batch_.reset(); | 542 commit_batch_.reset(); |
543 backing_.reset(); | 543 backing_.reset(); |
544 session_storage_backing_ = NULL; | 544 session_storage_backing_ = NULL; |
545 } | 545 } |
546 | 546 |
547 } // namespace content | 547 } // namespace content |
OLD | NEW |