| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_out_of_pr
ocess.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 #include <vector> | 7 #include <vector> |
| 9 | 8 |
| 10 #include "base/bind.h" | 9 #include "base/bind.h" |
| 11 #include "base/file_util.h" | |
| 12 #include "base/files/memory_mapped_file.h" | |
| 13 #include "base/json/json_file_value_serializer.h" | |
| 14 #include "base/path_service.h" | |
| 15 #include "base/strings/string_number_conversions.h" | |
| 16 #include "chrome/browser/component_updater/component_patcher.h" | |
| 17 #include "chrome/browser/component_updater/component_updater_service.h" | 10 #include "chrome/browser/component_updater/component_updater_service.h" |
| 18 #include "chrome/common/chrome_utility_messages.h" | 11 #include "chrome/common/chrome_utility_messages.h" |
| 19 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/utility_process_host.h" | 13 #include "content/public/browser/utility_process_host.h" |
| 21 #include "courgette/courgette.h" | 14 #include "courgette/courgette.h" |
| 22 #include "courgette/third_party/bsdiff.h" | 15 #include "courgette/third_party/bsdiff.h" |
| 23 #include "crypto/secure_hash.h" | |
| 24 #include "crypto/sha2.h" | |
| 25 #include "crypto/signature_verifier.h" | |
| 26 #include "extensions/common/crx_file.h" | |
| 27 #include "ipc/ipc_message_macros.h" | 16 #include "ipc/ipc_message_macros.h" |
| 28 | 17 |
| 29 using crypto::SecureHash; | |
| 30 | |
| 31 namespace component_updater { | 18 namespace component_updater { |
| 32 | 19 |
| 33 namespace { | 20 namespace { |
| 34 | 21 |
| 35 const char kInput[] = "input"; | 22 class OutOfProcessProcessDeltaUpdateOpFactory : public DeltaUpdateOpFactory { |
| 36 const char kOp[] = "op"; | |
| 37 const char kOutput[] = "output"; | |
| 38 const char kPatch[] = "patch"; | |
| 39 const char kSha256[] = "sha256"; | |
| 40 | |
| 41 // The integer offset disambiguates between overlapping error ranges. | |
| 42 const int kCourgetteErrorOffset = 300; | |
| 43 const int kBsdiffErrorOffset = 600; | |
| 44 | |
| 45 class CourgetteTraits : public DeltaUpdateOpPatchStrategy { | |
| 46 public: | 23 public: |
| 47 virtual int GetErrorOffset() const OVERRIDE; | 24 virtual DeltaUpdateOp* CreateDeltaUpdateOp( |
| 48 virtual int GetSuccessCode() const OVERRIDE; | 25 const std::string& operation) const OVERRIDE { |
| 49 virtual scoped_ptr<IPC::Message> GetPatchMessage( | 26 if (operation == "copy") { |
| 50 base::FilePath input_abs_path, | 27 return new DeltaUpdateOpCopy(); |
| 51 base::FilePath patch_abs_path, | 28 } else if (operation == "create") { |
| 52 base::FilePath output_abs_path) OVERRIDE; | 29 return new DeltaUpdateOpCreate(); |
| 53 virtual int Patch(base::FilePath input_abs_path, | 30 } else if (operation == kBsdiff || operation == kCourgette) { |
| 54 base::FilePath patch_abs_path, | 31 return new DeltaUpdateOpPatchOutOfProcess(operation); |
| 55 base::FilePath output_abs_path) OVERRIDE; | 32 } |
| 33 return NULL; |
| 34 } |
| 56 }; | 35 }; |
| 57 | 36 |
| 58 int CourgetteTraits::GetErrorOffset() const { | |
| 59 return kCourgetteErrorOffset; | |
| 60 } | |
| 61 | |
| 62 int CourgetteTraits::GetSuccessCode() const { | |
| 63 return courgette::C_OK; | |
| 64 } | |
| 65 | |
| 66 scoped_ptr<IPC::Message> CourgetteTraits::GetPatchMessage( | |
| 67 base::FilePath input_abs_path, | |
| 68 base::FilePath patch_abs_path, | |
| 69 base::FilePath output_abs_path) { | |
| 70 return scoped_ptr<IPC::Message>( | |
| 71 new ChromeUtilityMsg_PatchFileCourgette(input_abs_path, | |
| 72 patch_abs_path, | |
| 73 output_abs_path)); | |
| 74 } | |
| 75 | |
| 76 int CourgetteTraits::Patch(base::FilePath input_abs_path, | |
| 77 base::FilePath patch_abs_path, | |
| 78 base::FilePath output_abs_path) { | |
| 79 return courgette::ApplyEnsemblePatch(input_abs_path.value().c_str(), | |
| 80 patch_abs_path.value().c_str(), | |
| 81 output_abs_path.value().c_str()); | |
| 82 } | |
| 83 | |
| 84 class BsdiffTraits : public DeltaUpdateOpPatchStrategy { | |
| 85 public: | |
| 86 virtual int GetErrorOffset() const OVERRIDE; | |
| 87 virtual int GetSuccessCode() const OVERRIDE; | |
| 88 virtual scoped_ptr<IPC::Message> GetPatchMessage( | |
| 89 base::FilePath input_abs_path, | |
| 90 base::FilePath patch_abs_path, | |
| 91 base::FilePath output_abs_path) OVERRIDE; | |
| 92 virtual int Patch(base::FilePath input_abs_path, | |
| 93 base::FilePath patch_abs_path, | |
| 94 base::FilePath output_abs_path) OVERRIDE; | |
| 95 }; | |
| 96 | |
| 97 int BsdiffTraits::GetErrorOffset() const { | |
| 98 return kBsdiffErrorOffset; | |
| 99 } | |
| 100 | |
| 101 int BsdiffTraits::GetSuccessCode() const { | |
| 102 return courgette::OK; | |
| 103 } | |
| 104 | |
| 105 scoped_ptr<IPC::Message> BsdiffTraits::GetPatchMessage( | |
| 106 base::FilePath input_abs_path, | |
| 107 base::FilePath patch_abs_path, | |
| 108 base::FilePath output_abs_path) { | |
| 109 return scoped_ptr<IPC::Message>( | |
| 110 new ChromeUtilityMsg_PatchFileBsdiff(input_abs_path, | |
| 111 patch_abs_path, | |
| 112 output_abs_path)); | |
| 113 } | |
| 114 | |
| 115 int BsdiffTraits::Patch(base::FilePath input_abs_path, | |
| 116 base::FilePath patch_abs_path, | |
| 117 base::FilePath output_abs_path) { | |
| 118 return courgette::ApplyBinaryPatch(input_abs_path, | |
| 119 patch_abs_path, | |
| 120 output_abs_path); | |
| 121 } | |
| 122 | |
| 123 } // namespace | 37 } // namespace |
| 124 | 38 |
| 125 DeltaUpdateOpPatchStrategy::~DeltaUpdateOpPatchStrategy() { | 39 DeltaUpdateOpFactory* CreateOutOfProcessDeltaUpdateOpFactory() { |
| 40 return new OutOfProcessProcessDeltaUpdateOpFactory(); |
| 126 } | 41 } |
| 127 | 42 |
| 128 DeltaUpdateOp* CreateDeltaUpdateOp(const std::string& operation) { | 43 class DeltaUpdateOpPatchHost : public content::UtilityProcessHostClient { |
| 129 if (operation == "copy") { | 44 public: |
| 130 return new DeltaUpdateOpCopy(); | 45 DeltaUpdateOpPatchHost(scoped_refptr<DeltaUpdateOpPatchOutOfProcess> patcher, |
| 131 } else if (operation == "create") { | 46 scoped_refptr<base::SequencedTaskRunner> task_runner); |
| 132 return new DeltaUpdateOpCreate(); | |
| 133 } else if (operation == "bsdiff") { | |
| 134 scoped_ptr<DeltaUpdateOpPatchStrategy> strategy(new BsdiffTraits()); | |
| 135 return new DeltaUpdateOpPatch(strategy.Pass()); | |
| 136 } else if (operation == "courgette") { | |
| 137 scoped_ptr<DeltaUpdateOpPatchStrategy> strategy(new CourgetteTraits()); | |
| 138 return new DeltaUpdateOpPatch(strategy.Pass()); | |
| 139 } | |
| 140 return NULL; | |
| 141 } | |
| 142 | 47 |
| 143 DeltaUpdateOp* CreateDeltaUpdateOp(const base::DictionaryValue& command) { | 48 void StartProcess(scoped_ptr<IPC::Message> message); |
| 144 std::string operation; | |
| 145 if (!command.GetString(kOp, &operation)) | |
| 146 return NULL; | |
| 147 return CreateDeltaUpdateOp(operation); | |
| 148 } | |
| 149 | 49 |
| 150 DeltaUpdateOp::DeltaUpdateOp() : in_process_(false) { | 50 private: |
| 151 } | 51 virtual ~DeltaUpdateOpPatchHost(); |
| 152 | 52 |
| 153 DeltaUpdateOp::~DeltaUpdateOp() { | 53 void OnPatchSucceeded(); |
| 154 } | |
| 155 | 54 |
| 156 void DeltaUpdateOp::Run(const base::DictionaryValue* command_args, | 55 void OnPatchFailed(int error_code); |
| 157 const base::FilePath& input_dir, | |
| 158 const base::FilePath& unpack_dir, | |
| 159 ComponentInstaller* installer, | |
| 160 bool in_process, | |
| 161 const ComponentUnpacker::Callback& callback, | |
| 162 scoped_refptr<base::SequencedTaskRunner> task_runner) { | |
| 163 callback_ = callback; | |
| 164 in_process_ = in_process; | |
| 165 task_runner_ = task_runner; | |
| 166 std::string output_rel_path; | |
| 167 if (!command_args->GetString(kOutput, &output_rel_path) || | |
| 168 !command_args->GetString(kSha256, &output_sha256_)) { | |
| 169 DoneRunning(ComponentUnpacker::kDeltaBadCommands, 0); | |
| 170 return; | |
| 171 } | |
| 172 | 56 |
| 173 output_abs_path_ = | 57 // Overrides of content::UtilityProcessHostClient. |
| 174 unpack_dir.Append(base::FilePath::FromUTF8Unsafe(output_rel_path)); | 58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 175 ComponentUnpacker::Error parse_result = | |
| 176 DoParseArguments(command_args, input_dir, installer); | |
| 177 if (parse_result != ComponentUnpacker::kNone) { | |
| 178 DoneRunning(parse_result, 0); | |
| 179 return; | |
| 180 } | |
| 181 | 59 |
| 182 const base::FilePath parent = output_abs_path_.DirName(); | 60 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
| 183 if (!base::DirectoryExists(parent)) { | |
| 184 if (!base::CreateDirectory(parent)) { | |
| 185 DoneRunning(ComponentUnpacker::kIoError, 0); | |
| 186 return; | |
| 187 } | |
| 188 } | |
| 189 | 61 |
| 190 DoRun(base::Bind(&DeltaUpdateOp::DoneRunning, | 62 scoped_refptr<DeltaUpdateOpPatchOutOfProcess> patcher_; |
| 191 scoped_refptr<DeltaUpdateOp>(this))); | 63 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 192 } | 64 }; |
| 193 | |
| 194 void DeltaUpdateOp::DoneRunning(ComponentUnpacker::Error error, | |
| 195 int extended_error) { | |
| 196 if (error == ComponentUnpacker::kNone) | |
| 197 error = CheckHash(); | |
| 198 task_runner_->PostTask(FROM_HERE, | |
| 199 base::Bind(callback_, error, extended_error)); | |
| 200 callback_.Reset(); | |
| 201 } | |
| 202 | |
| 203 // Uses the hash as a checksum to confirm that the file now residing in the | |
| 204 // output directory probably has the contents it should. | |
| 205 ComponentUnpacker::Error DeltaUpdateOp::CheckHash() { | |
| 206 std::vector<uint8> expected_hash; | |
| 207 if (!base::HexStringToBytes(output_sha256_, &expected_hash) || | |
| 208 expected_hash.size() != crypto::kSHA256Length) | |
| 209 return ComponentUnpacker::kDeltaVerificationFailure; | |
| 210 | |
| 211 base::MemoryMappedFile output_file_mmapped; | |
| 212 if (!output_file_mmapped.Initialize(output_abs_path_)) | |
| 213 return ComponentUnpacker::kDeltaVerificationFailure; | |
| 214 | |
| 215 uint8 actual_hash[crypto::kSHA256Length] = {0}; | |
| 216 const scoped_ptr<SecureHash> hasher(SecureHash::Create(SecureHash::SHA256)); | |
| 217 hasher->Update(output_file_mmapped.data(), output_file_mmapped.length()); | |
| 218 hasher->Finish(actual_hash, sizeof(actual_hash)); | |
| 219 if (memcmp(actual_hash, &expected_hash[0], sizeof(actual_hash))) | |
| 220 return ComponentUnpacker::kDeltaVerificationFailure; | |
| 221 | |
| 222 return ComponentUnpacker::kNone; | |
| 223 } | |
| 224 | |
| 225 bool DeltaUpdateOp::InProcess() { | |
| 226 return in_process_; | |
| 227 } | |
| 228 | |
| 229 scoped_refptr<base::SequencedTaskRunner> DeltaUpdateOp::GetTaskRunner() { | |
| 230 return task_runner_; | |
| 231 } | |
| 232 | |
| 233 DeltaUpdateOpCopy::DeltaUpdateOpCopy() { | |
| 234 } | |
| 235 | |
| 236 DeltaUpdateOpCopy::~DeltaUpdateOpCopy() { | |
| 237 } | |
| 238 | |
| 239 ComponentUnpacker::Error DeltaUpdateOpCopy::DoParseArguments( | |
| 240 const base::DictionaryValue* command_args, | |
| 241 const base::FilePath& input_dir, | |
| 242 ComponentInstaller* installer) { | |
| 243 std::string input_rel_path; | |
| 244 if (!command_args->GetString(kInput, &input_rel_path)) | |
| 245 return ComponentUnpacker::kDeltaBadCommands; | |
| 246 | |
| 247 if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) | |
| 248 return ComponentUnpacker::kDeltaMissingExistingFile; | |
| 249 | |
| 250 return ComponentUnpacker::kNone; | |
| 251 } | |
| 252 | |
| 253 void DeltaUpdateOpCopy::DoRun(const ComponentUnpacker::Callback& callback) { | |
| 254 if (!base::CopyFile(input_abs_path_, output_abs_path_)) | |
| 255 callback.Run(ComponentUnpacker::kDeltaOperationFailure, 0); | |
| 256 else | |
| 257 callback.Run(ComponentUnpacker::kNone, 0); | |
| 258 } | |
| 259 | |
| 260 DeltaUpdateOpCreate::DeltaUpdateOpCreate() { | |
| 261 } | |
| 262 | |
| 263 DeltaUpdateOpCreate::~DeltaUpdateOpCreate() { | |
| 264 } | |
| 265 | |
| 266 ComponentUnpacker::Error DeltaUpdateOpCreate::DoParseArguments( | |
| 267 const base::DictionaryValue* command_args, | |
| 268 const base::FilePath& input_dir, | |
| 269 ComponentInstaller* installer) { | |
| 270 std::string patch_rel_path; | |
| 271 if (!command_args->GetString(kPatch, &patch_rel_path)) | |
| 272 return ComponentUnpacker::kDeltaBadCommands; | |
| 273 | |
| 274 patch_abs_path_ = | |
| 275 input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path)); | |
| 276 | |
| 277 return ComponentUnpacker::kNone; | |
| 278 } | |
| 279 | |
| 280 void DeltaUpdateOpCreate::DoRun(const ComponentUnpacker::Callback& callback) { | |
| 281 if (!base::Move(patch_abs_path_, output_abs_path_)) | |
| 282 callback.Run(ComponentUnpacker::kDeltaOperationFailure, 0); | |
| 283 else | |
| 284 callback.Run(ComponentUnpacker::kNone, 0); | |
| 285 } | |
| 286 | 65 |
| 287 DeltaUpdateOpPatchHost::DeltaUpdateOpPatchHost( | 66 DeltaUpdateOpPatchHost::DeltaUpdateOpPatchHost( |
| 288 scoped_refptr<DeltaUpdateOpPatch> patcher, | 67 scoped_refptr<DeltaUpdateOpPatchOutOfProcess> patcher, |
| 289 scoped_refptr<base::SequencedTaskRunner> task_runner) | 68 scoped_refptr<base::SequencedTaskRunner> task_runner) |
| 290 : patcher_(patcher), task_runner_(task_runner) { | 69 : patcher_(patcher), task_runner_(task_runner) { |
| 291 } | 70 } |
| 292 | 71 |
| 293 DeltaUpdateOpPatchHost::~DeltaUpdateOpPatchHost() { | 72 DeltaUpdateOpPatchHost::~DeltaUpdateOpPatchHost() { |
| 294 } | 73 } |
| 295 | 74 |
| 296 void DeltaUpdateOpPatchHost::StartProcess(scoped_ptr<IPC::Message> message) { | 75 void DeltaUpdateOpPatchHost::StartProcess(scoped_ptr<IPC::Message> message) { |
| 297 // The DeltaUpdateOpPatchHost is not responsible for deleting the | 76 // The DeltaUpdateOpPatchHost is not responsible for deleting the |
| 298 // UtilityProcessHost object. | 77 // UtilityProcessHost object. |
| 299 content::UtilityProcessHost* host = content::UtilityProcessHost::Create( | 78 content::UtilityProcessHost* host = content::UtilityProcessHost::Create( |
| 300 this, base::MessageLoopProxy::current().get()); | 79 this, base::MessageLoopProxy::current().get()); |
| 301 host->DisableSandbox(); | 80 host->DisableSandbox(); |
| 302 host->Send(message.release()); | 81 host->Send(message.release()); |
| 303 } | 82 } |
| 304 | 83 |
| 305 bool DeltaUpdateOpPatchHost::OnMessageReceived(const IPC::Message& message) { | 84 bool DeltaUpdateOpPatchHost::OnMessageReceived(const IPC::Message& message) { |
| 306 bool handled = true; | 85 bool handled = true; |
| 307 IPC_BEGIN_MESSAGE_MAP(DeltaUpdateOpPatchHost, message) | 86 IPC_BEGIN_MESSAGE_MAP(DeltaUpdateOpPatchHost, message) |
| 308 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PatchFile_Succeeded, | 87 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PatchFile_Succeeded, |
| 309 OnPatchSucceeded) | 88 OnPatchSucceeded) |
| 310 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PatchFile_Failed, | 89 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PatchFile_Failed, |
| 311 OnPatchFailed) | 90 OnPatchFailed) |
| 312 IPC_MESSAGE_UNHANDLED(handled = false) | 91 IPC_MESSAGE_UNHANDLED(handled = false) |
| 313 IPC_END_MESSAGE_MAP() | 92 IPC_END_MESSAGE_MAP() |
| 314 return handled; | 93 return handled; |
| 315 } | 94 } |
| 316 | 95 |
| 317 void DeltaUpdateOpPatchHost::OnPatchSucceeded() { | 96 void DeltaUpdateOpPatchHost::OnPatchSucceeded() { |
| 318 task_runner_->PostTask(FROM_HERE, | 97 task_runner_->PostTask( |
| 319 base::Bind(&DeltaUpdateOpPatch::DonePatching, | 98 FROM_HERE, |
| 320 patcher_, | 99 base::Bind(&DeltaUpdateOpPatchOutOfProcess::DonePatching, |
| 321 ComponentUnpacker::kNone, | 100 patcher_, |
| 322 0)); | 101 ComponentUnpacker::kNone, |
| 102 0)); |
| 323 task_runner_ = NULL; | 103 task_runner_ = NULL; |
| 324 patcher_ = NULL; | 104 patcher_ = NULL; |
| 325 } | 105 } |
| 326 | 106 |
| 327 void DeltaUpdateOpPatchHost::OnPatchFailed(int error_code) { | 107 void DeltaUpdateOpPatchHost::OnPatchFailed(int error_code) { |
| 328 task_runner_->PostTask(FROM_HERE, | 108 task_runner_->PostTask( |
| 329 base::Bind(&DeltaUpdateOpPatch::DonePatching, | 109 FROM_HERE, |
| 330 patcher_, | 110 base::Bind(&DeltaUpdateOpPatchOutOfProcess::DonePatching, |
| 331 ComponentUnpacker::kDeltaOperationFailure, | 111 patcher_, |
| 332 error_code)); | 112 ComponentUnpacker::kDeltaOperationFailure, |
| 113 error_code)); |
| 333 task_runner_ = NULL; | 114 task_runner_ = NULL; |
| 334 patcher_ = NULL; | 115 patcher_ = NULL; |
| 335 } | 116 } |
| 336 | 117 |
| 337 void DeltaUpdateOpPatchHost::OnProcessCrashed(int exit_code) { | 118 void DeltaUpdateOpPatchHost::OnProcessCrashed(int exit_code) { |
| 338 task_runner_->PostTask( | 119 task_runner_->PostTask( |
| 339 FROM_HERE, | 120 FROM_HERE, |
| 340 base::Bind(&DeltaUpdateOpPatch::DonePatching, | 121 base::Bind(&DeltaUpdateOpPatchOutOfProcess::DonePatching, |
| 341 patcher_, | 122 patcher_, |
| 342 ComponentUnpacker::kDeltaPatchProcessFailure, | 123 ComponentUnpacker::kDeltaPatchProcessFailure, |
| 343 exit_code)); | 124 exit_code)); |
| 344 task_runner_ = NULL; | 125 task_runner_ = NULL; |
| 345 patcher_ = NULL; | 126 patcher_ = NULL; |
| 346 } | 127 } |
| 347 | 128 |
| 348 DeltaUpdateOpPatch::DeltaUpdateOpPatch( | 129 DeltaUpdateOpPatchOutOfProcess::DeltaUpdateOpPatchOutOfProcess( |
| 349 scoped_ptr<DeltaUpdateOpPatchStrategy> strategy) { | 130 const std::string& operation) |
| 350 strategy_ = strategy.Pass(); | 131 : operation_(operation) { |
| 132 DCHECK(operation == kBsdiff || operation == kCourgette); |
| 351 } | 133 } |
| 352 | 134 |
| 353 DeltaUpdateOpPatch::~DeltaUpdateOpPatch() { | 135 DeltaUpdateOpPatchOutOfProcess::~DeltaUpdateOpPatchOutOfProcess() { |
| 354 } | 136 } |
| 355 | 137 |
| 356 ComponentUnpacker::Error DeltaUpdateOpPatch::DoParseArguments( | 138 ComponentUnpacker::Error DeltaUpdateOpPatchOutOfProcess::DoParseArguments( |
| 357 const base::DictionaryValue* command_args, | 139 const base::DictionaryValue* command_args, |
| 358 const base::FilePath& input_dir, | 140 const base::FilePath& input_dir, |
| 359 ComponentInstaller* installer) { | 141 ComponentInstaller* installer) { |
| 360 std::string patch_rel_path; | 142 std::string patch_rel_path; |
| 361 std::string input_rel_path; | 143 std::string input_rel_path; |
| 362 if (!command_args->GetString(kPatch, &patch_rel_path) || | 144 if (!command_args->GetString(kPatch, &patch_rel_path) || |
| 363 !command_args->GetString(kInput, &input_rel_path)) | 145 !command_args->GetString(kInput, &input_rel_path)) |
| 364 return ComponentUnpacker::kDeltaBadCommands; | 146 return ComponentUnpacker::kDeltaBadCommands; |
| 365 | 147 |
| 366 if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) | 148 if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) |
| 367 return ComponentUnpacker::kDeltaMissingExistingFile; | 149 return ComponentUnpacker::kDeltaMissingExistingFile; |
| 368 | 150 |
| 369 patch_abs_path_ = | 151 patch_abs_path_ = |
| 370 input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path)); | 152 input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path)); |
| 371 | 153 |
| 372 return ComponentUnpacker::kNone; | 154 return ComponentUnpacker::kNone; |
| 373 } | 155 } |
| 374 | 156 |
| 375 void DeltaUpdateOpPatch::DoRun(const ComponentUnpacker::Callback& callback) { | 157 void DeltaUpdateOpPatchOutOfProcess::DoRun( |
| 158 const ComponentUnpacker::Callback& callback) { |
| 376 callback_ = callback; | 159 callback_ = callback; |
| 377 if (!InProcess()) { | 160 host_ = new DeltaUpdateOpPatchHost( |
| 378 host_ = new DeltaUpdateOpPatchHost(scoped_refptr<DeltaUpdateOpPatch>(this), | 161 scoped_refptr<DeltaUpdateOpPatchOutOfProcess>(this), GetTaskRunner()); |
| 379 GetTaskRunner()); | 162 scoped_ptr<IPC::Message> patch_message; |
| 380 content::BrowserThread::PostTask( | 163 if (operation_ == kBsdiff) { |
| 381 content::BrowserThread::IO, | 164 patch_message.reset(new ChromeUtilityMsg_PatchFileBsdiff( |
| 382 FROM_HERE, | 165 input_abs_path_, patch_abs_path_, output_abs_path_)); |
| 383 base::Bind(&DeltaUpdateOpPatchHost::StartProcess, | 166 } else if (operation_ == kCourgette) { |
| 384 host_, | 167 patch_message.reset(new ChromeUtilityMsg_PatchFileCourgette( |
| 385 base::Passed(strategy_->GetPatchMessage(input_abs_path_, | 168 input_abs_path_, patch_abs_path_, output_abs_path_)); |
| 386 patch_abs_path_, | 169 } else { |
| 387 output_abs_path_)))); | 170 NOTREACHED(); |
| 388 return; | |
| 389 } | 171 } |
| 390 const int result = strategy_->Patch(input_abs_path_, | 172 |
| 391 patch_abs_path_, | 173 content::BrowserThread::PostTask( |
| 392 output_abs_path_); | 174 content::BrowserThread::IO, |
| 393 if (result == strategy_->GetSuccessCode()) | 175 FROM_HERE, |
| 394 DonePatching(ComponentUnpacker::kNone, 0); | 176 base::Bind(&DeltaUpdateOpPatchHost::StartProcess, |
| 395 else | 177 host_, |
| 396 DonePatching(ComponentUnpacker::kDeltaOperationFailure, result); | 178 base::Passed(&patch_message))); |
| 397 } | 179 } |
| 398 | 180 |
| 399 void DeltaUpdateOpPatch::DonePatching(ComponentUnpacker::Error error, | 181 void DeltaUpdateOpPatchOutOfProcess::DonePatching( |
| 400 int error_code) { | 182 ComponentUnpacker::Error error, |
| 183 int error_code) { |
| 401 host_ = NULL; | 184 host_ = NULL; |
| 402 if (error != ComponentUnpacker::kNone) { | 185 if (error != ComponentUnpacker::kNone) { |
| 403 error_code += strategy_->GetErrorOffset(); | 186 if (operation_ == kBsdiff) { |
| 187 error_code += kBsdiffErrorOffset; |
| 188 } else if (operation_ == kCourgette) { |
| 189 error_code += kCourgetteErrorOffset; |
| 190 } else { |
| 191 NOTREACHED(); |
| 192 } |
| 404 } | 193 } |
| 405 callback_.Run(error, error_code); | 194 callback_.Run(error, error_code); |
| 406 // The callback is no longer needed - it is best to release it in case it | 195 // The callback is no longer needed - it is best to release it in case it |
| 407 // contains a reference to this object. | 196 // contains a reference to this object. |
| 408 callback_.Reset(); | 197 callback_.Reset(); |
| 409 } | 198 } |
| 410 | 199 |
| 411 } // namespace component_updater | 200 } // namespace component_updater |
| OLD | NEW |