| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/updater/update_install_shim.h" | 5 #include "extensions/browser/updater/update_install_shim.h" |
| 6 | 6 |
| 7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "components/update_client/update_client_errors.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 | 16 |
| 16 namespace extensions { | 17 namespace extensions { |
| 17 | 18 |
| 19 namespace { |
| 20 using InstallError = update_client::InstallError; |
| 21 using Result = update_client::CrxInstaller::Result; |
| 22 } // namespace |
| 23 |
| 18 UpdateInstallShim::UpdateInstallShim(std::string extension_id, | 24 UpdateInstallShim::UpdateInstallShim(std::string extension_id, |
| 19 const base::FilePath& extension_root, | 25 const base::FilePath& extension_root, |
| 20 const UpdateInstallShimCallback& callback) | 26 const UpdateInstallShimCallback& callback) |
| 21 : extension_id_(extension_id), | 27 : extension_id_(extension_id), |
| 22 extension_root_(extension_root), | 28 extension_root_(extension_root), |
| 23 callback_(callback) {} | 29 callback_(callback) {} |
| 24 | 30 |
| 25 void UpdateInstallShim::OnUpdateError(int error) { | 31 void UpdateInstallShim::OnUpdateError(int error) { |
| 26 VLOG(1) << "OnUpdateError (" << extension_id_ << ") " << error; | 32 VLOG(1) << "OnUpdateError (" << extension_id_ << ") " << error; |
| 27 } | 33 } |
| 28 | 34 |
| 29 bool UpdateInstallShim::Install(const base::DictionaryValue& manifest, | 35 Result UpdateInstallShim::Install(const base::DictionaryValue& manifest, |
| 30 const base::FilePath& unpack_path) { | 36 const base::FilePath& unpack_path) { |
| 31 base::ScopedTempDir temp_dir; | 37 base::ScopedTempDir temp_dir; |
| 32 if (!temp_dir.CreateUniqueTempDir()) | 38 if (!temp_dir.CreateUniqueTempDir()) |
| 33 return false; | 39 return Result(InstallError::GENERIC_ERROR); |
| 34 | 40 |
| 35 // The UpdateClient code will delete unpack_path if it still exists after | 41 // The UpdateClient code will delete unpack_path if it still exists after |
| 36 // this method is done, so we rename it on top of our temp dir. | 42 // this method is done, so we rename it on top of our temp dir. |
| 37 if (!base::DeleteFile(temp_dir.GetPath(), true) || | 43 if (!base::DeleteFile(temp_dir.GetPath(), true) || |
| 38 !base::Move(unpack_path, temp_dir.GetPath())) { | 44 !base::Move(unpack_path, temp_dir.GetPath())) { |
| 39 LOG(ERROR) << "Trying to install update for " << extension_id_ | 45 LOG(ERROR) << "Trying to install update for " << extension_id_ |
| 40 << "and failed to move " << unpack_path.value() << " to " | 46 << "and failed to move " << unpack_path.value() << " to " |
| 41 << temp_dir.GetPath().value(); | 47 << temp_dir.GetPath().value(); |
| 42 return false; | 48 return Result(InstallError::GENERIC_ERROR); |
| 43 } | 49 } |
| 44 content::BrowserThread::PostTask( | 50 content::BrowserThread::PostTask( |
| 45 content::BrowserThread::UI, FROM_HERE, | 51 content::BrowserThread::UI, FROM_HERE, |
| 46 base::Bind(&UpdateInstallShim::RunCallbackOnUIThread, this, | 52 base::Bind(&UpdateInstallShim::RunCallbackOnUIThread, this, |
| 47 temp_dir.Take())); | 53 temp_dir.Take())); |
| 48 return true; | 54 return Result(InstallError::NONE); |
| 49 } | 55 } |
| 50 | 56 |
| 51 bool UpdateInstallShim::GetInstalledFile(const std::string& file, | 57 bool UpdateInstallShim::GetInstalledFile(const std::string& file, |
| 52 base::FilePath* installed_file) { | 58 base::FilePath* installed_file) { |
| 53 base::FilePath relative_path = base::FilePath::FromUTF8Unsafe(file); | 59 base::FilePath relative_path = base::FilePath::FromUTF8Unsafe(file); |
| 54 if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) | 60 if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) |
| 55 return false; | 61 return false; |
| 56 *installed_file = extension_root_.Append(relative_path); | 62 *installed_file = extension_root_.Append(relative_path); |
| 57 if (!extension_root_.IsParent(*installed_file) || | 63 if (!extension_root_.IsParent(*installed_file) || |
| 58 !base::PathExists(*installed_file)) { | 64 !base::PathExists(*installed_file)) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 74 if (callback_.is_null()) { | 80 if (callback_.is_null()) { |
| 75 content::BrowserThread::PostBlockingPoolTask( | 81 content::BrowserThread::PostBlockingPoolTask( |
| 76 FROM_HERE, base::Bind(base::IgnoreResult(&base::DeleteFile), temp_dir, | 82 FROM_HERE, base::Bind(base::IgnoreResult(&base::DeleteFile), temp_dir, |
| 77 true /*recursive */)); | 83 true /*recursive */)); |
| 78 return; | 84 return; |
| 79 } | 85 } |
| 80 callback_.Run(extension_id_, temp_dir); | 86 callback_.Run(extension_id_, temp_dir); |
| 81 } | 87 } |
| 82 | 88 |
| 83 } // namespace extensions | 89 } // namespace extensions |
| OLD | NEW |