| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 #ifndef CHROME_INSTALLER_UTIL_FILE_FROM_TEMPLATE_WORK_ITEM_H_ |
| 6 #define CHROME_INSTALLER_UTIL_FILE_FROM_TEMPLATE_WORK_ITEM_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 |
| 11 #include "base/file_path.h" |
| 12 #include "base/scoped_temp_dir.h" |
| 13 #include "chrome/installer/util/work_item.h" |
| 14 |
| 15 // A WorkItem subclass that takes a template in which variables are surrounded |
| 16 // by |kVariableDefiner| (e.g. "this is a $VARIABLE$ to be replaced") and |
| 17 // replaces their value as specified by the provided mappings before writing the |
| 18 // resulting file to the specified destination directory. |
| 19 // NOTE: All templates should end with the .template extension. |
| 20 class FileFromTemplateWorkItem : public WorkItem { |
| 21 public: |
| 22 virtual ~FileFromTemplateWorkItem(); |
| 23 |
| 24 virtual bool Do(); |
| 25 |
| 26 virtual void Rollback(); |
| 27 |
| 28 private: |
| 29 friend class WorkItem; |
| 30 |
| 31 // |source_path| specifies file containing the template to be written out |
| 32 // to |dest_path|. To facilitate rollback, the caller needs to supply a |
| 33 // temporary directory, |temp_dir| to save the original files if they exist |
| 34 // under |dest_path|. |
| 35 // |mappings| is a key-value mapping of each variable (key) found in the file |
| 36 // which will be replaced by its value in |dest_path|. |
| 37 // |dest_path| will be overwritten if it already exists. |
| 38 FileFromTemplateWorkItem(const FilePath& source_path, |
| 39 const FilePath& dest_path, |
| 40 const FilePath& temp_dir, |
| 41 const std::map<string16, string16>& mappings); |
| 42 |
| 43 // Source path to read the template from. |
| 44 FilePath source_path_; |
| 45 |
| 46 // Destination path to write the template to. |
| 47 FilePath dest_path_; |
| 48 |
| 49 // Temporary directory to backup |dest_path_| (if it already exists). |
| 50 FilePath temp_dir_; |
| 51 |
| 52 // The key-value pairs used to replace template variables by their values. |
| 53 std::map<string16, string16> mappings_; |
| 54 |
| 55 // Temporary directory into which the original |dest_path_| has been moved. |
| 56 ScopedTempDir backup_path_; |
| 57 |
| 58 // Whether the original files have been moved to backup path under |
| 59 // temporary directory. If true, moving back is needed during rollback. |
| 60 bool moved_to_backup_; |
| 61 }; |
| 62 |
| 63 #endif // CHROME_INSTALLER_UTIL_FILE_FROM_TEMPLATE_WORK_ITEM_H_ |
| OLD | NEW |