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