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