Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/component_updater/component_patcher_operation.h

Issue 25909005: Use UtilityProcessHost to patch files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nonblocking
Patch Set: Fix ASAN failure, rebase to LKGR/259825 Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(const 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 ComponentUnpacker::Callback& callback,
39 scoped_refptr<base::SequencedTaskRunner> task_runner);
40
41 protected:
27 virtual ~DeltaUpdateOp(); 42 virtual ~DeltaUpdateOp();
28 43
29 // Parses, runs, and verifies the operation, returning an error code if an 44 bool InProcess();
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 45
39 protected:
40 std::string output_sha256_; 46 std::string output_sha256_;
41 base::FilePath output_abs_path_; 47 base::FilePath output_abs_path_;
42 48
43 private: 49 private:
50 friend class base::RefCountedThreadSafe<DeltaUpdateOp>;
51
52
44 ComponentUnpacker::Error CheckHash(); 53 ComponentUnpacker::Error CheckHash();
45 54
46 // Subclasses must override DoParseArguments to parse operation-specific 55 // Subclasses must override DoParseArguments to parse operation-specific
47 // arguments. DoParseArguments returns DELTA_OK on success; any other code 56 // arguments. DoParseArguments returns DELTA_OK on success; any other code
48 // represents failure. 57 // represents failure.
49 virtual ComponentUnpacker::Error DoParseArguments( 58 virtual ComponentUnpacker::Error DoParseArguments(
50 base::DictionaryValue* command_args, 59 const base::DictionaryValue* command_args,
51 const base::FilePath& input_dir, 60 const base::FilePath& input_dir,
52 ComponentInstaller* installer) = 0; 61 ComponentInstaller* installer) = 0;
53 62
54 // Subclasses must override DoRun to actually perform the patching operation. 63 // Subclasses must override DoRun to actually perform the patching operation.
55 // DoRun returns DELTA_OK on success; any other code represents failure. 64 // They must call the provided callback when they have completed their
56 // Additional error information can be returned in the |error| parameter. 65 // operations. In practice, the provided callback is always for "DoneRunning".
57 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, 66 virtual void DoRun(const ComponentUnpacker::Callback& callback) = 0;
58 int* error) = 0; 67
68 // Callback given to subclasses for when they complete their operation.
69 // Validates the output, and posts a task to the patching operation's
70 // callback.
71 void DoneRunning(ComponentUnpacker::Error error, int extended_error);
72
73 bool in_process_;
74 ComponentUnpacker::Callback callback_;
75 scoped_refptr<base::SequencedTaskRunner> task_runner_;
59 76
60 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp); 77 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOp);
61 }; 78 };
62 79
63 // A 'copy' operation takes a file currently residing on the disk and moves it 80 // 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 81 // into the unpacking directory: this represents "no change" in the file being
65 // installed. 82 // installed.
66 class DeltaUpdateOpCopy : public DeltaUpdateOp { 83 class DeltaUpdateOpCopy : public DeltaUpdateOp {
67 public: 84 public:
68 DeltaUpdateOpCopy(); 85 DeltaUpdateOpCopy();
69 86
70 private: 87 private:
88 virtual ~DeltaUpdateOpCopy();
89
71 // Overrides of DeltaUpdateOp. 90 // Overrides of DeltaUpdateOp.
72 virtual ComponentUnpacker::Error DoParseArguments( 91 virtual ComponentUnpacker::Error DoParseArguments(
73 base::DictionaryValue* command_args, 92 const base::DictionaryValue* command_args,
74 const base::FilePath& input_dir, 93 const base::FilePath& input_dir,
75 ComponentInstaller* installer) OVERRIDE; 94 ComponentInstaller* installer) OVERRIDE;
76 95
77 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, 96 virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE;
78 int* error) OVERRIDE;
79 97
80 base::FilePath input_abs_path_; 98 base::FilePath input_abs_path_;
81 99
82 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy); 100 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy);
83 }; 101 };
84 102
85 // A 'create' operation takes a full file that was sent in the delta update 103 // 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 104 // 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 105 // addition of a new file, or a file so different that no bandwidth could be
88 // saved by transmitting a differential update. 106 // saved by transmitting a differential update.
89 class DeltaUpdateOpCreate : public DeltaUpdateOp { 107 class DeltaUpdateOpCreate : public DeltaUpdateOp {
90 public: 108 public:
91 DeltaUpdateOpCreate(); 109 DeltaUpdateOpCreate();
92 110
93 private: 111 private:
112 virtual ~DeltaUpdateOpCreate();
113
94 // Overrides of DeltaUpdateOp. 114 // Overrides of DeltaUpdateOp.
95 virtual ComponentUnpacker::Error DoParseArguments( 115 virtual ComponentUnpacker::Error DoParseArguments(
96 base::DictionaryValue* command_args, 116 const base::DictionaryValue* command_args,
97 const base::FilePath& input_dir, 117 const base::FilePath& input_dir,
98 ComponentInstaller* installer) OVERRIDE; 118 ComponentInstaller* installer) OVERRIDE;
99 119
100 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, 120 virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE;
101 int* error) OVERRIDE;
102 121
103 base::FilePath patch_abs_path_; 122 base::FilePath patch_abs_path_;
104 123
105 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); 124 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate);
106 }; 125 };
107 126
108 // A 'bsdiff' operation takes an existing file on disk, and a bsdiff- 127 class DeltaUpdateOpPatchStrategy {
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: 128 public:
113 DeltaUpdateOpPatchBsdiff(); 129 virtual ~DeltaUpdateOpPatchStrategy();
130
131 // Returns an integer to add to error codes to disambiguate their source.
132 virtual int GetErrorOffset() const = 0;
133
134 // Returns the "error code" that is expected in the successful install case.
135 virtual int GetSuccessCode() const = 0;
136
137 // Returns an IPC message that will start patching if it is sent to a
138 // UtilityProcessClient.
139 virtual scoped_ptr<IPC::Message> GetPatchMessage(
140 base::FilePath input_abs_path,
141 base::FilePath patch_abs_path,
142 base::FilePath output_abs_path) = 0;
143
144 // Does the actual patching operation, and returns an error code.
145 virtual int Patch(base::FilePath input_abs_path,
146 base::FilePath patch_abs_path,
147 base::FilePath output_abs_path) = 0;
148 };
149
150 class DeltaUpdateOpPatch;
151
152 class DeltaUpdateOpPatchHost : public content::UtilityProcessHostClient {
153 public:
154 explicit DeltaUpdateOpPatchHost(scoped_refptr<DeltaUpdateOpPatch> patcher);
155
156 void StartProcess(scoped_ptr<IPC::Message> message);
114 157
115 private: 158 private:
159 virtual ~DeltaUpdateOpPatchHost();
160
161 void OnPatchSucceeded();
162
163 void OnPatchFailed(int error_code);
164
165 // Overrides of content::UtilityProcessHostClient.
166 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
167
168 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
169
170 scoped_refptr<DeltaUpdateOpPatch> patcher_;
171 };
172
173 // Both 'bsdiff' and 'courgette' operations take an existing file on disk,
174 // and a bsdiff- or Courgette-format patch file provided in the delta update
175 // package, and run bsdiff or Courgette to construct an output file in the
176 // unpacking directory.
177 class DeltaUpdateOpPatch : public DeltaUpdateOp {
178 public:
179 explicit DeltaUpdateOpPatch(scoped_ptr<DeltaUpdateOpPatchStrategy> strategy);
180
181 void DonePatching(ComponentUnpacker::Error error, int error_code);
182
183 private:
184 virtual ~DeltaUpdateOpPatch();
185
116 // Overrides of DeltaUpdateOp. 186 // Overrides of DeltaUpdateOp.
117 virtual ComponentUnpacker::Error DoParseArguments( 187 virtual ComponentUnpacker::Error DoParseArguments(
118 base::DictionaryValue* command_args, 188 const base::DictionaryValue* command_args,
119 const base::FilePath& input_dir, 189 const base::FilePath& input_dir,
120 ComponentInstaller* installer) OVERRIDE; 190 ComponentInstaller* installer) OVERRIDE;
121 191
122 virtual ComponentUnpacker::Error DoRun(ComponentPatcher* patcher, 192 virtual void DoRun(const ComponentUnpacker::Callback& callback) OVERRIDE;
123 int* error) OVERRIDE;
124 193
194 ComponentUnpacker::Callback callback_;
125 base::FilePath patch_abs_path_; 195 base::FilePath patch_abs_path_;
126 base::FilePath input_abs_path_; 196 base::FilePath input_abs_path_;
197 scoped_ptr<DeltaUpdateOpPatchStrategy> strategy_;
198 scoped_refptr<DeltaUpdateOpPatchHost> host_;
127 199
128 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatchBsdiff); 200 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch);
129 }; 201 };
130 202
131 // A 'courgette' operation takes an existing file on disk, and a Courgette- 203 // Factory functions to create DeltaUpdateOp instances.
132 // format patch file provided in the delta update package, and runs Courgette 204 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 205
138 private: 206 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 207
157 } // namespace component_updater 208 } // namespace component_updater
158 209
159 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_ 210 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_OPERATION_H_
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/component_patcher.cc ('k') | chrome/browser/component_updater/component_patcher_operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698