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