OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ |
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ | 6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | |
9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | |
10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/ref_counted.h" | |
15 #include "chrome/browser/component_updater/component_patcher.h" | |
12 #include "chrome/browser/component_updater/component_unpacker.h" | 16 #include "chrome/browser/component_updater/component_unpacker.h" |
17 #include "content/public/browser/utility_process_host_client.h" | |
13 | 18 |
14 namespace base { | 19 namespace base { |
15 class DictionaryValue; | 20 class DictionaryValue; |
16 } // namespace base | 21 } // namespace base |
17 | 22 |
18 namespace component_updater { | 23 namespace component_updater { |
19 | 24 |
20 class ComponentInstaller; | 25 class ComponentInstaller; |
21 class ComponentPatcher; | |
22 | 26 |
23 class DeltaUpdateOp { | 27 class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> { |
24 public: | 28 public: |
29 DeltaUpdateOp(); | |
25 | 30 |
26 DeltaUpdateOp(); | 31 // Parses, runs, and verifies the operation. Calls |callback| with the |
32 // result of the operation. The callback is called using |task_runner|. | |
33 void Run(base::DictionaryValue* command_args, | |
34 const base::FilePath& input_dir, | |
35 const base::FilePath& unpack_dir, | |
36 ComponentInstaller* installer, | |
37 bool in_process, | |
38 const base::Callback<void(ComponentUnpacker::Error, int)>& callback, | |
39 scoped_refptr<base::SequencedTaskRunner> task_runner); | |
40 | |
41 protected: | |
42 typedef base::Callback<void(ComponentUnpacker::Error, int)> Callback; | |
Sorin Jianu
2014/02/27 20:53:57
This type could be a typedef in ComponentUnpacker.
waffles
2014/02/28 00:52:43
Done.
| |
43 | |
27 virtual ~DeltaUpdateOp(); | 44 virtual ~DeltaUpdateOp(); |
28 | 45 |
29 // Parses, runs, and verifies the operation, returning an error code if an | 46 bool InProcess(); |
Sorin Jianu
2014/02/27 20:53:57
Is there a way to remove some of the protected mem
waffles
2014/02/28 00:52:43
Let's leave this one to a later CL if you don't mi
| |
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 | 47 |
39 protected: | |
40 std::string output_sha256_; | 48 std::string output_sha256_; |
41 base::FilePath output_abs_path_; | 49 base::FilePath output_abs_path_; |
42 | 50 |
43 private: | 51 private: |
52 friend class base::RefCountedThreadSafe<DeltaUpdateOp>; | |
53 | |
44 ComponentUnpacker::Error CheckHash(); | 54 ComponentUnpacker::Error CheckHash(); |
45 | 55 |
46 // Subclasses must override DoParseArguments to parse operation-specific | 56 // Subclasses must override DoParseArguments to parse operation-specific |
47 // arguments. DoParseArguments returns DELTA_OK on success; any other code | 57 // arguments. DoParseArguments returns DELTA_OK on success; any other code |
48 // represents failure. | 58 // represents failure. |
49 virtual ComponentUnpacker::Error DoParseArguments( | 59 virtual ComponentUnpacker::Error DoParseArguments( |
50 base::DictionaryValue* command_args, | 60 base::DictionaryValue* command_args, |
51 const base::FilePath& input_dir, | 61 const base::FilePath& input_dir, |
52 ComponentInstaller* installer) = 0; | 62 ComponentInstaller* installer) = 0; |
53 | 63 |
54 // Subclasses must override DoRun to actually perform the patching operation. | 64 // Subclasses must override DoRun to actually perform the patching operation. |
55 // DoRun returns DELTA_OK on success; any other code represents failure. | 65 // They must call the provided callback when they have completed their |
56 // Additional error information can be returned in the |error| parameter. | 66 // operations. In practice, the provided callback is always for "DoneRunning". |
57 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | 67 virtual void DoRun(const Callback& callback) = 0; |
58 int* error) = 0; | 68 |
69 // Callback given to subclasses for when they complete their operation. | |
70 // Validates the output, and posts a task to the patching operation's | |
71 // callback. | |
72 void DoneRunning(ComponentUnpacker::Error error, int extended_error); | |
73 | |
74 bool in_process_; | |
75 Callback callback_; | |
76 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
59 | 77 |
60 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp); | 78 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp); |
61 }; | 79 }; |
62 | 80 |
63 // A 'copy' operation takes a file currently residing on the disk and moves it | 81 // 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 | 82 // into the unpacking directory: this represents "no change" in the file being |
65 // installed. | 83 // installed. |
66 class DeltaUpdateOpCopy : public DeltaUpdateOp { | 84 class DeltaUpdateOpCopy : public DeltaUpdateOp { |
67 public: | 85 public: |
68 DeltaUpdateOpCopy(); | 86 DeltaUpdateOpCopy(); |
69 | 87 |
88 protected: | |
89 virtual ~DeltaUpdateOpCopy(); | |
90 | |
70 private: | 91 private: |
71 // Overrides of DeltaUpdateOp. | 92 // Overrides of DeltaUpdateOp. |
72 virtual ComponentUnpacker::Error DoParseArguments( | 93 virtual ComponentUnpacker::Error DoParseArguments( |
73 base::DictionaryValue* command_args, | 94 base::DictionaryValue* command_args, |
74 const base::FilePath& input_dir, | 95 const base::FilePath& input_dir, |
75 ComponentInstaller* installer) OVERRIDE; | 96 ComponentInstaller* installer) OVERRIDE; |
76 | 97 |
77 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | 98 virtual void DoRun(const Callback& callback) OVERRIDE; |
78 int* error) OVERRIDE; | |
79 | 99 |
80 base::FilePath input_abs_path_; | 100 base::FilePath input_abs_path_; |
81 | 101 |
82 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy); | 102 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy); |
83 }; | 103 }; |
84 | 104 |
85 // A 'create' operation takes a full file that was sent in the delta update | 105 // 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 | 106 // 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 | 107 // addition of a new file, or a file so different that no bandwidth could be |
88 // saved by transmitting a differential update. | 108 // saved by transmitting a differential update. |
89 class DeltaUpdateOpCreate : public DeltaUpdateOp { | 109 class DeltaUpdateOpCreate : public DeltaUpdateOp { |
90 public: | 110 public: |
91 DeltaUpdateOpCreate(); | 111 DeltaUpdateOpCreate(); |
92 | 112 |
113 protected: | |
114 virtual ~DeltaUpdateOpCreate(); | |
115 | |
93 private: | 116 private: |
94 // Overrides of DeltaUpdateOp. | 117 // Overrides of DeltaUpdateOp. |
95 virtual ComponentUnpacker::Error DoParseArguments( | 118 virtual ComponentUnpacker::Error DoParseArguments( |
96 base::DictionaryValue* command_args, | 119 base::DictionaryValue* command_args, |
97 const base::FilePath& input_dir, | 120 const base::FilePath& input_dir, |
98 ComponentInstaller* installer) OVERRIDE; | 121 ComponentInstaller* installer) OVERRIDE; |
99 | 122 |
100 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | 123 virtual void DoRun(const Callback& callback) OVERRIDE; |
101 int* error) OVERRIDE; | |
102 | 124 |
103 base::FilePath patch_abs_path_; | 125 base::FilePath patch_abs_path_; |
104 | 126 |
105 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); | 127 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); |
106 }; | 128 }; |
107 | 129 |
108 // A 'bsdiff' operation takes an existing file on disk, and a bsdiff- | 130 class DeltaUpdateOpPatchTraits { |
Sorin Jianu
2014/02/27 20:53:57
Let's rename that Traits to something else, with t
waffles
2014/02/28 00:52:43
Done.
| |
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: | 131 public: |
113 DeltaUpdateOpPatchBsdiff(); | 132 virtual ~DeltaUpdateOpPatchTraits(); |
133 | |
134 // Returns an integer to add to error codes to disambiguate their source. | |
Sorin Jianu
2014/02/27 20:53:57
can any of these be const?
waffles
2014/02/28 00:52:43
Done.
| |
135 virtual int GetErrorOffset() = 0; | |
136 | |
137 // Returns the "error code" that is expected in the successful install case. | |
138 virtual int GetSuccessCode() = 0; | |
139 | |
140 // Returns an IPC message that will start patching if it is sent to a | |
141 // UtilityProcessClient. | |
142 virtual IPC::Message* GetPatchMessage(base::FilePath input_abs_path, | |
143 base::FilePath patch_abs_path, | |
144 base::FilePath output_abs_path) = 0; | |
145 | |
146 // Does the actual patching operation, and returns an error code. | |
147 virtual int Patch(base::FilePath input_abs_path, | |
148 base::FilePath patch_abs_path, | |
149 base::FilePath output_abs_path) = 0; | |
150 }; | |
151 | |
152 // Both 'bsdiff' and 'courgette' operations take an existing file on disk, | |
153 // and a bsdiff- or Courgette-format patch file provided in the delta update | |
154 // package, and run bsdiff or Courgette to construct an output file in the | |
155 // unpacking directory. | |
156 class DeltaUpdateOpPatch : public DeltaUpdateOp, | |
157 public content::UtilityProcessHostClient { | |
158 public: | |
159 explicit DeltaUpdateOpPatch(scoped_ptr<DeltaUpdateOpPatchTraits> traits); | |
160 | |
161 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
Sorin Jianu
2014/02/27 20:53:57
Can we make these two virtuals private and add the
waffles
2014/02/28 00:52:43
Done.
| |
162 | |
163 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | |
164 | |
165 protected: | |
166 virtual ~DeltaUpdateOpPatch(); | |
114 | 167 |
115 private: | 168 private: |
169 void DonePatching(ComponentUnpacker::Error error, int error_code); | |
170 | |
171 void OnPatchSucceeded(); | |
172 | |
173 void OnPatchFailed(int error_code); | |
174 | |
116 // Overrides of DeltaUpdateOp. | 175 // Overrides of DeltaUpdateOp. |
117 virtual ComponentUnpacker::Error DoParseArguments( | 176 virtual ComponentUnpacker::Error DoParseArguments( |
118 base::DictionaryValue* command_args, | 177 base::DictionaryValue* command_args, |
119 const base::FilePath& input_dir, | 178 const base::FilePath& input_dir, |
120 ComponentInstaller* installer) OVERRIDE; | 179 ComponentInstaller* installer) OVERRIDE; |
121 | 180 |
122 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | 181 virtual void DoRun(const Callback& callback) OVERRIDE; |
123 int* error) OVERRIDE; | |
124 | 182 |
183 void StartProcess(); | |
184 | |
185 Callback callback_; | |
125 base::FilePath patch_abs_path_; | 186 base::FilePath patch_abs_path_; |
126 base::FilePath input_abs_path_; | 187 base::FilePath input_abs_path_; |
188 scoped_ptr<DeltaUpdateOpPatchTraits> traits_; | |
127 | 189 |
128 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchBsdiff); | 190 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch); |
129 }; | 191 }; |
130 | 192 |
131 // A 'courgette' operation takes an existing file on disk, and a Courgette- | 193 // Factory functions to create DeltaUpdateOp instances. |
132 // format patch file provided in the delta update package, and runs Courgette | 194 DeltaUpdateOp* CreateDeltaUpdateOp(const base::DictionaryValue& command); |
133 // to construct an output file in the unpacking directory. | |
134 class DeltaUpdateOpPatchCourgette : public DeltaUpdateOp { | |
135 public: | |
136 DeltaUpdateOpPatchCourgette(); | |
137 | 195 |
138 private: | 196 DeltaUpdateOp* CreateDeltaUpdateOp(const std::string& operation); |
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 | 197 |
157 } // namespace component_updater | 198 } // namespace component_updater |
158 | 199 |
159 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ | 200 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ |
OLD | NEW |