Chromium Code Reviews| Index: chrome/common/important_file_writer.cc |
| diff --git a/chrome/common/important_file_writer.cc b/chrome/common/important_file_writer.cc |
| index f5c5fc115c1dcee81bc86f71d7c32235b8264c76..a73a1b580df9a2bae2f722efc56367a21552da9a 100644 |
| --- a/chrome/common/important_file_writer.cc |
| +++ b/chrome/common/important_file_writer.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -12,16 +12,36 @@ |
| #include "base/file_util.h" |
| #include "base/logging.h" |
| #include "base/message_loop_proxy.h" |
| +#include "base/rand_util.h" |
| #include "base/string_number_conversions.h" |
| #include "base/task.h" |
| #include "base/threading/thread.h" |
| #include "base/time.h" |
| -using base::TimeDelta; |
| - |
| namespace { |
| -const int kDefaultCommitIntervalMs = 10000; |
| +base::TimeDelta EstimateDesiredCommitInterval() { |
| + // 2 seconds interval provides reasonable optimization by coalescing bursts of |
| + // writes yet this value is reasonably low to be safe. |
| + const int kSafeCommitIntervalMs = 2000; |
| + |
| + static int commit_interval = 0; |
| + if (commit_interval == 0) { |
| + commit_interval = kSafeCommitIntervalMs; |
| + |
| +#if !defined(OFFICIAL_BUILD) && !defined(GOOGLE_CHROME_BUILD) |
| + // For debugging purpose we may want to increase commit interval in order to |
| + // ease manifestation of bugs caused by some exit path failing to commit |
| + // pending writes (as in http://crosbug.com/13102). |
| + const int kDebugCommitIntervalMs = 60000; |
| + |
| + // Leave 50% chance to match behaviour of official build. |
| + if (base::RandInt(0, 1)) |
|
Paweł Hajdan Jr.
2011/03/21 13:27:43
I'm strongly against any randomness in this code.
|
| + commit_interval = kDebugCommitIntervalMs; |
| +#endif |
| + } |
| + return base::TimeDelta::FromMilliseconds(commit_interval); |
| +} |
| class WriteToDiskTask : public Task { |
| public: |
| @@ -82,8 +102,7 @@ ImportantFileWriter::ImportantFileWriter( |
| : path_(path), |
| file_message_loop_proxy_(file_message_loop_proxy), |
| serializer_(NULL), |
| - commit_interval_(TimeDelta::FromMilliseconds( |
| - kDefaultCommitIntervalMs)) { |
| + commit_interval_(EstimateDesiredCommitInterval()) { |
| DCHECK(CalledOnValidThread()); |
| DCHECK(file_message_loop_proxy_.get()); |
| } |