| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/browser/component_updater/test/test_installer.h" | 5 #include "chrome/browser/component_updater/test/test_installer.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 | 10 |
| 11 TestInstaller::TestInstaller() | 11 TestInstaller::TestInstaller() |
| 12 : error_(0), install_count_(0) { | 12 : error_(0), install_count_(0) { |
| 13 } | 13 } |
| 14 | 14 |
| 15 void TestInstaller::OnUpdateError(int error) { | 15 void TestInstaller::OnUpdateError(int error) { |
| 16 error_ = error; | 16 error_ = error; |
| 17 } | 17 } |
| 18 | 18 |
| 19 bool TestInstaller::Install(const base::DictionaryValue& manifest, | 19 bool TestInstaller::Install(const base::DictionaryValue& manifest, |
| 20 const base::FilePath& unpack_path) { | 20 const base::FilePath& unpack_path) { |
| 21 ++install_count_; | 21 ++install_count_; |
| 22 return base::Delete(unpack_path, true); | 22 return base::DeleteFile(unpack_path, true); |
| 23 } | 23 } |
| 24 | 24 |
| 25 bool TestInstaller::GetInstalledFile(const std::string& file, | 25 bool TestInstaller::GetInstalledFile(const std::string& file, |
| 26 base::FilePath* installed_file) { | 26 base::FilePath* installed_file) { |
| 27 return false; | 27 return false; |
| 28 } | 28 } |
| 29 | 29 |
| 30 int TestInstaller::error() const { return error_; } | 30 int TestInstaller::error() const { return error_; } |
| 31 | 31 |
| 32 int TestInstaller::install_count() const { return install_count_; } | 32 int TestInstaller::install_count() const { return install_count_; } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 VersionedTestInstaller::VersionedTestInstaller() { | 49 VersionedTestInstaller::VersionedTestInstaller() { |
| 50 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), | 50 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), |
| 51 &install_directory_); | 51 &install_directory_); |
| 52 } | 52 } |
| 53 | 53 |
| 54 VersionedTestInstaller::~VersionedTestInstaller() { | 54 VersionedTestInstaller::~VersionedTestInstaller() { |
| 55 base::Delete(install_directory_, true); | 55 base::DeleteFile(install_directory_, true); |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 bool VersionedTestInstaller::Install(const base::DictionaryValue& manifest, | 59 bool VersionedTestInstaller::Install(const base::DictionaryValue& manifest, |
| 60 const base::FilePath& unpack_path) { | 60 const base::FilePath& unpack_path) { |
| 61 std::string version_string; | 61 std::string version_string; |
| 62 manifest.GetStringASCII("version", &version_string); | 62 manifest.GetStringASCII("version", &version_string); |
| 63 Version version(version_string.c_str()); | 63 Version version(version_string.c_str()); |
| 64 | 64 |
| 65 base::FilePath path; | 65 base::FilePath path; |
| 66 path = install_directory_.AppendASCII(version.GetString()); | 66 path = install_directory_.AppendASCII(version.GetString()); |
| 67 file_util::CreateDirectory(path.DirName()); | 67 file_util::CreateDirectory(path.DirName()); |
| 68 if (!base::Move(unpack_path, path)) | 68 if (!base::Move(unpack_path, path)) |
| 69 return false; | 69 return false; |
| 70 current_version_ = version; | 70 current_version_ = version; |
| 71 ++install_count_; | 71 ++install_count_; |
| 72 return true; | 72 return true; |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool VersionedTestInstaller::GetInstalledFile(const std::string& file, | 75 bool VersionedTestInstaller::GetInstalledFile(const std::string& file, |
| 76 base::FilePath* installed_file) { | 76 base::FilePath* installed_file) { |
| 77 base::FilePath path; | 77 base::FilePath path; |
| 78 path = install_directory_.AppendASCII(current_version_.GetString()); | 78 path = install_directory_.AppendASCII(current_version_.GetString()); |
| 79 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file)); | 79 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file)); |
| 80 return true; | 80 return true; |
| 81 } | 81 } |
| OLD | NEW |