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 "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(
33 base::DictionaryValue
* command_args
,
34 const base::FilePath
& input_dir
,
35 const base::FilePath
& unpack_dir
,
36 ComponentPatcher
* patcher
,
37 ComponentInstaller
* installer
,
41 std::string output_sha256_
;
42 base::FilePath output_abs_path_
;
45 ComponentUnpacker::Error
CheckHash();
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;
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
,
61 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp
);
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
67 class DeltaUpdateOpCopy
: public DeltaUpdateOp
{
72 // Overrides of DeltaUpdateOp.
73 virtual ComponentUnpacker::Error
DoParseArguments(
74 base::DictionaryValue
* command_args
,
75 const base::FilePath
& input_dir
,
76 ComponentInstaller
* installer
) OVERRIDE
;
78 virtual ComponentUnpacker::Error
DoRun(ComponentPatcher
* patcher
,
81 base::FilePath input_abs_path_
;
83 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy
);
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
{
92 DeltaUpdateOpCreate();
95 // Overrides of DeltaUpdateOp.
96 virtual ComponentUnpacker::Error
DoParseArguments(
97 base::DictionaryValue
* command_args
,
98 const base::FilePath
& input_dir
,
99 ComponentInstaller
* installer
) OVERRIDE
;
101 virtual ComponentUnpacker::Error
DoRun(ComponentPatcher
* patcher
,
102 int* error
) OVERRIDE
;
104 base::FilePath patch_abs_path_
;
106 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate
);
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
{
114 DeltaUpdateOpPatchBsdiff();
117 // Overrides of DeltaUpdateOp.
118 virtual ComponentUnpacker::Error
DoParseArguments(
119 base::DictionaryValue
* command_args
,
120 const base::FilePath
& input_dir
,
121 ComponentInstaller
* installer
) OVERRIDE
;
123 virtual ComponentUnpacker::Error
DoRun(ComponentPatcher
* patcher
,
124 int* error
) OVERRIDE
;
126 base::FilePath patch_abs_path_
;
127 base::FilePath input_abs_path_
;
129 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchBsdiff
);
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
{
137 DeltaUpdateOpPatchCourgette();
140 // Overrides of DeltaUpdateOp.
141 virtual ComponentUnpacker::Error
DoParseArguments(
142 base::DictionaryValue
* command_args
,
143 const base::FilePath
& input_dir
,
144 ComponentInstaller
* installer
) OVERRIDE
;
146 virtual ComponentUnpacker::Error
DoRun(ComponentPatcher
* patcher
,
147 int* error
) OVERRIDE
;
149 base::FilePath patch_abs_path_
;
150 base::FilePath input_abs_path_
;
152 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchCourgette
);
155 // Factory function to create DeltaUpdateOp instances.
156 DeltaUpdateOp
* CreateDeltaUpdateOp(base::DictionaryValue
* command
);
158 } // namespace component_updater
160 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_