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

Side by Side Diff: components/update_client/action_update.cc

Issue 2483513002: Revert of Makes the component installers return a Result instead of a bool. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « components/update_client/action_update.h ('k') | components/update_client/test_installer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "components/update_client/action_update.h" 5 #include "components/update_client/action_update.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 17 matching lines...) Expand all
28 namespace update_client { 28 namespace update_client {
29 29
30 namespace { 30 namespace {
31 31
32 void AppendDownloadMetrics( 32 void AppendDownloadMetrics(
33 const std::vector<CrxDownloader::DownloadMetrics>& source, 33 const std::vector<CrxDownloader::DownloadMetrics>& source,
34 std::vector<CrxDownloader::DownloadMetrics>* destination) { 34 std::vector<CrxDownloader::DownloadMetrics>* destination) {
35 destination->insert(destination->end(), source.begin(), source.end()); 35 destination->insert(destination->end(), source.begin(), source.end());
36 } 36 }
37 37
38 ErrorCategory UnpackerErrorToErrorCategory(UnpackerError error) {
39 ErrorCategory error_category = ErrorCategory::kErrorNone;
40 switch (error) {
41 case UnpackerError::kNone:
42 break;
43 case UnpackerError::kInstallerError:
44 error_category = ErrorCategory::kInstallError;
45 break;
46 default:
47 error_category = ErrorCategory::kUnpackError;
48 break;
49 }
50 return error_category;
51 }
52
38 } // namespace 53 } // namespace
39 54
40 ActionUpdate::ActionUpdate() { 55 ActionUpdate::ActionUpdate() {
41 } 56 }
42 57
43 ActionUpdate::~ActionUpdate() { 58 ActionUpdate::~ActionUpdate() {
44 DCHECK(thread_checker_.CalledOnValidThread()); 59 DCHECK(thread_checker_.CalledOnValidThread());
45 } 60 }
46 61
47 void ActionUpdate::Run(UpdateContext* update_context, Callback callback) { 62 void ActionUpdate::Run(UpdateContext* update_context, Callback callback) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 162
148 if (result.error == UnpackerError::kNone) { 163 if (result.error == UnpackerError::kNone) {
149 update_context_->blocking_task_runner->PostTask( 164 update_context_->blocking_task_runner->PostTask(
150 FROM_HERE, 165 FROM_HERE,
151 base::Bind(&ActionUpdate::StartInstallOnBlockingTaskRunner, 166 base::Bind(&ActionUpdate::StartInstallOnBlockingTaskRunner,
152 base::Unretained(this), item, crx_path, result.unpack_path)); 167 base::Unretained(this), item, crx_path, result.unpack_path));
153 } else { 168 } else {
154 update_context_->blocking_task_runner->PostTask( 169 update_context_->blocking_task_runner->PostTask(
155 FROM_HERE, 170 FROM_HERE,
156 base::Bind(&ActionUpdate::InstallCompleteOnBlockingTaskRunner, 171 base::Bind(&ActionUpdate::InstallCompleteOnBlockingTaskRunner,
157 base::Unretained(this), item, crx_path, 172 base::Unretained(this), item, crx_path, result.error,
158 ErrorCategory::kUnpackError, static_cast<int>(result.error),
159 result.extended_error)); 173 result.extended_error));
160 } 174 }
161 } 175 }
162 176
163 void ActionUpdate::StartInstallOnBlockingTaskRunner( 177 void ActionUpdate::StartInstallOnBlockingTaskRunner(
164 CrxUpdateItem* item, 178 CrxUpdateItem* item,
165 const base::FilePath& crx_path, 179 const base::FilePath& crx_path,
166 const base::FilePath& unpack_path) { 180 const base::FilePath& unpack_path) {
167 DCHECK(update_context_->blocking_task_runner->RunsTasksOnCurrentThread()); 181 DCHECK(update_context_->blocking_task_runner->RunsTasksOnCurrentThread());
168 DCHECK(!unpack_path.empty()); 182 DCHECK(!unpack_path.empty());
169 183
170 const auto result = DoInstall(item, crx_path, unpack_path); 184 const auto error = DoInstall(item, crx_path, unpack_path);
171 const ErrorCategory error_category =
172 result.error ? ErrorCategory::kInstallError : ErrorCategory::kErrorNone;
173 update_context_->blocking_task_runner->PostTask( 185 update_context_->blocking_task_runner->PostTask(
174 FROM_HERE, 186 FROM_HERE, base::Bind(&ActionUpdate::InstallCompleteOnBlockingTaskRunner,
175 base::Bind(&ActionUpdate::InstallCompleteOnBlockingTaskRunner, 187 base::Unretained(this), item, crx_path, error, 0));
176 base::Unretained(this), item, crx_path, error_category,
177 result.error, result.extended_error));
178 } 188 }
179 189
180 void ActionUpdate::InstallCompleteOnBlockingTaskRunner( 190 void ActionUpdate::InstallCompleteOnBlockingTaskRunner(
181 CrxUpdateItem* item, 191 CrxUpdateItem* item,
182 const base::FilePath& crx_path, 192 const base::FilePath& crx_path,
183 ErrorCategory error_category, 193 UnpackerError error,
184 int error,
185 int extended_error) { 194 int extended_error) {
186 update_client::DeleteFileAndEmptyParentDirectory(crx_path); 195 update_client::DeleteFileAndEmptyParentDirectory(crx_path);
187 update_context_->main_task_runner->PostDelayedTask( 196 update_context_->main_task_runner->PostDelayedTask(
188 FROM_HERE, 197 FROM_HERE,
189 base::Bind(&ActionUpdate::InstallComplete, base::Unretained(this), 198 base::Bind(&ActionUpdate::InstallComplete, base::Unretained(this),
190 item->id, error_category, error, extended_error), 199 item->id, error, extended_error),
191 base::TimeDelta::FromMilliseconds(update_context_->config->StepDelay())); 200 base::TimeDelta::FromMilliseconds(update_context_->config->StepDelay()));
192 } 201 }
193 202
194 CrxInstaller::Result ActionUpdate::DoInstall( 203 UnpackerError ActionUpdate::DoInstall(CrxUpdateItem* item,
195 CrxUpdateItem* item, 204 const base::FilePath& crx_path,
196 const base::FilePath& crx_path, 205 const base::FilePath& unpack_path) {
197 const base::FilePath& unpack_path) {
198 const auto& fingerprint = item->next_fp; 206 const auto& fingerprint = item->next_fp;
199 if (static_cast<int>(fingerprint.size()) != 207 if (static_cast<int>(fingerprint.size()) !=
200 base::WriteFile( 208 base::WriteFile(
201 unpack_path.Append(FILE_PATH_LITERAL("manifest.fingerprint")), 209 unpack_path.Append(FILE_PATH_LITERAL("manifest.fingerprint")),
202 fingerprint.c_str(), base::checked_cast<int>(fingerprint.size()))) { 210 fingerprint.c_str(), base::checked_cast<int>(fingerprint.size()))) {
203 return CrxInstaller::Result(InstallError::FINGERPRINT_WRITE_FAILED); 211 return UnpackerError::kFingerprintWriteFailed;
204 } 212 }
205 213
206 std::unique_ptr<base::DictionaryValue> manifest = ReadManifest(unpack_path); 214 std::unique_ptr<base::DictionaryValue> manifest = ReadManifest(unpack_path);
207 if (!manifest.get()) 215 if (!manifest.get())
208 return CrxInstaller::Result(InstallError::BAD_MANIFEST); 216 return UnpackerError::kBadManifest;
209 217
210 return item->component.installer->Install(*manifest, unpack_path); 218 return item->component.installer->Install(*manifest, unpack_path)
219 ? UnpackerError::kNone
220 : UnpackerError::kInstallerError;
211 } 221 }
212 222
213 void ActionUpdate::InstallComplete(const std::string& id, 223 void ActionUpdate::InstallComplete(const std::string& id,
214 ErrorCategory error_category, 224 UnpackerError error,
215 int error,
216 int extended_error) { 225 int extended_error) {
217 DCHECK(thread_checker_.CalledOnValidThread()); 226 DCHECK(thread_checker_.CalledOnValidThread());
218 DCHECK(id == update_context_->queue.front()); 227 DCHECK(id == update_context_->queue.front());
219 228
220 CrxUpdateItem* item = FindUpdateItemById(id); 229 CrxUpdateItem* item = FindUpdateItemById(id);
221 DCHECK(item); 230 DCHECK(item);
222 231
223 if (error == 0) { 232 if (error == UnpackerError::kNone)
224 DCHECK_EQ(ErrorCategory::kErrorNone, error_category);
225 DCHECK_EQ(0, extended_error);
226 OnInstallSuccess(item); 233 OnInstallSuccess(item);
227 } else { 234 else
228 OnInstallError(item, error_category, error, extended_error); 235 OnInstallError(item, error, extended_error);
229 }
230 } 236 }
231 237
232 ActionUpdateDiff::ActionUpdateDiff() { 238 ActionUpdateDiff::ActionUpdateDiff() {
233 } 239 }
234 240
235 ActionUpdateDiff::~ActionUpdateDiff() { 241 ActionUpdateDiff::~ActionUpdateDiff() {
236 DCHECK(thread_checker_.CalledOnValidThread()); 242 DCHECK(thread_checker_.CalledOnValidThread());
237 } 243 }
238 244
239 std::unique_ptr<Action> ActionUpdateDiff::Create() { 245 std::unique_ptr<Action> ActionUpdateDiff::Create() {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 DCHECK(item->state == CrxUpdateItem::State::kUpdatingDiff); 314 DCHECK(item->state == CrxUpdateItem::State::kUpdatingDiff);
309 315
310 item->component.version = item->next_version; 316 item->component.version = item->next_version;
311 item->component.fingerprint = item->next_fp; 317 item->component.fingerprint = item->next_fp;
312 ChangeItemState(item, CrxUpdateItem::State::kUpdated); 318 ChangeItemState(item, CrxUpdateItem::State::kUpdated);
313 319
314 UpdateCrxComplete(item); 320 UpdateCrxComplete(item);
315 } 321 }
316 322
317 void ActionUpdateDiff::OnInstallError(CrxUpdateItem* item, 323 void ActionUpdateDiff::OnInstallError(CrxUpdateItem* item,
318 ErrorCategory error_category, 324 UnpackerError error,
319 int error,
320 int extended_error) { 325 int extended_error) {
321 DCHECK(thread_checker_.CalledOnValidThread()); 326 DCHECK(thread_checker_.CalledOnValidThread());
322 327
323 item->diff_error_category = static_cast<int>(error_category); 328 item->diff_error_category =
324 item->diff_error_code = error; 329 static_cast<int>(UnpackerErrorToErrorCategory(error));
330 item->diff_error_code = static_cast<int>(error);
325 item->diff_extra_code1 = extended_error; 331 item->diff_extra_code1 = extended_error;
326 item->diff_update_failed = true; 332 item->diff_update_failed = true;
327 333
328 base::ThreadTaskRunnerHandle::Get()->PostTask( 334 base::ThreadTaskRunnerHandle::Get()->PostTask(
329 FROM_HERE, 335 FROM_HERE,
330 base::Bind(&ActionUpdateDiff::TryUpdateFull, base::Unretained(this))); 336 base::Bind(&ActionUpdateDiff::TryUpdateFull, base::Unretained(this)));
331 } 337 }
332 338
333 ActionUpdateFull::ActionUpdateFull() { 339 ActionUpdateFull::ActionUpdateFull() {
334 } 340 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 DCHECK(item->state == CrxUpdateItem::State::kUpdating); 407 DCHECK(item->state == CrxUpdateItem::State::kUpdating);
402 408
403 item->component.version = item->next_version; 409 item->component.version = item->next_version;
404 item->component.fingerprint = item->next_fp; 410 item->component.fingerprint = item->next_fp;
405 ChangeItemState(item, CrxUpdateItem::State::kUpdated); 411 ChangeItemState(item, CrxUpdateItem::State::kUpdated);
406 412
407 UpdateCrxComplete(item); 413 UpdateCrxComplete(item);
408 } 414 }
409 415
410 void ActionUpdateFull::OnInstallError(CrxUpdateItem* item, 416 void ActionUpdateFull::OnInstallError(CrxUpdateItem* item,
411 ErrorCategory error_category, 417 UnpackerError error,
412 int error,
413 int extended_error) { 418 int extended_error) {
414 DCHECK(thread_checker_.CalledOnValidThread()); 419 DCHECK(thread_checker_.CalledOnValidThread());
415 DCHECK(item->state == CrxUpdateItem::State::kUpdating); 420 DCHECK(item->state == CrxUpdateItem::State::kUpdating);
416 421
417 item->error_category = static_cast<int>(error_category); 422 item->error_category = static_cast<int>(UnpackerErrorToErrorCategory(error));
418 item->error_code = error; 423 item->error_code = static_cast<int>(error);
419 item->extra_code1 = extended_error; 424 item->extra_code1 = extended_error;
420 ChangeItemState(item, CrxUpdateItem::State::kNoUpdate); 425 ChangeItemState(item, CrxUpdateItem::State::kNoUpdate);
421 426
422 UpdateCrxComplete(item); 427 UpdateCrxComplete(item);
423 } 428 }
424 429
425 } // namespace update_client 430 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/action_update.h ('k') | components/update_client/test_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698