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

Unified Diff: chrome/installer/util/file_from_template_work_item.h

Issue 10160011: Create VisualElementsManifest.xml from template -- install VisualElements in the version directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove shortname property Created 8 years, 8 months 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 side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698