OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/files/important_file_writer.h" | 5 #include "base/files/important_file_writer.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/critical_closure.h" | 12 #include "base/critical_closure.h" |
13 #include "base/files/file.h" | 13 #include "base/files/file.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/task_runner.h" | 19 #include "base/task_runner.h" |
20 #include "base/task_runner_util.h" | 20 #include "base/task_runner_util.h" |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const int kDefaultCommitIntervalMs = 10000; | 28 const int kDefaultCommitIntervalMs = 10000; |
29 | 29 |
| 30 // This enum is used to define the buckets for an enumerated UMA histogram. |
| 31 // Hence, |
| 32 // (a) existing enumerated constants should never be deleted or reordered, and |
| 33 // (b) new constants should only be appended at the end of the enumeration. |
30 enum TempFileFailure { | 34 enum TempFileFailure { |
31 FAILED_CREATING, | 35 FAILED_CREATING, |
32 FAILED_OPENING, | 36 FAILED_OPENING, |
33 FAILED_CLOSING, | 37 FAILED_CLOSING, // Unused. |
34 FAILED_WRITING, | 38 FAILED_WRITING, |
35 FAILED_RENAMING, | 39 FAILED_RENAMING, |
36 FAILED_FLUSHING, | 40 FAILED_FLUSHING, |
37 TEMP_FILE_FAILURE_MAX | 41 TEMP_FILE_FAILURE_MAX |
38 }; | 42 }; |
39 | 43 |
40 void LogFailure(const FilePath& path, TempFileFailure failure_code, | 44 void LogFailure(const FilePath& path, TempFileFailure failure_code, |
41 const std::string& message) { | 45 const std::string& message) { |
42 UMA_HISTOGRAM_ENUMERATION("ImportantFile.TempFileFailures", failure_code, | 46 UMA_HISTOGRAM_ENUMERATION("ImportantFile.TempFileFailures", failure_code, |
43 TEMP_FILE_FAILURE_MAX); | 47 TEMP_FILE_FAILURE_MAX); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 197 |
194 void ImportantFileWriter::ForwardSuccessfulWrite(bool result) { | 198 void ImportantFileWriter::ForwardSuccessfulWrite(bool result) { |
195 DCHECK(CalledOnValidThread()); | 199 DCHECK(CalledOnValidThread()); |
196 if (result && !on_next_successful_write_.is_null()) { | 200 if (result && !on_next_successful_write_.is_null()) { |
197 on_next_successful_write_.Run(); | 201 on_next_successful_write_.Run(); |
198 on_next_successful_write_.Reset(); | 202 on_next_successful_write_.Reset(); |
199 } | 203 } |
200 } | 204 } |
201 | 205 |
202 } // namespace base | 206 } // namespace base |
OLD | NEW |