Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: content/browser/dom_storage/dom_storage_area.cc

Issue 1138843002: localStorage: Aggressively flush to disk for Android WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2357
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 // of other values being set, so changes are batched. 34 // of other values being set, so changes are batched.
35 const int kCommitDefaultDelaySecs = 5; 35 const int kCommitDefaultDelaySecs = 5;
36 36
37 // To avoid excessive IO we apply limits to the amount of data being written 37 // To avoid excessive IO we apply limits to the amount of data being written
38 // and the frequency of writes. The specific values used are somewhat arbitrary. 38 // and the frequency of writes. The specific values used are somewhat arbitrary.
39 const int kMaxBytesPerDay = kPerStorageAreaQuota * 2; 39 const int kMaxBytesPerDay = kPerStorageAreaQuota * 2;
40 const int kMaxCommitsPerHour = 6; 40 const int kMaxCommitsPerHour = 6;
41 41
42 } // namespace 42 } // namespace
43 43
44 bool DOMStorageArea::s_aggressive_flushing_enabled_ = false;
45
44 DOMStorageArea::RateLimiter::RateLimiter(size_t desired_rate, 46 DOMStorageArea::RateLimiter::RateLimiter(size_t desired_rate,
45 base::TimeDelta time_quantum) 47 base::TimeDelta time_quantum)
46 : rate_(desired_rate), samples_(0), time_quantum_(time_quantum) { 48 : rate_(desired_rate), samples_(0), time_quantum_(time_quantum) {
47 DCHECK_GT(desired_rate, 0ul); 49 DCHECK_GT(desired_rate, 0ul);
48 } 50 }
49 51
50 base::TimeDelta DOMStorageArea::RateLimiter::ComputeTimeNeeded() const { 52 base::TimeDelta DOMStorageArea::RateLimiter::ComputeTimeNeeded() const {
51 return time_quantum_ * (samples_ / rate_); 53 return time_quantum_ * (samples_ / rate_);
52 } 54 }
53 55
(...skipping 28 matching lines...) Expand all
82 } 84 }
83 85
84 // static 86 // static
85 GURL DOMStorageArea::OriginFromDatabaseFileName(const base::FilePath& name) { 87 GURL DOMStorageArea::OriginFromDatabaseFileName(const base::FilePath& name) {
86 DCHECK(name.MatchesExtension(kDatabaseFileExtension)); 88 DCHECK(name.MatchesExtension(kDatabaseFileExtension));
87 std::string origin_id = 89 std::string origin_id =
88 name.BaseName().RemoveExtension().MaybeAsASCII(); 90 name.BaseName().RemoveExtension().MaybeAsASCII();
89 return storage::GetOriginFromIdentifier(origin_id); 91 return storage::GetOriginFromIdentifier(origin_id);
90 } 92 }
91 93
94 void DOMStorageArea::EnableAggressiveCommitDelay() {
95 s_aggressive_flushing_enabled_ = true;
96 }
97
92 DOMStorageArea::DOMStorageArea(const GURL& origin, 98 DOMStorageArea::DOMStorageArea(const GURL& origin,
93 const base::FilePath& directory, 99 const base::FilePath& directory,
94 DOMStorageTaskRunner* task_runner) 100 DOMStorageTaskRunner* task_runner)
95 : namespace_id_(kLocalStorageNamespaceId), 101 : namespace_id_(kLocalStorageNamespaceId),
96 origin_(origin), 102 origin_(origin),
97 directory_(directory), 103 directory_(directory),
98 task_runner_(task_runner), 104 task_runner_(task_runner),
99 map_(new DOMStorageMap(kPerStorageAreaQuota + 105 map_(new DOMStorageMap(kPerStorageAreaQuota +
100 kPerStorageAreaOverQuotaAllowance)), 106 kPerStorageAreaOverQuotaAllowance)),
101 is_initial_import_done_(true), 107 is_initial_import_done_(true),
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 if (!commit_batches_in_flight_) { 377 if (!commit_batches_in_flight_) {
372 task_runner_->PostDelayedTask( 378 task_runner_->PostDelayedTask(
373 FROM_HERE, base::Bind(&DOMStorageArea::OnCommitTimer, this), 379 FROM_HERE, base::Bind(&DOMStorageArea::OnCommitTimer, this),
374 ComputeCommitDelay()); 380 ComputeCommitDelay());
375 } 381 }
376 } 382 }
377 return commit_batch_.get(); 383 return commit_batch_.get();
378 } 384 }
379 385
380 base::TimeDelta DOMStorageArea::ComputeCommitDelay() const { 386 base::TimeDelta DOMStorageArea::ComputeCommitDelay() const {
387 if (s_aggressive_flushing_enabled_)
388 return base::TimeDelta::FromSeconds(1);
389
381 base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; 390 base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_;
382 base::TimeDelta delay = std::max( 391 base::TimeDelta delay = std::max(
383 base::TimeDelta::FromSeconds(kCommitDefaultDelaySecs), 392 base::TimeDelta::FromSeconds(kCommitDefaultDelaySecs),
384 std::max(commit_rate_limiter_.ComputeDelayNeeded(elapsed_time), 393 std::max(commit_rate_limiter_.ComputeDelayNeeded(elapsed_time),
385 data_rate_limiter_.ComputeDelayNeeded(elapsed_time))); 394 data_rate_limiter_.ComputeDelayNeeded(elapsed_time)));
386 UMA_HISTOGRAM_LONG_TIMES("LocalStorage.CommitDelay", delay); 395 UMA_HISTOGRAM_LONG_TIMES("LocalStorage.CommitDelay", delay);
387 return delay; 396 return delay;
388 } 397 }
389 398
390 void DOMStorageArea::OnCommitTimer() { 399 void DOMStorageArea::OnCommitTimer() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 commit_batch_->clear_all_first, 465 commit_batch_->clear_all_first,
457 commit_batch_->changed_values); 466 commit_batch_->changed_values);
458 DCHECK(success); 467 DCHECK(success);
459 } 468 }
460 commit_batch_.reset(); 469 commit_batch_.reset();
461 backing_.reset(); 470 backing_.reset();
462 session_storage_backing_ = NULL; 471 session_storage_backing_ = NULL;
463 } 472 }
464 473
465 } // namespace content 474 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_area.h ('k') | content/public/common/content_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698