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_operation.h" | 5 #include "chrome/browser/component_updater/component_patcher_operation.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 namespace { | 27 namespace { |
28 | 28 |
29 const char kInput[] = "input"; | 29 const char kInput[] = "input"; |
30 const char kOp[] = "op"; | 30 const char kOp[] = "op"; |
31 const char kOutput[] = "output"; | 31 const char kOutput[] = "output"; |
32 const char kPatch[] = "patch"; | 32 const char kPatch[] = "patch"; |
33 const char kSha256[] = "sha256"; | 33 const char kSha256[] = "sha256"; |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
| 37 namespace component_updater { |
| 38 |
37 DeltaUpdateOp* CreateDeltaUpdateOp(base::DictionaryValue* command) { | 39 DeltaUpdateOp* CreateDeltaUpdateOp(base::DictionaryValue* command) { |
38 std::string operation; | 40 std::string operation; |
39 if (!command->GetString(kOp, &operation)) | 41 if (!command->GetString(kOp, &operation)) |
40 return NULL; | 42 return NULL; |
41 if (operation == "copy") | 43 if (operation == "copy") |
42 return new DeltaUpdateOpCopy(); | 44 return new DeltaUpdateOpCopy(); |
43 else if (operation == "create") | 45 else if (operation == "create") |
44 return new DeltaUpdateOpCreate(); | 46 return new DeltaUpdateOpCreate(); |
45 else if (operation == "bsdiff") | 47 else if (operation == "bsdiff") |
46 return new DeltaUpdateOpPatchBsdiff(); | 48 return new DeltaUpdateOpPatchBsdiff(); |
47 else if (operation == "courgette") | 49 else if (operation == "courgette") |
48 return new DeltaUpdateOpPatchCourgette(); | 50 return new DeltaUpdateOpPatchCourgette(); |
49 return NULL; | 51 return NULL; |
50 } | 52 } |
51 | 53 |
52 DeltaUpdateOp::DeltaUpdateOp() {} | 54 DeltaUpdateOp::DeltaUpdateOp() {} |
53 | 55 |
54 DeltaUpdateOp::~DeltaUpdateOp() {} | 56 DeltaUpdateOp::~DeltaUpdateOp() {} |
55 | 57 |
56 ComponentUnpacker::Error DeltaUpdateOp::Run(base::DictionaryValue* command_args, | 58 ComponentUnpacker::Error DeltaUpdateOp::Run( |
57 const base::FilePath& input_dir, | 59 base::DictionaryValue* command_args, |
58 const base::FilePath& unpack_dir, | 60 const base::FilePath& input_dir, |
59 ComponentPatcher* patcher, | 61 const base::FilePath& unpack_dir, |
60 ComponentInstaller* installer, | 62 ComponentPatcher* patcher, |
61 int* error) { | 63 ComponentInstaller* installer, |
| 64 int* error) { |
62 std::string output_rel_path; | 65 std::string output_rel_path; |
63 if (!command_args->GetString(kOutput, &output_rel_path) || | 66 if (!command_args->GetString(kOutput, &output_rel_path) || |
64 !command_args->GetString(kSha256, &output_sha256_)) | 67 !command_args->GetString(kSha256, &output_sha256_)) |
65 return ComponentUnpacker::kDeltaBadCommands; | 68 return ComponentUnpacker::kDeltaBadCommands; |
66 | 69 |
67 output_abs_path_ = unpack_dir.Append( | 70 output_abs_path_ = unpack_dir.Append( |
68 base::FilePath::FromUTF8Unsafe(output_rel_path)); | 71 base::FilePath::FromUTF8Unsafe(output_rel_path)); |
69 ComponentUnpacker::Error parse_result = DoParseArguments( | 72 ComponentUnpacker::Error parse_result = DoParseArguments( |
70 command_args, input_dir, installer); | 73 command_args, input_dir, installer); |
71 if (parse_result != ComponentUnpacker::kNone) | 74 if (parse_result != ComponentUnpacker::kNone) |
72 return parse_result; | 75 return parse_result; |
73 | 76 |
74 const base::FilePath parent = output_abs_path_.DirName(); | 77 const base::FilePath parent = output_abs_path_.DirName(); |
75 if (!base::DirectoryExists(parent)) { | 78 if (!base::DirectoryExists(parent)) { |
76 if (!file_util::CreateDirectory(parent)) | 79 if (!file_util::CreateDirectory(parent)) |
77 return ComponentUnpacker::kIoError; | 80 return ComponentUnpacker::kIoError; |
78 } | 81 } |
79 | 82 |
80 ComponentUnpacker::Error run_result = DoRun(patcher, error); | 83 ComponentUnpacker::Error run_result = DoRun( |
| 84 patcher, error); |
81 if (run_result != ComponentUnpacker::kNone) | 85 if (run_result != ComponentUnpacker::kNone) |
82 return run_result; | 86 return run_result; |
83 | 87 |
84 return CheckHash(); | 88 return CheckHash(); |
85 } | 89 } |
86 | 90 |
87 // Uses the hash as a checksum to confirm that the file now residing in the | 91 // Uses the hash as a checksum to confirm that the file now residing in the |
88 // output directory probably has the contents it should. | 92 // output directory probably has the contents it should. |
89 ComponentUnpacker::Error DeltaUpdateOp::CheckHash() { | 93 ComponentUnpacker::Error DeltaUpdateOp::CheckHash() { |
90 std::vector<uint8> expected_hash; | 94 std::vector<uint8> expected_hash; |
(...skipping 24 matching lines...) Expand all Loading... |
115 std::string input_rel_path; | 119 std::string input_rel_path; |
116 if (!command_args->GetString(kInput, &input_rel_path)) | 120 if (!command_args->GetString(kInput, &input_rel_path)) |
117 return ComponentUnpacker::kDeltaBadCommands; | 121 return ComponentUnpacker::kDeltaBadCommands; |
118 | 122 |
119 if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) | 123 if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) |
120 return ComponentUnpacker::kDeltaMissingExistingFile; | 124 return ComponentUnpacker::kDeltaMissingExistingFile; |
121 | 125 |
122 return ComponentUnpacker::kNone; | 126 return ComponentUnpacker::kNone; |
123 } | 127 } |
124 | 128 |
125 ComponentUnpacker::Error DeltaUpdateOpCopy::DoRun(ComponentPatcher*, | 129 ComponentUnpacker::Error DeltaUpdateOpCopy::DoRun( |
126 int* error) { | 130 ComponentPatcher*, |
| 131 int* error) { |
127 *error = 0; | 132 *error = 0; |
128 if (!base::CopyFile(input_abs_path_, output_abs_path_)) | 133 if (!base::CopyFile(input_abs_path_, output_abs_path_)) |
129 return ComponentUnpacker::kDeltaOperationFailure; | 134 return ComponentUnpacker::kDeltaOperationFailure; |
130 | 135 |
131 return ComponentUnpacker::kNone; | 136 return ComponentUnpacker::kNone; |
132 } | 137 } |
133 | 138 |
134 DeltaUpdateOpCreate::DeltaUpdateOpCreate() {} | 139 DeltaUpdateOpCreate::DeltaUpdateOpCreate() {} |
135 | 140 |
136 ComponentUnpacker::Error DeltaUpdateOpCreate::DoParseArguments( | 141 ComponentUnpacker::Error DeltaUpdateOpCreate::DoParseArguments( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 ComponentPatcher* patcher, | 218 ComponentPatcher* patcher, |
214 int* error) { | 219 int* error) { |
215 *error = 0; | 220 *error = 0; |
216 return patcher->Patch(ComponentPatcher::kPatchTypeCourgette, | 221 return patcher->Patch(ComponentPatcher::kPatchTypeCourgette, |
217 input_abs_path_, | 222 input_abs_path_, |
218 patch_abs_path_, | 223 patch_abs_path_, |
219 output_abs_path_, | 224 output_abs_path_, |
220 error); | 225 error); |
221 } | 226 } |
222 | 227 |
| 228 } // namespace component_updater |
OLD | NEW |