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

Side by Side Diff: base/files/important_file_writer.cc

Issue 988693005: Chromium roll (https://codereview.chromium.org/976353002) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fixed bad android build patch Created 5 years, 9 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
« no previous file with comments | « base/files/file_path_watcher_win.cc ('k') | base/json/json_file_value_serializer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/debug/alias.h"
13 #include "base/files/file.h" 14 #include "base/files/file.h"
14 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h"
19 #include "base/task_runner.h" 21 #include "base/task_runner.h"
20 #include "base/task_runner_util.h" 22 #include "base/task_runner_util.h"
21 #include "base/threading/thread.h" 23 #include "base/threading/thread.h"
22 #include "base/time/time.h" 24 #include "base/time/time.h"
23 25
24 namespace base { 26 namespace base {
25 27
26 namespace { 28 namespace {
27 29
28 const int kDefaultCommitIntervalMs = 10000; 30 const int kDefaultCommitIntervalMs = 10000;
(...skipping 18 matching lines...) Expand all
47 TEMP_FILE_FAILURE_MAX); 49 TEMP_FILE_FAILURE_MAX);
48 DPLOG(WARNING) << "temp file failure: " << path.value().c_str() 50 DPLOG(WARNING) << "temp file failure: " << path.value().c_str()
49 << " : " << message; 51 << " : " << message;
50 } 52 }
51 53
52 } // namespace 54 } // namespace
53 55
54 // static 56 // static
55 bool ImportantFileWriter::WriteFileAtomically(const FilePath& path, 57 bool ImportantFileWriter::WriteFileAtomically(const FilePath& path,
56 const std::string& data) { 58 const std::string& data) {
59 #if defined(OS_CHROMEOS)
60 // On Chrome OS, chrome gets killed when it cannot finish shutdown quickly,
61 // and this function seems to be one of the slowest shutdown steps.
62 // Include some info to the report for investigation. crbug.com/418627
63 // TODO(hashimoto): Remove this.
64 struct {
65 size_t data_size;
66 char path[128];
67 } file_info;
68 file_info.data_size = data.size();
69 base::strlcpy(file_info.path, path.value().c_str(),
70 arraysize(file_info.path));
71 base::debug::Alias(&file_info);
72 #endif
57 // Write the data to a temp file then rename to avoid data loss if we crash 73 // Write the data to a temp file then rename to avoid data loss if we crash
58 // while writing the file. Ensure that the temp file is on the same volume 74 // while writing the file. Ensure that the temp file is on the same volume
59 // as target file, so it can be moved in one step, and that the temp file 75 // as target file, so it can be moved in one step, and that the temp file
60 // is securely created. 76 // is securely created.
61 FilePath tmp_file_path; 77 FilePath tmp_file_path;
62 if (!base::CreateTemporaryFileInDir(path.DirName(), &tmp_file_path)) { 78 if (!base::CreateTemporaryFileInDir(path.DirName(), &tmp_file_path)) {
63 LogFailure(path, FAILED_CREATING, "could not create temporary file"); 79 LogFailure(path, FAILED_CREATING, "could not create temporary file");
64 return false; 80 return false;
65 } 81 }
66 82
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 213
198 void ImportantFileWriter::ForwardSuccessfulWrite(bool result) { 214 void ImportantFileWriter::ForwardSuccessfulWrite(bool result) {
199 DCHECK(CalledOnValidThread()); 215 DCHECK(CalledOnValidThread());
200 if (result && !on_next_successful_write_.is_null()) { 216 if (result && !on_next_successful_write_.is_null()) {
201 on_next_successful_write_.Run(); 217 on_next_successful_write_.Run();
202 on_next_successful_write_.Reset(); 218 on_next_successful_write_.Reset();
203 } 219 }
204 } 220 }
205 221
206 } // namespace base 222 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_watcher_win.cc ('k') | base/json/json_file_value_serializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698