Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / component_updater / test / test_installer.cc
blob2f1a7bc3861f0b23914063414523429a90664c4c
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
3 // found in the LICENSE file.
5 #include "chrome/browser/component_updater/test/test_installer.h"
7 #include <string>
9 #include "base/file_util.h"
10 #include "base/files/file_path.h"
11 #include "base/values.h"
13 namespace component_updater {
15 TestInstaller::TestInstaller() : error_(0), install_count_(0) {
18 void TestInstaller::OnUpdateError(int error) {
19 error_ = error;
22 bool TestInstaller::Install(const base::DictionaryValue& manifest,
23 const base::FilePath& unpack_path) {
24 ++install_count_;
25 return base::DeleteFile(unpack_path, true);
28 bool TestInstaller::GetInstalledFile(const std::string& file,
29 base::FilePath* installed_file) {
30 return false;
33 int TestInstaller::error() const {
34 return error_;
37 int TestInstaller::install_count() const {
38 return install_count_;
41 ReadOnlyTestInstaller::ReadOnlyTestInstaller(const base::FilePath& install_dir)
42 : install_directory_(install_dir) {
45 ReadOnlyTestInstaller::~ReadOnlyTestInstaller() {
48 bool ReadOnlyTestInstaller::GetInstalledFile(const std::string& file,
49 base::FilePath* installed_file) {
50 *installed_file = install_directory_.AppendASCII(file);
51 return true;
54 VersionedTestInstaller::VersionedTestInstaller() {
55 base::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &install_directory_);
58 VersionedTestInstaller::~VersionedTestInstaller() {
59 base::DeleteFile(install_directory_, true);
62 bool VersionedTestInstaller::Install(const base::DictionaryValue& manifest,
63 const base::FilePath& unpack_path) {
64 std::string version_string;
65 manifest.GetStringASCII("version", &version_string);
66 Version version(version_string.c_str());
68 base::FilePath path;
69 path = install_directory_.AppendASCII(version.GetString());
70 base::CreateDirectory(path.DirName());
71 if (!base::Move(unpack_path, path))
72 return false;
73 current_version_ = version;
74 ++install_count_;
75 return true;
78 bool VersionedTestInstaller::GetInstalledFile(const std::string& file,
79 base::FilePath* installed_file) {
80 base::FilePath path;
81 path = install_directory_.AppendASCII(current_version_.GetString());
82 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file));
83 return true;
86 } // namespace component_updater