OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_ | 5 #ifndef COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_ |
6 #define COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_ | 6 #define COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "components/update_client/component_patcher.h" | 14 #include "components/update_client/component_patcher.h" |
15 #include "components/update_client/component_unpacker.h" | 15 #include "components/update_client/component_unpacker.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class DictionaryValue; | 18 class DictionaryValue; |
19 } // namespace base | 19 } // namespace base |
20 | 20 |
21 namespace update_client { | 21 namespace update_client { |
22 | 22 |
23 extern const char kOp[]; | 23 extern const char kOp[]; |
24 extern const char kBsdiff[]; | 24 extern const char kBsdiff[]; |
25 extern const char kCourgette[]; | 25 extern const char kCourgette[]; |
26 extern const char kInput[]; | 26 extern const char kInput[]; |
27 extern const char kPatch[]; | 27 extern const char kPatch[]; |
28 | 28 |
29 class CrxInstaller; | 29 class CrxInstaller; |
| 30 class OutOfProcessPatcher; |
30 enum class UnpackerError; | 31 enum class UnpackerError; |
31 | 32 |
32 class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> { | 33 class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> { |
33 public: | 34 public: |
34 DeltaUpdateOp(); | 35 DeltaUpdateOp(); |
35 | 36 |
36 // Parses, runs, and verifies the operation. Calls |callback| with the | 37 // Parses, runs, and verifies the operation. Calls |callback| with the |
37 // result of the operation. The callback is called using |task_runner|. | 38 // result of the operation. The callback is called using |task_runner|. |
38 void Run(const base::DictionaryValue* command_args, | 39 void Run(const base::DictionaryValue* command_args, |
39 const base::FilePath& input_dir, | 40 const base::FilePath& input_dir, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const base::FilePath& input_dir, | 120 const base::FilePath& input_dir, |
120 const scoped_refptr<CrxInstaller>& installer) override; | 121 const scoped_refptr<CrxInstaller>& installer) override; |
121 | 122 |
122 void DoRun(const ComponentPatcher::Callback& callback) override; | 123 void DoRun(const ComponentPatcher::Callback& callback) override; |
123 | 124 |
124 base::FilePath patch_abs_path_; | 125 base::FilePath patch_abs_path_; |
125 | 126 |
126 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); | 127 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); |
127 }; | 128 }; |
128 | 129 |
129 // An interface an embedder may fulfill to enable out-of-process patching. | |
130 class OutOfProcessPatcher | |
131 : public base::RefCountedThreadSafe<OutOfProcessPatcher> { | |
132 public: | |
133 virtual void Patch( | |
134 const std::string& operation, | |
135 scoped_refptr<base::SequencedTaskRunner> task_runner, | |
136 const base::FilePath& input_abs_path, | |
137 const base::FilePath& patch_abs_path, | |
138 const base::FilePath& output_abs_path, | |
139 base::Callback<void(int result)> callback) = 0; | |
140 | |
141 protected: | |
142 friend class base::RefCountedThreadSafe<OutOfProcessPatcher>; | |
143 | |
144 virtual ~OutOfProcessPatcher() {} | |
145 }; | |
146 | |
147 // Both 'bsdiff' and 'courgette' operations take an existing file on disk, | 130 // Both 'bsdiff' and 'courgette' operations take an existing file on disk, |
148 // and a bsdiff- or Courgette-format patch file provided in the delta update | 131 // and a bsdiff- or Courgette-format patch file provided in the delta update |
149 // package, and run bsdiff or Courgette to construct an output file in the | 132 // package, and run bsdiff or Courgette to construct an output file in the |
150 // unpacking directory. | 133 // unpacking directory. |
151 class DeltaUpdateOpPatch : public DeltaUpdateOp { | 134 class DeltaUpdateOpPatch : public DeltaUpdateOp { |
152 public: | 135 public: |
153 // |out_of_process_patcher| may be NULL. | 136 // |out_of_process_patcher| may be NULL. |
154 DeltaUpdateOpPatch(const std::string& operation, | 137 DeltaUpdateOpPatch( |
155 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher); | 138 const std::string& operation, |
| 139 const scoped_refptr<OutOfProcessPatcher>& out_of_process_patcher); |
156 | 140 |
157 private: | 141 private: |
158 ~DeltaUpdateOpPatch() override; | 142 ~DeltaUpdateOpPatch() override; |
159 | 143 |
160 // Overrides of DeltaUpdateOp. | 144 // Overrides of DeltaUpdateOp. |
161 UnpackerError DoParseArguments( | 145 UnpackerError DoParseArguments( |
162 const base::DictionaryValue* command_args, | 146 const base::DictionaryValue* command_args, |
163 const base::FilePath& input_dir, | 147 const base::FilePath& input_dir, |
164 const scoped_refptr<CrxInstaller>& installer) override; | 148 const scoped_refptr<CrxInstaller>& installer) override; |
165 | 149 |
166 void DoRun(const ComponentPatcher::Callback& callback) override; | 150 void DoRun(const ComponentPatcher::Callback& callback) override; |
167 | 151 |
168 // |success_code| is the code that indicates a successful patch. | 152 // |success_code| is the code that indicates a successful patch. |
169 // |result| is the code the patching operation returned. | 153 // |result| is the code the patching operation returned. |
170 void DonePatching(const ComponentPatcher::Callback& callback, int result); | 154 void DonePatching(const ComponentPatcher::Callback& callback, int result); |
171 | 155 |
172 std::string operation_; | 156 std::string operation_; |
173 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_; | 157 const scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_; |
174 base::FilePath patch_abs_path_; | 158 base::FilePath patch_abs_path_; |
175 base::FilePath input_abs_path_; | 159 base::FilePath input_abs_path_; |
176 | 160 |
177 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch); | 161 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch); |
178 }; | 162 }; |
179 | 163 |
180 DeltaUpdateOp* CreateDeltaUpdateOp( | 164 DeltaUpdateOp* CreateDeltaUpdateOp( |
181 const std::string& operation, | 165 const std::string& operation, |
182 const scoped_refptr<OutOfProcessPatcher>& out_of_process_patcher); | 166 const scoped_refptr<OutOfProcessPatcher>& out_of_process_patcher); |
183 | 167 |
184 } // namespace update_client | 168 } // namespace update_client |
185 | 169 |
186 #endif // COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_ | 170 #endif // COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_ |
OLD | NEW |