| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/common/extensions/extension_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // Get a temp directory on the same file system as the profile. | 80 // Get a temp directory on the same file system as the profile. |
| 81 base::FilePath install_temp_dir = GetInstallTempDir(extensions_dir); | 81 base::FilePath install_temp_dir = GetInstallTempDir(extensions_dir); |
| 82 base::ScopedTempDir extension_temp_dir; | 82 base::ScopedTempDir extension_temp_dir; |
| 83 if (install_temp_dir.empty() || | 83 if (install_temp_dir.empty() || |
| 84 !extension_temp_dir.CreateUniqueTempDirUnderPath(install_temp_dir)) { | 84 !extension_temp_dir.CreateUniqueTempDirUnderPath(install_temp_dir)) { |
| 85 LOG(ERROR) << "Creating of temp dir under in the profile failed."; | 85 LOG(ERROR) << "Creating of temp dir under in the profile failed."; |
| 86 return base::FilePath(); | 86 return base::FilePath(); |
| 87 } | 87 } |
| 88 base::FilePath crx_temp_source = | 88 base::FilePath crx_temp_source = |
| 89 extension_temp_dir.path().Append(unpacked_source_dir.BaseName()); | 89 extension_temp_dir.path().Append(unpacked_source_dir.BaseName()); |
| 90 if (!file_util::Move(unpacked_source_dir, crx_temp_source)) { | 90 if (!base::Move(unpacked_source_dir, crx_temp_source)) { |
| 91 LOG(ERROR) << "Moving extension from : " << unpacked_source_dir.value() | 91 LOG(ERROR) << "Moving extension from : " << unpacked_source_dir.value() |
| 92 << " to : " << crx_temp_source.value() << " failed."; | 92 << " to : " << crx_temp_source.value() << " failed."; |
| 93 return base::FilePath(); | 93 return base::FilePath(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Try to find a free directory. There can be legitimate conflicts in the case | 96 // Try to find a free directory. There can be legitimate conflicts in the case |
| 97 // of overinstallation of the same version. | 97 // of overinstallation of the same version. |
| 98 const int kMaxAttempts = 100; | 98 const int kMaxAttempts = 100; |
| 99 for (int i = 0; i < kMaxAttempts; ++i) { | 99 for (int i = 0; i < kMaxAttempts; ++i) { |
| 100 base::FilePath candidate = extension_dir.AppendASCII( | 100 base::FilePath candidate = extension_dir.AppendASCII( |
| 101 base::StringPrintf("%s_%u", version.c_str(), i)); | 101 base::StringPrintf("%s_%u", version.c_str(), i)); |
| 102 if (!file_util::PathExists(candidate)) { | 102 if (!file_util::PathExists(candidate)) { |
| 103 version_dir = candidate; | 103 version_dir = candidate; |
| 104 break; | 104 break; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 if (version_dir.empty()) { | 108 if (version_dir.empty()) { |
| 109 LOG(ERROR) << "Could not find a home for extension " << id << " with " | 109 LOG(ERROR) << "Could not find a home for extension " << id << " with " |
| 110 << "version " << version << "."; | 110 << "version " << version << "."; |
| 111 return base::FilePath(); | 111 return base::FilePath(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 if (!file_util::Move(crx_temp_source, version_dir)) { | 114 if (!base::Move(crx_temp_source, version_dir)) { |
| 115 LOG(ERROR) << "Installing extension from : " << crx_temp_source.value() | 115 LOG(ERROR) << "Installing extension from : " << crx_temp_source.value() |
| 116 << " into : " << version_dir.value() << " failed."; | 116 << " into : " << version_dir.value() << " failed."; |
| 117 return base::FilePath(); | 117 return base::FilePath(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 return version_dir; | 120 return version_dir; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void UninstallExtension(const base::FilePath& extensions_dir, | 123 void UninstallExtension(const base::FilePath& extensions_dir, |
| 124 const std::string& id) { | 124 const std::string& id) { |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 return base::FilePath(); | 567 return base::FilePath(); |
| 568 } | 568 } |
| 569 return temp_path; | 569 return temp_path; |
| 570 } | 570 } |
| 571 | 571 |
| 572 void DeleteFile(const base::FilePath& path, bool recursive) { | 572 void DeleteFile(const base::FilePath& path, bool recursive) { |
| 573 base::Delete(path, recursive); | 573 base::Delete(path, recursive); |
| 574 } | 574 } |
| 575 | 575 |
| 576 } // namespace extension_file_util | 576 } // namespace extension_file_util |
| OLD | NEW |