Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: components/update_client/test_installer.cc

Issue 2479633003: Makes the component installers return a Result instead of a bool. (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/update_client/test_installer.h ('k') | components/update_client/update_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
12 13
13 namespace update_client { 14 namespace update_client {
14 15
15 TestInstaller::TestInstaller() : error_(0), install_count_(0) { 16 TestInstaller::TestInstaller() : error_(0), install_count_(0) {
16 } 17 }
17 18
18 void TestInstaller::OnUpdateError(int error) { 19 void TestInstaller::OnUpdateError(int error) {
19 error_ = error; 20 error_ = error;
20 } 21 }
21 22
22 bool TestInstaller::Install(const base::DictionaryValue& manifest, 23 CrxInstaller::Result TestInstaller::Install(
23 const base::FilePath& unpack_path) { 24 const base::DictionaryValue& manifest,
25 const base::FilePath& unpack_path) {
24 ++install_count_; 26 ++install_count_;
25 return base::DeleteFile(unpack_path, true); 27 if (!base::DeleteFile(unpack_path, true))
28 return Result(InstallError::GENERIC_ERROR);
29
30 return Result(InstallError::NONE);
26 } 31 }
27 32
28 bool TestInstaller::GetInstalledFile(const std::string& file, 33 bool TestInstaller::GetInstalledFile(const std::string& file,
29 base::FilePath* installed_file) { 34 base::FilePath* installed_file) {
30 return false; 35 return false;
31 } 36 }
32 37
33 TestInstaller::~TestInstaller() { 38 TestInstaller::~TestInstaller() {
34 } 39 }
35 40
(...skipping 15 matching lines...) Expand all
51 } 56 }
52 57
53 VersionedTestInstaller::VersionedTestInstaller() { 58 VersionedTestInstaller::VersionedTestInstaller() {
54 base::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &install_directory_); 59 base::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &install_directory_);
55 } 60 }
56 61
57 VersionedTestInstaller::~VersionedTestInstaller() { 62 VersionedTestInstaller::~VersionedTestInstaller() {
58 base::DeleteFile(install_directory_, true); 63 base::DeleteFile(install_directory_, true);
59 } 64 }
60 65
61 bool VersionedTestInstaller::Install(const base::DictionaryValue& manifest, 66 CrxInstaller::Result VersionedTestInstaller::Install(
62 const base::FilePath& unpack_path) { 67 const base::DictionaryValue& manifest,
68 const base::FilePath& unpack_path) {
63 std::string version_string; 69 std::string version_string;
64 manifest.GetStringASCII("version", &version_string); 70 manifest.GetStringASCII("version", &version_string);
65 base::Version version(version_string.c_str()); 71 base::Version version(version_string.c_str());
66 72
67 base::FilePath path; 73 base::FilePath path;
68 path = install_directory_.AppendASCII(version.GetString()); 74 path = install_directory_.AppendASCII(version.GetString());
69 base::CreateDirectory(path.DirName()); 75 base::CreateDirectory(path.DirName());
70 if (!base::Move(unpack_path, path)) 76 if (!base::Move(unpack_path, path))
71 return false; 77 return Result(InstallError::GENERIC_ERROR);
72 current_version_ = version; 78 current_version_ = version;
73 ++install_count_; 79 ++install_count_;
74 return true; 80 return Result(InstallError::NONE);
75 } 81 }
76 82
77 bool VersionedTestInstaller::GetInstalledFile(const std::string& file, 83 bool VersionedTestInstaller::GetInstalledFile(const std::string& file,
78 base::FilePath* installed_file) { 84 base::FilePath* installed_file) {
79 base::FilePath path; 85 base::FilePath path;
80 path = install_directory_.AppendASCII(current_version_.GetString()); 86 path = install_directory_.AppendASCII(current_version_.GetString());
81 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file)); 87 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file));
82 return true; 88 return true;
83 } 89 }
84 90
85 } // namespace update_client 91 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/test_installer.h ('k') | components/update_client/update_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698