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" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // of other values being set, so changes are batched. | 35 // of other values being set, so changes are batched. |
36 const int kCommitDefaultDelaySecs = 5; | 36 const int kCommitDefaultDelaySecs = 5; |
37 | 37 |
38 // To avoid excessive IO we apply limits to the amount of data being written | 38 // To avoid excessive IO we apply limits to the amount of data being written |
39 // and the frequency of writes. The specific values used are somewhat arbitrary. | 39 // and the frequency of writes. The specific values used are somewhat arbitrary. |
40 const int kMaxBytesPerDay = kPerStorageAreaQuota * 2; | 40 const int kMaxBytesPerDay = kPerStorageAreaQuota * 2; |
41 const int kMaxCommitsPerHour = 6; | 41 const int kMaxCommitsPerHour = 6; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
| 45 bool DOMStorageArea::s_aggressive_flushing_enabled_ = false; |
| 46 |
45 DOMStorageArea::RateLimiter::RateLimiter(size_t desired_rate, | 47 DOMStorageArea::RateLimiter::RateLimiter(size_t desired_rate, |
46 base::TimeDelta time_quantum) | 48 base::TimeDelta time_quantum) |
47 : rate_(desired_rate), samples_(0), time_quantum_(time_quantum) { | 49 : rate_(desired_rate), samples_(0), time_quantum_(time_quantum) { |
48 DCHECK_GT(desired_rate, 0ul); | 50 DCHECK_GT(desired_rate, 0ul); |
49 } | 51 } |
50 | 52 |
51 base::TimeDelta DOMStorageArea::RateLimiter::ComputeTimeNeeded() const { | 53 base::TimeDelta DOMStorageArea::RateLimiter::ComputeTimeNeeded() const { |
52 return time_quantum_ * (samples_ / rate_); | 54 return time_quantum_ * (samples_ / rate_); |
53 } | 55 } |
54 | 56 |
(...skipping 28 matching lines...) Expand all Loading... |
83 } | 85 } |
84 | 86 |
85 // static | 87 // static |
86 GURL DOMStorageArea::OriginFromDatabaseFileName(const base::FilePath& name) { | 88 GURL DOMStorageArea::OriginFromDatabaseFileName(const base::FilePath& name) { |
87 DCHECK(name.MatchesExtension(kDatabaseFileExtension)); | 89 DCHECK(name.MatchesExtension(kDatabaseFileExtension)); |
88 std::string origin_id = | 90 std::string origin_id = |
89 name.BaseName().RemoveExtension().MaybeAsASCII(); | 91 name.BaseName().RemoveExtension().MaybeAsASCII(); |
90 return storage::GetOriginFromIdentifier(origin_id); | 92 return storage::GetOriginFromIdentifier(origin_id); |
91 } | 93 } |
92 | 94 |
| 95 void DOMStorageArea::EnableAggressiveCommitDelay() { |
| 96 s_aggressive_flushing_enabled_ = true; |
| 97 } |
| 98 |
93 DOMStorageArea::DOMStorageArea(const GURL& origin, | 99 DOMStorageArea::DOMStorageArea(const GURL& origin, |
94 const base::FilePath& directory, | 100 const base::FilePath& directory, |
95 DOMStorageTaskRunner* task_runner) | 101 DOMStorageTaskRunner* task_runner) |
96 : namespace_id_(kLocalStorageNamespaceId), | 102 : namespace_id_(kLocalStorageNamespaceId), |
97 origin_(origin), | 103 origin_(origin), |
98 directory_(directory), | 104 directory_(directory), |
99 task_runner_(task_runner), | 105 task_runner_(task_runner), |
100 map_(new DOMStorageMap(kPerStorageAreaQuota + | 106 map_(new DOMStorageMap(kPerStorageAreaQuota + |
101 kPerStorageAreaOverQuotaAllowance)), | 107 kPerStorageAreaOverQuotaAllowance)), |
102 is_initial_import_done_(true), | 108 is_initial_import_done_(true), |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 // started after the commits have happened. | 387 // started after the commits have happened. |
382 if (commit_batches_in_flight_) | 388 if (commit_batches_in_flight_) |
383 return; | 389 return; |
384 | 390 |
385 task_runner_->PostDelayedTask( | 391 task_runner_->PostDelayedTask( |
386 FROM_HERE, base::Bind(&DOMStorageArea::OnCommitTimer, this), | 392 FROM_HERE, base::Bind(&DOMStorageArea::OnCommitTimer, this), |
387 ComputeCommitDelay()); | 393 ComputeCommitDelay()); |
388 } | 394 } |
389 | 395 |
390 base::TimeDelta DOMStorageArea::ComputeCommitDelay() const { | 396 base::TimeDelta DOMStorageArea::ComputeCommitDelay() const { |
| 397 if (s_aggressive_flushing_enabled_) |
| 398 return base::TimeDelta::FromSeconds(1); |
| 399 |
391 base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; | 400 base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; |
392 base::TimeDelta delay = std::max( | 401 base::TimeDelta delay = std::max( |
393 base::TimeDelta::FromSeconds(kCommitDefaultDelaySecs), | 402 base::TimeDelta::FromSeconds(kCommitDefaultDelaySecs), |
394 std::max(commit_rate_limiter_.ComputeDelayNeeded(elapsed_time), | 403 std::max(commit_rate_limiter_.ComputeDelayNeeded(elapsed_time), |
395 data_rate_limiter_.ComputeDelayNeeded(elapsed_time))); | 404 data_rate_limiter_.ComputeDelayNeeded(elapsed_time))); |
396 UMA_HISTOGRAM_LONG_TIMES("LocalStorage.CommitDelay", delay); | 405 UMA_HISTOGRAM_LONG_TIMES("LocalStorage.CommitDelay", delay); |
397 return delay; | 406 return delay; |
398 } | 407 } |
399 | 408 |
400 void DOMStorageArea::OnCommitTimer() { | 409 void DOMStorageArea::OnCommitTimer() { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 commit_batch_->clear_all_first, | 475 commit_batch_->clear_all_first, |
467 commit_batch_->changed_values); | 476 commit_batch_->changed_values); |
468 DCHECK(success); | 477 DCHECK(success); |
469 } | 478 } |
470 commit_batch_.reset(); | 479 commit_batch_.reset(); |
471 backing_.reset(); | 480 backing_.reset(); |
472 session_storage_backing_ = NULL; | 481 session_storage_backing_ = NULL; |
473 } | 482 } |
474 | 483 |
475 } // namespace content | 484 } // namespace content |
OLD | NEW |