c9bc0b1690c3d62ccfb76499b3ddde8cf43ecf11
[platform/framework/web/crosswalk.git] / src / chrome / browser / component_updater / component_patcher_operation.h
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 "base/files/file_path.h"
12 #include "chrome/browser/component_updater/component_unpacker.h"
13
14 namespace base {
15 class DictionaryValue;
16 }  // namespace base
17
18 namespace component_updater {
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(base::DictionaryValue* command_args,
33                                const base::FilePath& input_dir,
34                                const base::FilePath& unpack_dir,
35                                ComponentPatcher* patcher,
36                                ComponentInstaller* installer,
37                                int* error);
38
39  protected:
40   std::string output_sha256_;
41   base::FilePath output_abs_path_;
42
43  private:
44   ComponentUnpacker::Error CheckHash();
45
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;
53
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,
58                                          int* error) = 0;
59
60   DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp);
61 };
62
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
65 // installed.
66 class DeltaUpdateOpCopy : public DeltaUpdateOp {
67  public:
68   DeltaUpdateOpCopy();
69
70  private:
71   // Overrides of DeltaUpdateOp.
72   virtual ComponentUnpacker::Error DoParseArguments(
73       base::DictionaryValue* command_args,
74       const base::FilePath& input_dir,
75       ComponentInstaller* installer) OVERRIDE;
76
77   virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
78                                          int* error) OVERRIDE;
79
80   base::FilePath input_abs_path_;
81
82   DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy);
83 };
84
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 {
90  public:
91   DeltaUpdateOpCreate();
92
93  private:
94   // Overrides of DeltaUpdateOp.
95   virtual ComponentUnpacker::Error DoParseArguments(
96       base::DictionaryValue* command_args,
97       const base::FilePath& input_dir,
98       ComponentInstaller* installer) OVERRIDE;
99
100   virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
101                                          int* error) OVERRIDE;
102
103   base::FilePath patch_abs_path_;
104
105   DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate);
106 };
107
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 {
112  public:
113   DeltaUpdateOpPatchBsdiff();
114
115  private:
116   // Overrides of DeltaUpdateOp.
117   virtual ComponentUnpacker::Error DoParseArguments(
118       base::DictionaryValue* command_args,
119       const base::FilePath& input_dir,
120       ComponentInstaller* installer) OVERRIDE;
121
122   virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
123                                          int* error) OVERRIDE;
124
125   base::FilePath patch_abs_path_;
126   base::FilePath input_abs_path_;
127
128   DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchBsdiff);
129 };
130
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 {
135  public:
136   DeltaUpdateOpPatchCourgette();
137
138  private:
139   // Overrides of DeltaUpdateOp.
140   virtual ComponentUnpacker::Error DoParseArguments(
141       base::DictionaryValue* command_args,
142       const base::FilePath& input_dir,
143       ComponentInstaller* installer) OVERRIDE;
144
145   virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher,
146                                          int* error) OVERRIDE;
147
148   base::FilePath patch_abs_path_;
149   base::FilePath input_abs_path_;
150
151   DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchCourgette);
152 };
153
154 // Factory function to create DeltaUpdateOp instances.
155 DeltaUpdateOp* CreateDeltaUpdateOp(base::DictionaryValue* command);
156
157 }  // namespace component_updater
158
159 #endif  // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_