| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/component_updater/component_patcher.h" | 5 #include "chrome/browser/component_updater/component_patcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 JSONFileValueSerializer serializer(commands); | 26 JSONFileValueSerializer serializer(commands); |
| 27 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | 27 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); |
| 28 | 28 |
| 29 return (root.get() && root->IsType(base::Value::TYPE_LIST)) ? | 29 return (root.get() && root->IsType(base::Value::TYPE_LIST)) ? |
| 30 static_cast<base::ListValue*>(root.release()) : NULL; | 30 static_cast<base::ListValue*>(root.release()) : NULL; |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 namespace component_updater { |
| 35 | 36 |
| 36 // The patching support is not cross-platform at the moment. | 37 // The patching support is not cross-platform at the moment. |
| 37 ComponentPatcherCrossPlatform::ComponentPatcherCrossPlatform() {} | 38 ComponentPatcherCrossPlatform::ComponentPatcherCrossPlatform() {} |
| 38 | 39 |
| 39 ComponentUnpacker::Error ComponentPatcherCrossPlatform::Patch( | 40 ComponentUnpacker::Error ComponentPatcherCrossPlatform::Patch( |
| 40 PatchType patch_type, | 41 PatchType patch_type, |
| 41 const base::FilePath& input_file, | 42 const base::FilePath& input_file, |
| 42 const base::FilePath& patch_file, | 43 const base::FilePath& patch_file, |
| 43 const base::FilePath& output_file, | 44 const base::FilePath& output_file, |
| 44 int* error) { | 45 int* error) { |
| 45 return ComponentUnpacker::kDeltaUnsupportedCommand; | 46 return ComponentUnpacker::kDeltaUnsupportedCommand; |
| 46 } | 47 } |
| 47 | 48 |
| 48 | 49 |
| 49 // Takes the contents of a differential component update in input_dir | 50 // Takes the contents of a differential component update in input_dir |
| 50 // and produces the contents of a full component update in unpack_dir | 51 // and produces the contents of a full component update in unpack_dir |
| 51 // using input_abs_path_ files that the installer knows about. | 52 // using input_abs_path_ files that the installer knows about. |
| 52 ComponentUnpacker::Error DifferentialUpdatePatch( | 53 void DifferentialUpdatePatch( |
| 53 const base::FilePath& input_dir, | 54 const base::FilePath& input_dir, |
| 54 const base::FilePath& unpack_dir, | 55 const base::FilePath& unpack_dir, |
| 55 ComponentPatcher* patcher, | 56 ComponentPatcher* patcher, |
| 56 ComponentInstaller* installer, | 57 ComponentInstaller* installer, |
| 57 int* error) { | 58 base::Callback<void(ComponentUnpacker::Error, int)> callback) { |
| 58 *error = 0; | 59 int error = 0; |
| 59 scoped_ptr<base::ListValue> commands(ReadCommands(input_dir)); | 60 scoped_ptr<base::ListValue> commands(ReadCommands(input_dir)); |
| 60 if (!commands.get()) | 61 if (!commands.get()) { |
| 61 return ComponentUnpacker::kDeltaBadCommands; | 62 callback.Run(ComponentUnpacker::kDeltaBadCommands, error); |
| 63 return; |
| 64 } |
| 62 | 65 |
| 63 for (base::ValueVector::const_iterator command = commands->begin(), | 66 for (base::ValueVector::const_iterator command = commands->begin(), |
| 64 end = commands->end(); command != end; command++) { | 67 end = commands->end(); command != end; command++) { |
| 65 if (!(*command)->IsType(base::Value::TYPE_DICTIONARY)) | 68 if (!(*command)->IsType(base::Value::TYPE_DICTIONARY)) { |
| 66 return ComponentUnpacker::kDeltaBadCommands; | 69 callback.Run(ComponentUnpacker::kDeltaBadCommands, error); |
| 70 return; |
| 71 } |
| 67 base::DictionaryValue* command_args = | 72 base::DictionaryValue* command_args = |
| 68 static_cast<base::DictionaryValue*>(*command); | 73 static_cast<base::DictionaryValue*>(*command); |
| 69 scoped_ptr<DeltaUpdateOp> operation(CreateDeltaUpdateOp(command_args)); | 74 scoped_ptr<DeltaUpdateOp> operation(CreateDeltaUpdateOp(command_args)); |
| 70 if (!operation) | 75 if (!operation) { |
| 71 return ComponentUnpacker::kDeltaUnsupportedCommand; | 76 callback.Run(ComponentUnpacker::kDeltaUnsupportedCommand, error); |
| 77 return; |
| 78 } |
| 72 | 79 |
| 73 ComponentUnpacker::Error result = operation->Run( | 80 ComponentUnpacker::Error result = operation->Run( |
| 74 command_args, input_dir, unpack_dir, patcher, installer, error); | 81 command_args, input_dir, unpack_dir, patcher, installer, &error); |
| 75 if (result != ComponentUnpacker::kNone) | 82 if (result != ComponentUnpacker::kNone) { |
| 76 return result; | 83 callback.Run(result, error); |
| 84 return; |
| 85 } |
| 77 } | 86 } |
| 78 | 87 |
| 79 return ComponentUnpacker::kNone; | 88 callback.Run(ComponentUnpacker::kNone, error); |
| 80 } | 89 } |
| 81 | 90 |
| 91 } // namespace component_updater |
| OLD | NEW |