| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ | |
| 6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "chrome/browser/component_updater/component_unpacker.h" | |
| 12 | |
| 13 namespace base { | |
| 14 | |
| 15 class FilePath; | |
| 16 class DictionaryValue; | |
| 17 | |
| 18 } // namespace base | |
| 19 | |
| 20 class ComponentInstaller; | |
| 21 class ComponentPatcher; | |
| 22 | |
| 23 class DeltaUpdateOp { | |
| 24 public: | |
| 25 | |
| 26 DeltaUpdateOp(); | |
| 27 virtual ~DeltaUpdateOp(); | |
| 28 | |
| 29 // Parses, runs, and verifies the operation, returning an error code if an | |
| 30 // error is encountered, and DELTA_OK otherwise. In case of errors, | |
| 31 // extended error information can be returned in the |error| parameter. | |
| 32 ComponentUnpacker::Error Run( | |
| 33 base::DictionaryValue* command_args, | |
| 34 const base::FilePath& input_dir, | |
| 35 const base::FilePath& unpack_dir, | |
| 36 ComponentPatcher* patcher, | |
| 37 ComponentInstaller* installer, | |
| 38 int* error); | |
| 39 | |
| 40 protected: | |
| 41 std::string output_sha256_; | |
| 42 base::FilePath output_abs_path_; | |
| 43 | |
| 44 private: | |
| 45 ComponentUnpacker::Error CheckHash(); | |
| 46 | |
| 47 // Subclasses must override DoParseArguments to parse operation-specific | |
| 48 // arguments. DoParseArguments returns DELTA_OK on success; any other code | |
| 49 // represents failure. | |
| 50 virtual ComponentUnpacker::Error DoParseArguments( | |
| 51 base::DictionaryValue* command_args, | |
| 52 const base::FilePath& input_dir, | |
| 53 ComponentInstaller* installer) = 0; | |
| 54 | |
| 55 // Subclasses must override DoRun to actually perform the patching operation. | |
| 56 // DoRun returns DELTA_OK on success; any other code represents failure. | |
| 57 // Additional error information can be returned in the |error| parameter. | |
| 58 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | |
| 59 int* error) = 0; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp); | |
| 62 }; | |
| 63 | |
| 64 // A 'copy' operation takes a file currently residing on the disk and moves it | |
| 65 // into the unpacking directory: this represents "no change" in the file being | |
| 66 // installed. | |
| 67 class DeltaUpdateOpCopy : public DeltaUpdateOp { | |
| 68 public: | |
| 69 DeltaUpdateOpCopy(); | |
| 70 | |
| 71 private: | |
| 72 // Overrides of DeltaUpdateOp. | |
| 73 virtual ComponentUnpacker::Error DoParseArguments( | |
| 74 base::DictionaryValue* command_args, | |
| 75 const base::FilePath& input_dir, | |
| 76 ComponentInstaller* installer) OVERRIDE; | |
| 77 | |
| 78 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | |
| 79 int* error) OVERRIDE; | |
| 80 | |
| 81 base::FilePath input_abs_path_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy); | |
| 84 }; | |
| 85 | |
| 86 // A 'create' operation takes a full file that was sent in the delta update | |
| 87 // archive and moves it into the unpacking directory: this represents the | |
| 88 // addition of a new file, or a file so different that no bandwidth could be | |
| 89 // saved by transmitting a differential update. | |
| 90 class DeltaUpdateOpCreate : public DeltaUpdateOp { | |
| 91 public: | |
| 92 DeltaUpdateOpCreate(); | |
| 93 | |
| 94 private: | |
| 95 // Overrides of DeltaUpdateOp. | |
| 96 virtual ComponentUnpacker::Error DoParseArguments( | |
| 97 base::DictionaryValue* command_args, | |
| 98 const base::FilePath& input_dir, | |
| 99 ComponentInstaller* installer) OVERRIDE; | |
| 100 | |
| 101 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | |
| 102 int* error) OVERRIDE; | |
| 103 | |
| 104 base::FilePath patch_abs_path_; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); | |
| 107 }; | |
| 108 | |
| 109 // A 'bsdiff' operation takes an existing file on disk, and a bsdiff- | |
| 110 // format patch file provided in the delta update package, and runs bsdiff | |
| 111 // to construct an output file in the unpacking directory. | |
| 112 class DeltaUpdateOpPatchBsdiff : public DeltaUpdateOp { | |
| 113 public: | |
| 114 DeltaUpdateOpPatchBsdiff(); | |
| 115 | |
| 116 private: | |
| 117 // Overrides of DeltaUpdateOp. | |
| 118 virtual ComponentUnpacker::Error DoParseArguments( | |
| 119 base::DictionaryValue* command_args, | |
| 120 const base::FilePath& input_dir, | |
| 121 ComponentInstaller* installer) OVERRIDE; | |
| 122 | |
| 123 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | |
| 124 int* error) OVERRIDE; | |
| 125 | |
| 126 base::FilePath patch_abs_path_; | |
| 127 base::FilePath input_abs_path_; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchBsdiff); | |
| 130 }; | |
| 131 | |
| 132 // A 'courgette' operation takes an existing file on disk, and a Courgette- | |
| 133 // format patch file provided in the delta update package, and runs Courgette | |
| 134 // to construct an output file in the unpacking directory. | |
| 135 class DeltaUpdateOpPatchCourgette : public DeltaUpdateOp { | |
| 136 public: | |
| 137 DeltaUpdateOpPatchCourgette(); | |
| 138 | |
| 139 private: | |
| 140 // Overrides of DeltaUpdateOp. | |
| 141 virtual ComponentUnpacker::Error DoParseArguments( | |
| 142 base::DictionaryValue* command_args, | |
| 143 const base::FilePath& input_dir, | |
| 144 ComponentInstaller* installer) OVERRIDE; | |
| 145 | |
| 146 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | |
| 147 int* error) OVERRIDE; | |
| 148 | |
| 149 base::FilePath patch_abs_path_; | |
| 150 base::FilePath input_abs_path_; | |
| 151 | |
| 152 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchCourgette); | |
| 153 }; | |
| 154 | |
| 155 // Factory function to create DeltaUpdateOp instances. | |
| 156 DeltaUpdateOp* CreateDeltaUpdateOp(base::DictionaryValue* command); | |
| 157 | |
| 158 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ | |
| OLD | NEW |