OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/dom_storage/dom_storage_area.h" | 5 #include "webkit/dom_storage/dom_storage_area.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" |
10 #include "base/time.h" | 11 #include "base/time.h" |
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
12 #include "webkit/base/file_path_string_conversions.h" | 13 #include "webkit/base/file_path_string_conversions.h" |
13 #include "webkit/database/database_util.h" | 14 #include "webkit/database/database_util.h" |
14 #include "webkit/dom_storage/dom_storage_map.h" | 15 #include "webkit/dom_storage/dom_storage_map.h" |
15 #include "webkit/dom_storage/dom_storage_namespace.h" | 16 #include "webkit/dom_storage/dom_storage_namespace.h" |
16 #include "webkit/dom_storage/dom_storage_task_runner.h" | 17 #include "webkit/dom_storage/dom_storage_task_runner.h" |
17 #include "webkit/dom_storage/dom_storage_types.h" | 18 #include "webkit/dom_storage/dom_storage_types.h" |
18 #include "webkit/dom_storage/local_storage_database_adapter.h" | 19 #include "webkit/dom_storage/local_storage_database_adapter.h" |
19 #include "webkit/dom_storage/session_storage_database.h" | 20 #include "webkit/dom_storage/session_storage_database.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 base::Bind(&DomStorageArea::ShutdownInCommitSequence, this)); | 271 base::Bind(&DomStorageArea::ShutdownInCommitSequence, this)); |
271 DCHECK(success); | 272 DCHECK(success); |
272 } | 273 } |
273 | 274 |
274 void DomStorageArea::InitialImportIfNeeded() { | 275 void DomStorageArea::InitialImportIfNeeded() { |
275 if (is_initial_import_done_) | 276 if (is_initial_import_done_) |
276 return; | 277 return; |
277 | 278 |
278 DCHECK(backing_.get()); | 279 DCHECK(backing_.get()); |
279 | 280 |
| 281 base::TimeTicks before = base::TimeTicks::Now(); |
280 ValuesMap initial_values; | 282 ValuesMap initial_values; |
281 backing_->ReadAllValues(&initial_values); | 283 backing_->ReadAllValues(&initial_values); |
282 map_->SwapValues(&initial_values); | 284 map_->SwapValues(&initial_values); |
283 is_initial_import_done_ = true; | 285 is_initial_import_done_ = true; |
| 286 base::TimeDelta time_to_import = base::TimeTicks::Now() - before; |
| 287 UMA_HISTOGRAM_TIMES("LocalStorage.BrowserTimeToPrimeLocalStorage", |
| 288 time_to_import); |
| 289 |
| 290 size_t local_storage_size_kb = map_->bytes_used() / 1024; |
| 291 // Track localStorage size, from 0-6MB. Note that the maximum size should be |
| 292 // 5MB, but we add some slop since we want to make sure the max size is always |
| 293 // above what we see in practice, since histograms can't change. |
| 294 UMA_HISTOGRAM_CUSTOM_COUNTS("LocalStorage.BrowserLocalStorageSizeInKB", |
| 295 local_storage_size_kb, |
| 296 0, 6 * 1024, 50); |
| 297 if (local_storage_size_kb < 100) { |
| 298 UMA_HISTOGRAM_TIMES( |
| 299 "LocalStorage.BrowserTimeToPrimeLocalStorageUnder100KB", |
| 300 time_to_import); |
| 301 } else if (local_storage_size_kb < 1000) { |
| 302 UMA_HISTOGRAM_TIMES( |
| 303 "LocalStorage.BrowserTimeToPrimeLocalStorage100KBTo1MB", |
| 304 time_to_import); |
| 305 } else { |
| 306 UMA_HISTOGRAM_TIMES( |
| 307 "LocalStorage.BrowserTimeToPrimeLocalStorage1MBTo5MB", |
| 308 time_to_import); |
| 309 } |
284 } | 310 } |
285 | 311 |
286 DomStorageArea::CommitBatch* DomStorageArea::CreateCommitBatchIfNeeded() { | 312 DomStorageArea::CommitBatch* DomStorageArea::CreateCommitBatchIfNeeded() { |
287 DCHECK(!is_shutdown_); | 313 DCHECK(!is_shutdown_); |
288 if (!commit_batch_.get()) { | 314 if (!commit_batch_.get()) { |
289 commit_batch_.reset(new CommitBatch()); | 315 commit_batch_.reset(new CommitBatch()); |
290 | 316 |
291 // Start a timer to commit any changes that accrue in the batch, but only if | 317 // Start a timer to commit any changes that accrue in the batch, but only if |
292 // no commits are currently in flight. In that case the timer will be | 318 // no commits are currently in flight. In that case the timer will be |
293 // started after the commits have happened. | 319 // started after the commits have happened. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 commit_batch_->clear_all_first, | 386 commit_batch_->clear_all_first, |
361 commit_batch_->changed_values); | 387 commit_batch_->changed_values); |
362 DCHECK(success); | 388 DCHECK(success); |
363 } | 389 } |
364 commit_batch_.reset(); | 390 commit_batch_.reset(); |
365 backing_.reset(); | 391 backing_.reset(); |
366 session_storage_backing_ = NULL; | 392 session_storage_backing_ = NULL; |
367 } | 393 } |
368 | 394 |
369 } // namespace dom_storage | 395 } // namespace dom_storage |
OLD | NEW |