OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "extensions/browser/sandboxed_unpacker.h" | 5 #include "extensions/browser/sandboxed_unpacker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 location_(location), | 226 location_(location), |
227 creation_flags_(creation_flags), | 227 creation_flags_(creation_flags), |
228 unpacker_io_task_runner_(unpacker_io_task_runner) { | 228 unpacker_io_task_runner_(unpacker_io_task_runner) { |
229 // Tracking for crbug.com/692069. The location must be valid. If it's invalid, | 229 // Tracking for crbug.com/692069. The location must be valid. If it's invalid, |
230 // the utility process kills itself for a bad IPC. | 230 // the utility process kills itself for a bad IPC. |
231 CHECK_GT(location, Manifest::INVALID_LOCATION); | 231 CHECK_GT(location, Manifest::INVALID_LOCATION); |
232 CHECK_LT(location, Manifest::NUM_LOCATIONS); | 232 CHECK_LT(location, Manifest::NUM_LOCATIONS); |
233 } | 233 } |
234 | 234 |
235 bool SandboxedUnpacker::CreateTempDirectory() { | 235 bool SandboxedUnpacker::CreateTempDirectory() { |
236 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 236 CHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
237 | 237 |
238 base::FilePath temp_dir; | 238 base::FilePath temp_dir; |
239 if (!FindWritableTempLocation(extensions_dir_, &temp_dir)) { | 239 if (!FindWritableTempLocation(extensions_dir_, &temp_dir)) { |
240 ReportFailure(COULD_NOT_GET_TEMP_DIRECTORY, | 240 ReportFailure(COULD_NOT_GET_TEMP_DIRECTORY, |
241 l10n_util::GetStringFUTF16( | 241 l10n_util::GetStringFUTF16( |
242 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 242 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
243 ASCIIToUTF16("COULD_NOT_GET_TEMP_DIRECTORY"))); | 243 ASCIIToUTF16("COULD_NOT_GET_TEMP_DIRECTORY"))); |
244 return false; | 244 return false; |
245 } | 245 } |
246 | 246 |
247 if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_dir)) { | 247 if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_dir)) { |
248 ReportFailure(COULD_NOT_CREATE_TEMP_DIRECTORY, | 248 ReportFailure(COULD_NOT_CREATE_TEMP_DIRECTORY, |
249 l10n_util::GetStringFUTF16( | 249 l10n_util::GetStringFUTF16( |
250 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 250 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
251 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY"))); | 251 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY"))); |
252 return false; | 252 return false; |
253 } | 253 } |
254 | 254 |
255 return true; | 255 return true; |
256 } | 256 } |
257 | 257 |
258 void SandboxedUnpacker::StartWithCrx(const CRXFileInfo& crx_info) { | 258 void SandboxedUnpacker::StartWithCrx(const CRXFileInfo& crx_info) { |
259 // We assume that we are started on the thread that the client wants us | 259 // We assume that we are started on the thread that the client wants us |
260 // to do file IO on. | 260 // to do file IO on. |
261 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 261 CHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
262 | 262 |
263 crx_unpack_start_time_ = base::TimeTicks::Now(); | 263 crx_unpack_start_time_ = base::TimeTicks::Now(); |
264 std::string expected_hash; | 264 std::string expected_hash; |
265 if (!crx_info.expected_hash.empty() && | 265 if (!crx_info.expected_hash.empty() && |
266 base::CommandLine::ForCurrentProcess()->HasSwitch( | 266 base::CommandLine::ForCurrentProcess()->HasSwitch( |
267 extensions::switches::kEnableCrxHashCheck)) { | 267 extensions::switches::kEnableCrxHashCheck)) { |
268 expected_hash = base::ToLowerASCII(crx_info.expected_hash); | 268 expected_hash = base::ToLowerASCII(crx_info.expected_hash); |
269 } | 269 } |
270 | 270 |
271 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", | 271 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 return; | 438 return; |
439 } | 439 } |
440 | 440 |
441 unpacker_io_task_runner_->PostTask( | 441 unpacker_io_task_runner_->PostTask( |
442 FROM_HERE, base::Bind(&SandboxedUnpacker::UnpackExtensionSucceeded, this, | 442 FROM_HERE, base::Bind(&SandboxedUnpacker::UnpackExtensionSucceeded, this, |
443 base::Passed(&manifest))); | 443 base::Passed(&manifest))); |
444 } | 444 } |
445 | 445 |
446 void SandboxedUnpacker::UnpackExtensionSucceeded( | 446 void SandboxedUnpacker::UnpackExtensionSucceeded( |
447 std::unique_ptr<base::DictionaryValue> manifest) { | 447 std::unique_ptr<base::DictionaryValue> manifest) { |
448 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 448 CHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
449 | 449 |
450 std::unique_ptr<base::DictionaryValue> final_manifest( | 450 std::unique_ptr<base::DictionaryValue> final_manifest( |
451 RewriteManifestFile(*manifest)); | 451 RewriteManifestFile(*manifest)); |
452 if (!final_manifest) | 452 if (!final_manifest) |
453 return; | 453 return; |
454 | 454 |
455 // Create an extension object that refers to the temporary location the | 455 // Create an extension object that refers to the temporary location the |
456 // extension was unpacked to. We use this until the extension is finally | 456 // extension was unpacked to. We use this until the extension is finally |
457 // installed. For example, the install UI shows images from inside the | 457 // installed. For example, the install UI shows images from inside the |
458 // extension. | 458 // extension. |
(...skipping 26 matching lines...) Expand all Loading... |
485 if (!RewriteImageFiles(&install_icon)) | 485 if (!RewriteImageFiles(&install_icon)) |
486 return; | 486 return; |
487 | 487 |
488 if (!RewriteCatalogFiles()) | 488 if (!RewriteCatalogFiles()) |
489 return; | 489 return; |
490 | 490 |
491 ReportSuccess(std::move(manifest), install_icon); | 491 ReportSuccess(std::move(manifest), install_icon); |
492 } | 492 } |
493 | 493 |
494 void SandboxedUnpacker::UnpackExtensionFailed(const base::string16& error) { | 494 void SandboxedUnpacker::UnpackExtensionFailed(const base::string16& error) { |
495 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 495 CHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
496 | 496 |
497 ReportFailure( | 497 ReportFailure( |
498 UNPACKER_CLIENT_FAILED, | 498 UNPACKER_CLIENT_FAILED, |
499 l10n_util::GetStringFUTF16(IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, error)); | 499 l10n_util::GetStringFUTF16(IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, error)); |
500 } | 500 } |
501 | 501 |
502 base::string16 SandboxedUnpacker::FailureReasonToString16( | 502 base::string16 SandboxedUnpacker::FailureReasonToString16( |
503 FailureReason reason) { | 503 FailureReason reason) { |
504 switch (reason) { | 504 switch (reason) { |
505 case COULD_NOT_GET_TEMP_DIRECTORY: | 505 case COULD_NOT_GET_TEMP_DIRECTORY: |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 l10n_util::GetStringFUTF16(IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 896 l10n_util::GetStringFUTF16(IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
897 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); | 897 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); |
898 return false; | 898 return false; |
899 } | 899 } |
900 } | 900 } |
901 | 901 |
902 return true; | 902 return true; |
903 } | 903 } |
904 | 904 |
905 void SandboxedUnpacker::Cleanup() { | 905 void SandboxedUnpacker::Cleanup() { |
906 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 906 DCHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
907 if (!temp_dir_.Delete()) { | 907 if (!temp_dir_.Delete()) { |
908 LOG(WARNING) << "Can not delete temp directory at " | 908 LOG(WARNING) << "Can not delete temp directory at " |
909 << temp_dir_.GetPath().value(); | 909 << temp_dir_.GetPath().value(); |
910 } | 910 } |
911 } | 911 } |
912 | 912 |
913 } // namespace extensions | 913 } // namespace extensions |
OLD | NEW |