Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / component_updater / component_patcher_operation.h
blob42b289db9eb30e7de1c49bc8c4946b0c2927524f
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_
8 #include <string>
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "chrome/browser/component_updater/component_unpacker.h"
13 namespace base {
14 class FilePath;
15 class DictionaryValue;
16 } // namespace base
18 namespace component_updater {
20 class ComponentInstaller;
21 class ComponentPatcher;
23 class DeltaUpdateOp {
24 public:
26 DeltaUpdateOp();
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,
38 int* error);
40 protected:
41 std::string output_sha256_;
42 base::FilePath output_abs_path_;
44 private:
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,
59 int* error) = 0;
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
66 // installed.
67 class DeltaUpdateOpCopy : public DeltaUpdateOp {
68 public:
69 DeltaUpdateOpCopy();
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;
78 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
79 int* error) OVERRIDE;
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 {
91 public:
92 DeltaUpdateOpCreate();
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;
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 {
113 public:
114 DeltaUpdateOpPatchBsdiff();
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;
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 {
136 public:
137 DeltaUpdateOpPatchCourgette();
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;
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_