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