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.
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h"
12 #include "chrome/browser/component_updater/component_unpacker.h"
15 class DictionaryValue;
18 namespace component_updater {
20 class ComponentInstaller;
21 class ComponentPatcher;
27 virtual ~DeltaUpdateOp();
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(base::DictionaryValue* command_args,
33 const base::FilePath& input_dir,
34 const base::FilePath& unpack_dir,
35 ComponentPatcher* patcher,
36 ComponentInstaller* installer,
40 std::string output_sha256_;
41 base::FilePath output_abs_path_;
44 ComponentUnpacker::Error CheckHash();
46 // Subclasses must override DoParseArguments to parse operation-specific
47 // arguments. DoParseArguments returns DELTA_OK on success; any other code
48 // represents failure.
49 virtual ComponentUnpacker::Error DoParseArguments(
50 base::DictionaryValue* command_args,
51 const base::FilePath& input_dir,
52 ComponentInstaller* installer) = 0;
54 // Subclasses must override DoRun to actually perform the patching operation.
55 // DoRun returns DELTA_OK on success; any other code represents failure.
56 // Additional error information can be returned in the |error| parameter.
57 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
60 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp);
63 // A 'copy' operation takes a file currently residing on the disk and moves it
64 // into the unpacking directory: this represents "no change" in the file being
66 class DeltaUpdateOpCopy : public DeltaUpdateOp {
71 // Overrides of DeltaUpdateOp.
72 virtual ComponentUnpacker::Error DoParseArguments(
73 base::DictionaryValue* command_args,
74 const base::FilePath& input_dir,
75 ComponentInstaller* installer) OVERRIDE;
77 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
80 base::FilePath input_abs_path_;
82 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy);
85 // A 'create' operation takes a full file that was sent in the delta update
86 // archive and moves it into the unpacking directory: this represents the
87 // addition of a new file, or a file so different that no bandwidth could be
88 // saved by transmitting a differential update.
89 class DeltaUpdateOpCreate : public DeltaUpdateOp {
91 DeltaUpdateOpCreate();
94 // Overrides of DeltaUpdateOp.
95 virtual ComponentUnpacker::Error DoParseArguments(
96 base::DictionaryValue* command_args,
97 const base::FilePath& input_dir,
98 ComponentInstaller* installer) OVERRIDE;
100 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
101 int* error) OVERRIDE;
103 base::FilePath patch_abs_path_;
105 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate);
108 // A 'bsdiff' operation takes an existing file on disk, and a bsdiff-
109 // format patch file provided in the delta update package, and runs bsdiff
110 // to construct an output file in the unpacking directory.
111 class DeltaUpdateOpPatchBsdiff : public DeltaUpdateOp {
113 DeltaUpdateOpPatchBsdiff();
116 // Overrides of DeltaUpdateOp.
117 virtual ComponentUnpacker::Error DoParseArguments(
118 base::DictionaryValue* command_args,
119 const base::FilePath& input_dir,
120 ComponentInstaller* installer) OVERRIDE;
122 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
123 int* error) OVERRIDE;
125 base::FilePath patch_abs_path_;
126 base::FilePath input_abs_path_;
128 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchBsdiff);
131 // A 'courgette' operation takes an existing file on disk, and a Courgette-
132 // format patch file provided in the delta update package, and runs Courgette
133 // to construct an output file in the unpacking directory.
134 class DeltaUpdateOpPatchCourgette : public DeltaUpdateOp {
136 DeltaUpdateOpPatchCourgette();
139 // Overrides of DeltaUpdateOp.
140 virtual ComponentUnpacker::Error DoParseArguments(
141 base::DictionaryValue* command_args,
142 const base::FilePath& input_dir,
143 ComponentInstaller* installer) OVERRIDE;
145 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
146 int* error) OVERRIDE;
148 base::FilePath patch_abs_path_;
149 base::FilePath input_abs_path_;
151 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchCourgette);
154 // Factory function to create DeltaUpdateOp instances.
155 DeltaUpdateOp* CreateDeltaUpdateOp(base::DictionaryValue* command);
157 } // namespace component_updater
159 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_