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 19 matching lines...) Expand all Loading... |
30 namespace content { | 30 namespace content { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Delay for a moment after a value is set in anticipation | 34 // Delay for a moment after a value is set in anticipation |
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 kMaxBytesPerHour = kPerStorageAreaQuota; |
41 const int kMaxCommitsPerHour = 6; | 41 const int kMaxCommitsPerHour = 60; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 bool DOMStorageArea::s_aggressive_flushing_enabled_ = false; | 45 bool DOMStorageArea::s_aggressive_flushing_enabled_ = false; |
46 | 46 |
47 DOMStorageArea::RateLimiter::RateLimiter(size_t desired_rate, | 47 DOMStorageArea::RateLimiter::RateLimiter(size_t desired_rate, |
48 base::TimeDelta time_quantum) | 48 base::TimeDelta time_quantum) |
49 : rate_(desired_rate), samples_(0), time_quantum_(time_quantum) { | 49 : rate_(desired_rate), samples_(0), time_quantum_(time_quantum) { |
50 DCHECK_GT(desired_rate, 0ul); | 50 DCHECK_GT(desired_rate, 0ul); |
51 } | 51 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 : namespace_id_(kLocalStorageNamespaceId), | 102 : namespace_id_(kLocalStorageNamespaceId), |
103 origin_(origin), | 103 origin_(origin), |
104 directory_(directory), | 104 directory_(directory), |
105 task_runner_(task_runner), | 105 task_runner_(task_runner), |
106 map_(new DOMStorageMap(kPerStorageAreaQuota + | 106 map_(new DOMStorageMap(kPerStorageAreaQuota + |
107 kPerStorageAreaOverQuotaAllowance)), | 107 kPerStorageAreaOverQuotaAllowance)), |
108 is_initial_import_done_(true), | 108 is_initial_import_done_(true), |
109 is_shutdown_(false), | 109 is_shutdown_(false), |
110 commit_batches_in_flight_(0), | 110 commit_batches_in_flight_(0), |
111 start_time_(base::TimeTicks::Now()), | 111 start_time_(base::TimeTicks::Now()), |
112 data_rate_limiter_(kMaxBytesPerDay, base::TimeDelta::FromHours(24)), | 112 data_rate_limiter_(kMaxBytesPerHour, base::TimeDelta::FromHours(1)), |
113 commit_rate_limiter_(kMaxCommitsPerHour, base::TimeDelta::FromHours(1)) { | 113 commit_rate_limiter_(kMaxCommitsPerHour, base::TimeDelta::FromHours(1)) { |
114 if (!directory.empty()) { | 114 if (!directory.empty()) { |
115 base::FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_)); | 115 base::FilePath path = directory.Append(DatabaseFileNameFromOrigin(origin_)); |
116 backing_.reset(new LocalStorageDatabaseAdapter(path)); | 116 backing_.reset(new LocalStorageDatabaseAdapter(path)); |
117 is_initial_import_done_ = false; | 117 is_initial_import_done_ = false; |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 DOMStorageArea::DOMStorageArea(int64 namespace_id, | 121 DOMStorageArea::DOMStorageArea(int64 namespace_id, |
122 const std::string& persistent_namespace_id, | 122 const std::string& persistent_namespace_id, |
123 const GURL& origin, | 123 const GURL& origin, |
124 SessionStorageDatabase* session_storage_backing, | 124 SessionStorageDatabase* session_storage_backing, |
125 DOMStorageTaskRunner* task_runner) | 125 DOMStorageTaskRunner* task_runner) |
126 : namespace_id_(namespace_id), | 126 : namespace_id_(namespace_id), |
127 persistent_namespace_id_(persistent_namespace_id), | 127 persistent_namespace_id_(persistent_namespace_id), |
128 origin_(origin), | 128 origin_(origin), |
129 task_runner_(task_runner), | 129 task_runner_(task_runner), |
130 map_(new DOMStorageMap(kPerStorageAreaQuota + | 130 map_(new DOMStorageMap(kPerStorageAreaQuota + |
131 kPerStorageAreaOverQuotaAllowance)), | 131 kPerStorageAreaOverQuotaAllowance)), |
132 session_storage_backing_(session_storage_backing), | 132 session_storage_backing_(session_storage_backing), |
133 is_initial_import_done_(true), | 133 is_initial_import_done_(true), |
134 is_shutdown_(false), | 134 is_shutdown_(false), |
135 commit_batches_in_flight_(0), | 135 commit_batches_in_flight_(0), |
136 start_time_(base::TimeTicks::Now()), | 136 start_time_(base::TimeTicks::Now()), |
137 data_rate_limiter_(kMaxBytesPerDay, base::TimeDelta::FromHours(24)), | 137 data_rate_limiter_(kMaxBytesPerHour, base::TimeDelta::FromHours(1)), |
138 commit_rate_limiter_(kMaxCommitsPerHour, base::TimeDelta::FromHours(1)) { | 138 commit_rate_limiter_(kMaxCommitsPerHour, base::TimeDelta::FromHours(1)) { |
139 DCHECK(namespace_id != kLocalStorageNamespaceId); | 139 DCHECK(namespace_id != kLocalStorageNamespaceId); |
140 if (session_storage_backing) { | 140 if (session_storage_backing) { |
141 backing_.reset(new SessionStorageDatabaseAdapter( | 141 backing_.reset(new SessionStorageDatabaseAdapter( |
142 session_storage_backing, persistent_namespace_id, origin)); | 142 session_storage_backing, persistent_namespace_id, origin)); |
143 is_initial_import_done_ = false; | 143 is_initial_import_done_ = false; |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 DOMStorageArea::~DOMStorageArea() { | 147 DOMStorageArea::~DOMStorageArea() { |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 commit_batch_->clear_all_first, | 475 commit_batch_->clear_all_first, |
476 commit_batch_->changed_values); | 476 commit_batch_->changed_values); |
477 DCHECK(success); | 477 DCHECK(success); |
478 } | 478 } |
479 commit_batch_.reset(); | 479 commit_batch_.reset(); |
480 backing_.reset(); | 480 backing_.reset(); |
481 session_storage_backing_ = NULL; | 481 session_storage_backing_ = NULL; |
482 } | 482 } |
483 | 483 |
484 } // namespace content | 484 } // namespace content |
OLD | NEW |