| Index: chrome/installer/util/file_from_template_work_item.h
|
| diff --git a/chrome/installer/util/file_from_template_work_item.h b/chrome/installer/util/file_from_template_work_item.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..18a1da50391fdb29416240c91f2410e09420fd38
|
| --- /dev/null
|
| +++ b/chrome/installer/util/file_from_template_work_item.h
|
| @@ -0,0 +1,63 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROME_INSTALLER_UTIL_FILE_FROM_TEMPLATE_WORK_ITEM_H_
|
| +#define CHROME_INSTALLER_UTIL_FILE_FROM_TEMPLATE_WORK_ITEM_H_
|
| +#pragma once
|
| +
|
| +#include <map>
|
| +
|
| +#include "base/file_path.h"
|
| +#include "base/scoped_temp_dir.h"
|
| +#include "chrome/installer/util/work_item.h"
|
| +
|
| +// A WorkItem subclass that takes a template in which variables are surrounded
|
| +// by |kVariableDefiner| (e.g. "this is a $VARIABLE$ to be replaced") and
|
| +// replaces their value as specified by the provided mappings before writing the
|
| +// resulting file to the specified destination directory.
|
| +// NOTE: All templates should end with the .template extension.
|
| +class FileFromTemplateWorkItem : public WorkItem {
|
| + public:
|
| + virtual ~FileFromTemplateWorkItem();
|
| +
|
| + virtual bool Do();
|
| +
|
| + virtual void Rollback();
|
| +
|
| + private:
|
| + friend class WorkItem;
|
| +
|
| + // |source_path| specifies file containing the template to be written out
|
| + // to |dest_path|. To facilitate rollback, the caller needs to supply a
|
| + // temporary directory, |temp_dir| to save the original files if they exist
|
| + // under |dest_path|.
|
| + // |mappings| is a key-value mapping of each variable (key) found in the file
|
| + // which will be replaced by its value in |dest_path|.
|
| + // |dest_path| will be overwritten if it already exists.
|
| + FileFromTemplateWorkItem(const FilePath& source_path,
|
| + const FilePath& dest_path,
|
| + const FilePath& temp_dir,
|
| + const std::map<string16, string16>& mappings);
|
| +
|
| + // Source path to read the template from.
|
| + FilePath source_path_;
|
| +
|
| + // Destination path to write the template to.
|
| + FilePath dest_path_;
|
| +
|
| + // Temporary directory to backup |dest_path_| (if it already exists).
|
| + FilePath temp_dir_;
|
| +
|
| + // The key-value pairs used to replace template variables by their values.
|
| + std::map<string16, string16> mappings_;
|
| +
|
| + // Temporary directory into which the original |dest_path_| has been moved.
|
| + ScopedTempDir backup_path_;
|
| +
|
| + // Whether the original files have been moved to backup path under
|
| + // temporary directory. If true, moving back is needed during rollback.
|
| + bool moved_to_backup_;
|
| +};
|
| +
|
| +#endif // CHROME_INSTALLER_UTIL_FILE_FROM_TEMPLATE_WORK_ITEM_H_
|
|
|