Chromium Code Reviews| 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 "chrome/common/important_file_writer.h" | 5 #include "chrome/common/important_file_writer.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 } | 43 } |
| 44 | 44 |
| 45 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE; | 45 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE; |
| 46 base::PlatformFile tmp_file = | 46 base::PlatformFile tmp_file = |
| 47 base::CreatePlatformFile(tmp_file_path, flags, NULL, NULL); | 47 base::CreatePlatformFile(tmp_file_path, flags, NULL, NULL); |
| 48 if (tmp_file == base::kInvalidPlatformFileValue) { | 48 if (tmp_file == base::kInvalidPlatformFileValue) { |
| 49 LogFailure(FAILED_OPENING, "could not open temporary file"); | 49 LogFailure(FAILED_OPENING, "could not open temporary file"); |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 | 52 |
| 53 DCHECK_LE(data_.length(), static_cast<size_t>(kint32max)); | 53 // If happens in the wild something really bad is likely to be going on. |
|
Mark Mentovai
2011/11/05 00:49:02
If happens -> if this happens?
Scott Hess - ex-Googler
2011/11/08 18:47:51
Done.
| |
| 54 CHECK_LE(data_.length(), static_cast<size_t>(kint32max)); | |
| 54 int bytes_written = base::WritePlatformFile( | 55 int bytes_written = base::WritePlatformFile( |
| 55 tmp_file, 0, data_.data(), static_cast<int>(data_.length())); | 56 tmp_file, 0, data_.data(), static_cast<int>(data_.length())); |
| 56 base::FlushPlatformFile(tmp_file); // Ignore return value. | 57 base::FlushPlatformFile(tmp_file); // Ignore return value. |
| 57 | 58 |
| 58 if (!base::ClosePlatformFile(tmp_file)) { | 59 if (!base::ClosePlatformFile(tmp_file)) { |
| 59 LogFailure(FAILED_CLOSING, "failed to close temporary file"); | 60 LogFailure(FAILED_CLOSING, "failed to close temporary file"); |
| 60 file_util::Delete(tmp_file_path, false); | 61 file_util::Delete(tmp_file_path, false); |
| 61 return; | 62 return; |
| 62 } | 63 } |
| 63 | 64 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 DCHECK(serializer_); | 162 DCHECK(serializer_); |
| 162 std::string data; | 163 std::string data; |
| 163 if (serializer_->SerializeData(&data)) { | 164 if (serializer_->SerializeData(&data)) { |
| 164 WriteNow(data); | 165 WriteNow(data); |
| 165 } else { | 166 } else { |
| 166 DLOG(WARNING) << "failed to serialize data to be saved in " | 167 DLOG(WARNING) << "failed to serialize data to be saved in " |
| 167 << path_.value(); | 168 << path_.value(); |
| 168 } | 169 } |
| 169 serializer_ = NULL; | 170 serializer_ = NULL; |
| 170 } | 171 } |
| OLD | NEW |