| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/process/process_info.h" | 13 #include "base/process/process_info.h" |
| 14 #include "base/rand_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "content/browser/dom_storage/dom_storage_namespace.h" | 17 #include "content/browser/dom_storage/dom_storage_namespace.h" |
| 17 #include "content/browser/dom_storage/dom_storage_task_runner.h" | 18 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
| 18 #include "content/browser/dom_storage/local_storage_database_adapter.h" | 19 #include "content/browser/dom_storage/local_storage_database_adapter.h" |
| 19 #include "content/browser/dom_storage/session_storage_database.h" | 20 #include "content/browser/dom_storage/session_storage_database.h" |
| 20 #include "content/browser/dom_storage/session_storage_database_adapter.h" | 21 #include "content/browser/dom_storage/session_storage_database_adapter.h" |
| 21 #include "content/common/dom_storage/dom_storage_map.h" | 22 #include "content/common/dom_storage/dom_storage_map.h" |
| 22 #include "content/common/dom_storage/dom_storage_types.h" | 23 #include "content/common/dom_storage/dom_storage_types.h" |
| 24 #include "content/public/browser/browser_main_runner.h" |
| 23 #include "storage/browser/database/database_util.h" | 25 #include "storage/browser/database/database_util.h" |
| 24 #include "storage/common/database/database_identifier.h" | 26 #include "storage/common/database/database_identifier.h" |
| 25 #include "storage/common/fileapi/file_system_util.h" | 27 #include "storage/common/fileapi/file_system_util.h" |
| 26 | 28 |
| 27 using storage::DatabaseUtil; | 29 using storage::DatabaseUtil; |
| 28 | 30 |
| 29 namespace content { | 31 namespace content { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 391 |
| 390 void DOMStorageArea::OnCommitTimer() { | 392 void DOMStorageArea::OnCommitTimer() { |
| 391 if (is_shutdown_) | 393 if (is_shutdown_) |
| 392 return; | 394 return; |
| 393 | 395 |
| 394 // It's possible that there is nothing to commit if an immediate | 396 // It's possible that there is nothing to commit if an immediate |
| 395 // commit occured after the timer was scheduled but before it fired. | 397 // commit occured after the timer was scheduled but before it fired. |
| 396 if (!commit_batch_) | 398 if (!commit_batch_) |
| 397 return; | 399 return; |
| 398 | 400 |
| 401 // Don't mind the double counting of the few that are deferred compared |
| 402 // to the masses that aren't. |
| 403 // TODO: edit histogram.xml |
| 404 bool defer_commit = IsBrowserStartingUp(); |
| 405 UMA_HISTOGRAM_BOOLEAN("LocalStorage.Commit", !defer_commit); |
| 406 if (defer_commit) { |
| 407 task_runner_->PostDelayedTask( |
| 408 FROM_HERE, base::Bind(&DOMStorageArea::OnCommitTimer, this), |
| 409 base::TimeDelta::FromSeconds(base::RandInt(5, 15))); |
| 410 return; |
| 411 } |
| 412 |
| 399 PostCommitTask(); | 413 PostCommitTask(); |
| 400 } | 414 } |
| 401 | 415 |
| 402 void DOMStorageArea::PostCommitTask() { | 416 void DOMStorageArea::PostCommitTask() { |
| 403 if (is_shutdown_ || !commit_batch_) | 417 if (is_shutdown_ || !commit_batch_) |
| 404 return; | 418 return; |
| 405 | 419 |
| 406 DCHECK(backing_.get()); | 420 DCHECK(backing_.get()); |
| 407 | 421 |
| 408 commit_rate_limiter_.add_samples(1); | 422 commit_rate_limiter_.add_samples(1); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 commit_batch_->clear_all_first, | 470 commit_batch_->clear_all_first, |
| 457 commit_batch_->changed_values); | 471 commit_batch_->changed_values); |
| 458 DCHECK(success); | 472 DCHECK(success); |
| 459 } | 473 } |
| 460 commit_batch_.reset(); | 474 commit_batch_.reset(); |
| 461 backing_.reset(); | 475 backing_.reset(); |
| 462 session_storage_backing_ = NULL; | 476 session_storage_backing_ = NULL; |
| 463 } | 477 } |
| 464 | 478 |
| 465 } // namespace content | 479 } // namespace content |
| OLD | NEW |