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 18 matching lines...) Expand all Loading... |
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 | 35 |
36 // The patching support is not cross-platform at the moment. | 36 // The patching support is not cross-platform at the moment. |
37 ComponentPatcherCrossPlatform::ComponentPatcherCrossPlatform() {} | 37 ComponentPatcherCrossPlatform::ComponentPatcherCrossPlatform() {} |
38 | 38 |
39 ComponentUnpacker::Error ComponentPatcherCrossPlatform::Patch( | 39 component_updater::Error ComponentPatcherCrossPlatform::Patch( |
40 PatchType patch_type, | 40 PatchType patch_type, |
41 const base::FilePath& input_file, | 41 const base::FilePath& input_file, |
42 const base::FilePath& patch_file, | 42 const base::FilePath& patch_file, |
43 const base::FilePath& output_file, | 43 const base::FilePath& output_file, |
44 int* error) { | 44 int* error) { |
45 return ComponentUnpacker::kDeltaUnsupportedCommand; | 45 return component_updater::kDeltaUnsupportedCommand; |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 // Takes the contents of a differential component update in input_dir | 49 // Takes the contents of a differential component update in input_dir |
50 // and produces the contents of a full component update in unpack_dir | 50 // and produces the contents of a full component update in unpack_dir |
51 // using input_abs_path_ files that the installer knows about. | 51 // using input_abs_path_ files that the installer knows about. |
52 ComponentUnpacker::Error DifferentialUpdatePatch( | 52 void DifferentialUpdatePatch( |
53 const base::FilePath& input_dir, | 53 const base::FilePath& input_dir, |
54 const base::FilePath& unpack_dir, | 54 const base::FilePath& unpack_dir, |
55 ComponentPatcher* patcher, | 55 ComponentPatcher* patcher, |
56 ComponentInstaller* installer, | 56 ComponentInstaller* installer, |
57 int* error) { | 57 base::Callback<void(component_updater::Error, int)> callback) { |
58 *error = 0; | 58 int error = 0; |
59 scoped_ptr<base::ListValue> commands(ReadCommands(input_dir)); | 59 scoped_ptr<base::ListValue> commands(ReadCommands(input_dir)); |
60 if (!commands.get()) | 60 if (!commands.get()) { |
61 return ComponentUnpacker::kDeltaBadCommands; | 61 callback.Run(component_updater::kDeltaBadCommands, error); |
| 62 return; |
| 63 } |
62 | 64 |
63 for (base::ValueVector::const_iterator command = commands->begin(), | 65 for (base::ValueVector::const_iterator command = commands->begin(), |
64 end = commands->end(); command != end; command++) { | 66 end = commands->end(); command != end; command++) { |
65 if (!(*command)->IsType(base::Value::TYPE_DICTIONARY)) | 67 if (!(*command)->IsType(base::Value::TYPE_DICTIONARY)) { |
66 return ComponentUnpacker::kDeltaBadCommands; | 68 callback.Run(component_updater::kDeltaBadCommands, error); |
| 69 return; |
| 70 } |
67 base::DictionaryValue* command_args = | 71 base::DictionaryValue* command_args = |
68 static_cast<base::DictionaryValue*>(*command); | 72 static_cast<base::DictionaryValue*>(*command); |
69 scoped_ptr<DeltaUpdateOp> operation(CreateDeltaUpdateOp(command_args)); | 73 scoped_ptr<DeltaUpdateOp> operation(CreateDeltaUpdateOp(command_args)); |
70 if (!operation) | 74 if (!operation) { |
71 return ComponentUnpacker::kDeltaUnsupportedCommand; | 75 callback.Run(component_updater::kDeltaUnsupportedCommand, error); |
| 76 return; |
| 77 } |
72 | 78 |
73 ComponentUnpacker::Error result = operation->Run( | 79 component_updater::Error result = operation->Run( |
74 command_args, input_dir, unpack_dir, patcher, installer, error); | 80 command_args, input_dir, unpack_dir, patcher, installer, &error); |
75 if (result != ComponentUnpacker::kNone) | 81 if (result != component_updater::kNone) { |
76 return result; | 82 callback.Run(result, error); |
| 83 return; |
| 84 } |
77 } | 85 } |
78 | 86 |
79 return ComponentUnpacker::kNone; | 87 callback.Run(component_updater::kNone, error); |
80 } | 88 } |
81 | 89 |
OLD | NEW |