| 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 <string> | |
| 8 | |
| 9 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 11 #include "base/values.h" | 9 #include "base/values.h" |
| 12 | 10 |
| 13 namespace component_updater { | 11 namespace component_updater { |
| 14 | 12 |
| 15 TestInstaller::TestInstaller() : error_(0), install_count_(0) { | 13 TestInstaller::TestInstaller() |
| 14 : error_(0), install_count_(0) { |
| 16 } | 15 } |
| 17 | 16 |
| 18 void TestInstaller::OnUpdateError(int error) { | 17 void TestInstaller::OnUpdateError(int error) { |
| 19 error_ = error; | 18 error_ = error; |
| 20 } | 19 } |
| 21 | 20 |
| 22 bool TestInstaller::Install(const base::DictionaryValue& manifest, | 21 bool TestInstaller::Install(const base::DictionaryValue& manifest, |
| 23 const base::FilePath& unpack_path) { | 22 const base::FilePath& unpack_path) { |
| 24 ++install_count_; | 23 ++install_count_; |
| 25 return base::DeleteFile(unpack_path, true); | 24 return base::DeleteFile(unpack_path, true); |
| 26 } | 25 } |
| 27 | 26 |
| 27 void TestInstaller::OnInstallError( |
| 28 const InstallerSourceSerializer& serializer) { |
| 29 } |
| 30 |
| 28 bool TestInstaller::GetInstalledFile(const std::string& file, | 31 bool TestInstaller::GetInstalledFile(const std::string& file, |
| 29 base::FilePath* installed_file) { | 32 base::FilePath* installed_file) { |
| 30 return false; | 33 return false; |
| 31 } | 34 } |
| 32 | 35 |
| 33 int TestInstaller::error() const { | 36 int TestInstaller::error() const { return error_; } |
| 34 return error_; | |
| 35 } | |
| 36 | 37 |
| 37 int TestInstaller::install_count() const { | 38 int TestInstaller::install_count() const { return install_count_; } |
| 38 return install_count_; | 39 |
| 39 } | |
| 40 | 40 |
| 41 ReadOnlyTestInstaller::ReadOnlyTestInstaller(const base::FilePath& install_dir) | 41 ReadOnlyTestInstaller::ReadOnlyTestInstaller(const base::FilePath& install_dir) |
| 42 : install_directory_(install_dir) { | 42 : install_directory_(install_dir) { |
| 43 } | 43 } |
| 44 | 44 |
| 45 ReadOnlyTestInstaller::~ReadOnlyTestInstaller() { | 45 ReadOnlyTestInstaller::~ReadOnlyTestInstaller() { |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool ReadOnlyTestInstaller::GetInstalledFile(const std::string& file, | 48 bool ReadOnlyTestInstaller::GetInstalledFile(const std::string& file, |
| 49 base::FilePath* installed_file) { | 49 base::FilePath* installed_file) { |
| 50 *installed_file = install_directory_.AppendASCII(file); | 50 *installed_file = install_directory_.AppendASCII(file); |
| 51 return true; | 51 return true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 |
| 54 VersionedTestInstaller::VersionedTestInstaller() { | 55 VersionedTestInstaller::VersionedTestInstaller() { |
| 55 base::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &install_directory_); | 56 base::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &install_directory_); |
| 56 } | 57 } |
| 57 | 58 |
| 58 VersionedTestInstaller::~VersionedTestInstaller() { | 59 VersionedTestInstaller::~VersionedTestInstaller() { |
| 59 base::DeleteFile(install_directory_, true); | 60 base::DeleteFile(install_directory_, true); |
| 60 } | 61 } |
| 61 | 62 |
| 63 |
| 62 bool VersionedTestInstaller::Install(const base::DictionaryValue& manifest, | 64 bool VersionedTestInstaller::Install(const base::DictionaryValue& manifest, |
| 63 const base::FilePath& unpack_path) { | 65 const base::FilePath& unpack_path) { |
| 64 std::string version_string; | 66 std::string version_string; |
| 65 manifest.GetStringASCII("version", &version_string); | 67 manifest.GetStringASCII("version", &version_string); |
| 66 Version version(version_string.c_str()); | 68 Version version(version_string.c_str()); |
| 67 | 69 |
| 68 base::FilePath path; | 70 base::FilePath path; |
| 69 path = install_directory_.AppendASCII(version.GetString()); | 71 path = install_directory_.AppendASCII(version.GetString()); |
| 70 base::CreateDirectory(path.DirName()); | 72 base::CreateDirectory(path.DirName()); |
| 71 if (!base::Move(unpack_path, path)) | 73 if (!base::Move(unpack_path, path)) |
| 72 return false; | 74 return false; |
| 73 current_version_ = version; | 75 current_version_ = version; |
| 74 ++install_count_; | 76 ++install_count_; |
| 75 return true; | 77 return true; |
| 76 } | 78 } |
| 77 | 79 |
| 78 bool VersionedTestInstaller::GetInstalledFile(const std::string& file, | 80 bool VersionedTestInstaller::GetInstalledFile(const std::string& file, |
| 79 base::FilePath* installed_file) { | 81 base::FilePath* installed_file) { |
| 80 base::FilePath path; | 82 base::FilePath path; |
| 81 path = install_directory_.AppendASCII(current_version_.GetString()); | 83 path = install_directory_.AppendASCII(current_version_.GetString()); |
| 82 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file)); | 84 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file)); |
| 83 return true; | 85 return true; |
| 84 } | 86 } |
| 85 | 87 |
| 86 } // namespace component_updater | 88 } // namespace component_updater |
| 89 |
| OLD | NEW |