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> |
Sorin Jianu
2014/02/03 20:57:57
needs one line after the lib include.
waffles
2014/02/07 01:00:59
Done.
| |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | |
10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/memory/weak_ptr.h" | |
14 #include "chrome/browser/component_updater/component_patcher.h" | |
12 #include "chrome/browser/component_updater/component_unpacker.h" | 15 #include "chrome/browser/component_updater/component_unpacker.h" |
16 #include "content/public/browser/utility_process_host_client.h" | |
13 | 17 |
14 namespace base { | 18 namespace base { |
15 class DictionaryValue; | 19 class DictionaryValue; |
16 } // namespace base | 20 } // namespace base |
17 | 21 |
18 namespace component_updater { | 22 namespace component_updater { |
19 | 23 |
20 class ComponentInstaller; | 24 class ComponentInstaller; |
21 class ComponentPatcher; | |
22 | 25 |
23 class DeltaUpdateOp { | 26 class DeltaUpdateOp { |
24 public: | 27 public: |
25 | |
26 DeltaUpdateOp(); | 28 DeltaUpdateOp(); |
27 virtual ~DeltaUpdateOp(); | 29 virtual ~DeltaUpdateOp(); |
28 | 30 |
29 // Parses, runs, and verifies the operation, returning an error code if an | 31 // Parses, runs, and verifies the operation. Calls |callback| with the |
30 // error is encountered, and DELTA_OK otherwise. In case of errors, | 32 // result of the operateration. The callback is called using |task_runner|. |
Sorin Jianu
2014/02/03 20:57:57
operateration
waffles
2014/02/07 01:00:59
Done. That's a fun word to say.
| |
31 // extended error information can be returned in the |error| parameter. | 33 void Run(base::DictionaryValue* command_args, |
32 ComponentUnpacker::Error Run(base::DictionaryValue* command_args, | 34 const base::FilePath& input_dir, |
33 const base::FilePath& input_dir, | 35 const base::FilePath& unpack_dir, |
34 const base::FilePath& unpack_dir, | 36 ComponentInstaller* installer, |
35 ComponentPatcher* patcher, | 37 bool in_process, |
36 ComponentInstaller* installer, | 38 const base::Callback<void(ComponentUnpacker::Error, int)>& callback, |
37 int* error); | 39 scoped_refptr<base::SequencedTaskRunner> task_runner); |
38 | 40 |
39 protected: | 41 protected: |
42 base::WeakPtr<DeltaUpdateOp> GetWeakPtr(); | |
43 | |
40 std::string output_sha256_; | 44 std::string output_sha256_; |
41 base::FilePath output_abs_path_; | 45 base::FilePath output_abs_path_; |
46 bool in_process_; | |
Sorin Jianu
2014/02/03 20:57:57
most likely, we want in_process_ to be immutable i
waffles
2014/02/07 01:00:59
Done. I'm a little resistant to making the remaini
Sorin Jianu
2014/02/27 20:53:57
Well, a nice symmetry would be that all of them wo
| |
42 | 47 |
43 private: | 48 private: |
44 ComponentUnpacker::Error CheckHash(); | 49 ComponentUnpacker::Error CheckHash(); |
45 | 50 |
46 // Subclasses must override DoParseArguments to parse operation-specific | 51 // Subclasses must override DoParseArguments to parse operation-specific |
47 // arguments. DoParseArguments returns DELTA_OK on success; any other code | 52 // arguments. DoParseArguments returns DELTA_OK on success; any other code |
48 // represents failure. | 53 // represents failure. |
49 virtual ComponentUnpacker::Error DoParseArguments( | 54 virtual ComponentUnpacker::Error DoParseArguments( |
50 base::DictionaryValue* command_args, | 55 base::DictionaryValue* command_args, |
51 const base::FilePath& input_dir, | 56 const base::FilePath& input_dir, |
52 ComponentInstaller* installer) = 0; | 57 ComponentInstaller* installer) = 0; |
53 | 58 |
54 // Subclasses must override DoRun to actually perform the patching operation. | 59 // Subclasses must override DoRun to actually perform the patching operation. |
55 // DoRun returns DELTA_OK on success; any other code represents failure. | 60 // They must call the provided callback when they have completed their |
56 // Additional error information can be returned in the |error| parameter. | 61 // operations. |
57 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | 62 virtual void DoRun( |
58 int* error) = 0; | 63 const base::Callback<void(ComponentUnpacker::Error, int)>& callback) = 0; |
Sorin Jianu
2014/02/03 20:57:57
I wonder if you could find a way to indicate in a
waffles
2014/02/07 01:00:59
I've added a comment, but I'm not sure these detai
| |
64 | |
65 // Callback given to subclasses for when they complete their operation. | |
66 // Validates the output, and posts a task to the patching operation's | |
67 // callback. | |
68 void DoneRunning(ComponentUnpacker::Error error, int extended_error); | |
69 | |
70 base::Callback<void(ComponentUnpacker::Error, int)> callback_; | |
71 base::WeakPtrFactory<DeltaUpdateOp> ptr_factory_; | |
72 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
59 | 73 |
60 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp); | 74 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp); |
61 }; | 75 }; |
62 | 76 |
63 // A 'copy' operation takes a file currently residing on the disk and moves it | 77 // 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 | 78 // into the unpacking directory: this represents "no change" in the file being |
65 // installed. | 79 // installed. |
66 class DeltaUpdateOpCopy : public DeltaUpdateOp { | 80 class DeltaUpdateOpCopy : public DeltaUpdateOp { |
67 public: | 81 public: |
68 DeltaUpdateOpCopy(); | 82 DeltaUpdateOpCopy(); |
69 | 83 |
70 private: | 84 private: |
71 // Overrides of DeltaUpdateOp. | 85 // Overrides of DeltaUpdateOp. |
72 virtual ComponentUnpacker::Error DoParseArguments( | 86 virtual ComponentUnpacker::Error DoParseArguments( |
73 base::DictionaryValue* command_args, | 87 base::DictionaryValue* command_args, |
74 const base::FilePath& input_dir, | 88 const base::FilePath& input_dir, |
75 ComponentInstaller* installer) OVERRIDE; | 89 ComponentInstaller* installer) OVERRIDE; |
76 | 90 |
77 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | 91 virtual void DoRun( |
78 int* error) OVERRIDE; | 92 const base::Callback<void(ComponentUnpacker::Error, int)>& callback) |
Sorin Jianu
2014/02/03 20:57:57
maybe typedef the callback type to make the lines
waffles
2014/02/07 01:00:59
Done. I've never been a fan of typedefs in C++.
Sorin Jianu
2014/02/27 20:53:57
Agreed, but what is the option? The callback libra
| |
93 OVERRIDE; | |
79 | 94 |
80 base::FilePath input_abs_path_; | 95 base::FilePath input_abs_path_; |
81 | 96 |
82 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy); | 97 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy); |
83 }; | 98 }; |
84 | 99 |
85 // A 'create' operation takes a full file that was sent in the delta update | 100 // 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 | 101 // 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 | 102 // addition of a new file, or a file so different that no bandwidth could be |
88 // saved by transmitting a differential update. | 103 // saved by transmitting a differential update. |
89 class DeltaUpdateOpCreate : public DeltaUpdateOp { | 104 class DeltaUpdateOpCreate : public DeltaUpdateOp { |
90 public: | 105 public: |
91 DeltaUpdateOpCreate(); | 106 DeltaUpdateOpCreate(); |
92 | 107 |
93 private: | 108 private: |
94 // Overrides of DeltaUpdateOp. | 109 // Overrides of DeltaUpdateOp. |
95 virtual ComponentUnpacker::Error DoParseArguments( | 110 virtual ComponentUnpacker::Error DoParseArguments( |
96 base::DictionaryValue* command_args, | 111 base::DictionaryValue* command_args, |
97 const base::FilePath& input_dir, | 112 const base::FilePath& input_dir, |
98 ComponentInstaller* installer) OVERRIDE; | 113 ComponentInstaller* installer) OVERRIDE; |
99 | 114 |
100 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | 115 virtual void DoRun( |
101 int* error) OVERRIDE; | 116 const base::Callback<void(ComponentUnpacker::Error, int)>& callback) |
117 OVERRIDE; | |
102 | 118 |
103 base::FilePath patch_abs_path_; | 119 base::FilePath patch_abs_path_; |
104 | 120 |
105 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); | 121 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); |
106 }; | 122 }; |
107 | 123 |
108 // A 'bsdiff' operation takes an existing file on disk, and a bsdiff- | 124 // Both 'bsdiff' and 'courgette' operations take an existing file on disk, |
109 // format patch file provided in the delta update package, and runs bsdiff | 125 // and a bsdiff- or Courgette-format patch file provided in the delta update |
110 // to construct an output file in the unpacking directory. | 126 // package, and run bsdiff or Courgette to construct an output file in the |
111 class DeltaUpdateOpPatchBsdiff : public DeltaUpdateOp { | 127 // unpacking directory. |
128 class DeltaUpdateOpPatch : public DeltaUpdateOp { | |
112 public: | 129 public: |
113 DeltaUpdateOpPatchBsdiff(); | 130 explicit DeltaUpdateOpPatch(component_updater::PatchType patch_type); |
131 | |
132 virtual ~DeltaUpdateOpPatch(); | |
133 | |
134 void DonePatching(bool success, int error_code); | |
135 | |
136 // An inner class is used so that DeltaUpdateOpPatch does not need to derive | |
137 // from UtilityProcessHostClient (because it is refcounted). | |
138 class PatcherBridge : public content::UtilityProcessHostClient { | |
139 public: | |
140 explicit PatcherBridge(DeltaUpdateOpPatch* op); | |
141 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
142 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | |
143 | |
144 private: | |
145 virtual ~PatcherBridge(); | |
146 void OnPatchSucceeded(); | |
147 void OnPatchFailed(int error_code); | |
148 DeltaUpdateOpPatch* op_; | |
149 DISALLOW_COPY_AND_ASSIGN(PatcherBridge); | |
150 }; | |
151 | |
152 base::Callback<void(ComponentUnpacker::Error, int)>callback_; | |
Sorin Jianu
2014/02/03 20:57:57
callback_ is declared as a public member.
Sorin Jianu
2014/02/03 20:57:57
one space between the type and variable name?
waffles
2014/02/07 01:00:59
Done.
waffles
2014/02/07 01:00:59
Done.
| |
114 | 153 |
115 private: | 154 private: |
116 // Overrides of DeltaUpdateOp. | 155 // 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( | 156 virtual ComponentUnpacker::Error DoParseArguments( |
141 base::DictionaryValue* command_args, | 157 base::DictionaryValue* command_args, |
142 const base::FilePath& input_dir, | 158 const base::FilePath& input_dir, |
143 ComponentInstaller* installer) OVERRIDE; | 159 ComponentInstaller* installer) OVERRIDE; |
144 | 160 |
145 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, | 161 virtual void DoRun( |
146 int* error) OVERRIDE; | 162 const base::Callback<void(ComponentUnpacker::Error, int)>& callback) |
163 OVERRIDE; | |
164 | |
165 void StartProcess(); | |
147 | 166 |
148 base::FilePath patch_abs_path_; | 167 base::FilePath patch_abs_path_; |
149 base::FilePath input_abs_path_; | 168 base::FilePath input_abs_path_; |
169 const component_updater::PatchType patch_type_; | |
170 scoped_refptr<PatcherBridge> bridge_; | |
150 | 171 |
151 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchCourgette); | 172 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch); |
152 }; | 173 }; |
153 | 174 |
154 // Factory function to create DeltaUpdateOp instances. | 175 // Factory function to create DeltaUpdateOp instances. |
155 DeltaUpdateOp* CreateDeltaUpdateOp(base::DictionaryValue* command); | 176 DeltaUpdateOp* CreateDeltaUpdateOp(base::DictionaryValue* command); |
156 | 177 |
157 } // namespace component_updater | 178 } // namespace component_updater |
158 | 179 |
159 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ | 180 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ |
OLD | NEW |