| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_INSTALLER_UTIL_DELETE_TREE_WORK_ITEM_H_ | 5 #ifndef CHROME_INSTALLER_UTIL_DELETE_TREE_WORK_ITEM_H_ |
| 6 #define CHROME_INSTALLER_UTIL_DELETE_TREE_WORK_ITEM_H_ | 6 #define CHROME_INSTALLER_UTIL_DELETE_TREE_WORK_ITEM_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 15 #include "chrome/installer/util/work_item.h" | 10 #include "chrome/installer/util/work_item.h" |
| 16 | 11 |
| 17 // A WorkItem subclass that recursively deletes a file system hierarchy at the | 12 // A WorkItem subclass that recursively deletes a file system hierarchy at the |
| 18 // given root path. The file system hierarchy could be a single file, or a | 13 // given root path. The file system hierarchy could be a single file, or a |
| 19 // directory. | 14 // directory. |
| 20 // The file system hierarchy to be deleted can have one or more key files. If | 15 // The file system hierarchy to be deleted can have one or more key files. If |
| 21 // specified, deletion will be performed only if all key files are not in use. | 16 // specified, deletion will be performed only if all key files are not in use. |
| 22 class DeleteTreeWorkItem : public WorkItem { | 17 class DeleteTreeWorkItem : public WorkItem { |
| 23 public: | 18 public: |
| 24 ~DeleteTreeWorkItem() override; | 19 ~DeleteTreeWorkItem() override; |
| 25 | 20 |
| 26 bool Do() override; | |
| 27 | |
| 28 void Rollback() override; | |
| 29 | |
| 30 private: | 21 private: |
| 31 friend class WorkItem; | 22 friend class WorkItem; |
| 32 | 23 |
| 33 // |root_path| will be moved to |temp_path| (rather than copied there and then | 24 // |root_path| will be moved to |temp_path| (rather than copied there and then |
| 34 // deleted). For best results in this case, |root_path| and |temp_path| | 25 // deleted). For best results in this case, |root_path| and |temp_path| |
| 35 // should be on the same volume; otherwise, the move will be simulated | 26 // should be on the same volume; otherwise, the move will be simulated |
| 36 // by a copy-and-delete operation. | 27 // by a copy-and-delete operation. |
| 37 DeleteTreeWorkItem(const base::FilePath& root_path, | 28 DeleteTreeWorkItem(const base::FilePath& root_path, |
| 38 const base::FilePath& temp_path, | 29 const base::FilePath& temp_path); |
| 39 const std::vector<base::FilePath>& key_paths); | 30 |
| 31 // WorkItem: |
| 32 bool DoImpl() override; |
| 33 void RollbackImpl() override; |
| 40 | 34 |
| 41 // Return temporary path for work based on |backup_path_| and |root_path_|. | 35 // Return temporary path for work based on |backup_path_| and |root_path_|. |
| 42 base::FilePath GetBackupPath(); | 36 base::FilePath GetBackupPath(); |
| 43 | 37 |
| 44 // Attempts to delete |root_path_|. Returns true on success. | 38 // Attempts to delete |root_path_|. Returns true on success. |
| 45 bool DeleteRoot(); | 39 bool DeleteRoot(); |
| 46 | 40 |
| 47 // Attempts to move |root_path_| to backup. Returns true on success. | 41 // Attempts to move |root_path_| to backup. Returns true on success. |
| 48 bool MoveRootToBackup(); | 42 bool MoveRootToBackup(); |
| 49 | 43 |
| 50 // Root path to delete. | 44 // Root path to delete. |
| 51 base::FilePath root_path_; | 45 const base::FilePath root_path_; |
| 52 | 46 |
| 53 // Temporary directory that can be used. | 47 // Temporary directory that can be used. |
| 54 base::FilePath temp_path_; | 48 const base::FilePath temp_path_; |
| 55 | |
| 56 // The number of key files. | |
| 57 ptrdiff_t num_key_files_; | |
| 58 | |
| 59 // Contains the paths to the key files. If specified, deletion will be | |
| 60 // performed only if none of the key files are in use. | |
| 61 std::unique_ptr<base::FilePath[]> key_paths_; | |
| 62 | |
| 63 // Contains the temp directories for the backed-up key files. The directories | |
| 64 // are created and populated in Do() as-needed. We don't use a standard | |
| 65 // container for this since base::ScopedTempDir isn't CopyConstructible. | |
| 66 std::unique_ptr<base::ScopedTempDir[]> key_backup_paths_; | |
| 67 | 49 |
| 68 // The temporary directory into which the original root_path_ has been moved. | 50 // The temporary directory into which the original root_path_ has been moved. |
| 69 base::ScopedTempDir backup_path_; | 51 base::ScopedTempDir backup_path_; |
| 70 | 52 |
| 71 // Set to true once root_path_ has been moved into backup_path_. | 53 // Set to true once root_path_ has been moved into backup_path_. |
| 72 bool moved_to_backup_; | 54 bool moved_to_backup_ = false; |
| 73 }; | 55 }; |
| 74 | 56 |
| 75 #endif // CHROME_INSTALLER_UTIL_DELETE_TREE_WORK_ITEM_H_ | 57 #endif // CHROME_INSTALLER_UTIL_DELETE_TREE_WORK_ITEM_H_ |
| OLD | NEW |