| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This file contains the code to apply a Courgette patch. | 5 // This file contains the code to apply a Courgette patch. |
| 6 | 6 |
| 7 #include "courgette/ensemble.h" | 7 #include "courgette/ensemble.h" |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 correction, | 213 correction, |
| 214 corrected_elements, | 214 corrected_elements, |
| 215 &corrected_elements_storage_); | 215 &corrected_elements_storage_); |
| 216 } | 216 } |
| 217 | 217 |
| 218 Status EnsemblePatchApplication::TransformDown( | 218 Status EnsemblePatchApplication::TransformDown( |
| 219 SourceStreamSet* transformed_elements, | 219 SourceStreamSet* transformed_elements, |
| 220 SinkStream* basic_elements) { | 220 SinkStream* basic_elements) { |
| 221 // Construct blob of original input followed by reformed elements. | 221 // Construct blob of original input followed by reformed elements. |
| 222 | 222 |
| 223 basic_elements->Reserve(final_patch_input_size_prediction_); | 223 if (!basic_elements->Reserve(final_patch_input_size_prediction_)) { |
| 224 return C_STREAM_ERROR; |
| 225 } |
| 224 | 226 |
| 225 // The original input: | 227 // The original input: |
| 226 basic_elements->Write(base_region_.start(), base_region_.length()); | 228 if (!basic_elements->Write(base_region_.start(), base_region_.length())) |
| 229 return C_STREAM_ERROR; |
| 227 | 230 |
| 228 for (size_t i = 0; i < patchers_.size(); ++i) { | 231 for (size_t i = 0; i < patchers_.size(); ++i) { |
| 229 SourceStreamSet single_corrected_element; | 232 SourceStreamSet single_corrected_element; |
| 230 if (!transformed_elements->ReadSet(&single_corrected_element)) | 233 if (!transformed_elements->ReadSet(&single_corrected_element)) |
| 231 return C_STREAM_ERROR; | 234 return C_STREAM_ERROR; |
| 232 Status status = patchers_[i]->Reform(&single_corrected_element, | 235 Status status = patchers_[i]->Reform(&single_corrected_element, |
| 233 basic_elements); | 236 basic_elements); |
| 234 if (status != C_OK) | 237 if (status != C_OK) |
| 235 return status; | 238 return status; |
| 236 if (!single_corrected_element.Empty()) | 239 if (!single_corrected_element.Empty()) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 static_cast<int>(new_sink_stream.Length())); | 406 static_cast<int>(new_sink_stream.Length())); |
| 404 if (written == -1) | 407 if (written == -1) |
| 405 return C_WRITE_OPEN_ERROR; | 408 return C_WRITE_OPEN_ERROR; |
| 406 if (static_cast<size_t>(written) != new_sink_stream.Length()) | 409 if (static_cast<size_t>(written) != new_sink_stream.Length()) |
| 407 return C_WRITE_ERROR; | 410 return C_WRITE_ERROR; |
| 408 | 411 |
| 409 return C_OK; | 412 return C_OK; |
| 410 } | 413 } |
| 411 | 414 |
| 412 } // namespace | 415 } // namespace |
| OLD | NEW |