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

Side by Side Diff: extensions/browser/preload_check_group.cc

Issue 2783143005: Replace ExtensionInstallChecker with generic PreloadCheckGroup (Closed)
Patch Set: fix debug build Created 3 years, 8 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "extensions/browser/preload_check_group.h"
6
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/memory/ref_counted.h"
10 #include "extensions/common/extension.h"
11
12 namespace extensions {
13
14 PreloadCheckGroup::PreloadCheckGroup()
15 : PreloadCheck(nullptr), weak_ptr_factory_(this) {}
16
17 PreloadCheckGroup::~PreloadCheckGroup() {}
18
19 void PreloadCheckGroup::AddCheck(PreloadCheck* check) {
20 DCHECK_EQ(0, running_checks_);
21 checks_.push_back(check);
22 }
23
24 void PreloadCheckGroup::Start(ResultCallback callback) {
25 DCHECK(thread_checker_.CalledOnValidThread());
26 DCHECK_EQ(0, running_checks_);
27
28 callback_ = std::move(callback);
29 running_checks_ = checks_.size();
30 for (auto* check : checks_) {
31 check->Start(base::Bind(&PreloadCheckGroup::OnCheckComplete,
32 weak_ptr_factory_.GetWeakPtr()));
33 // Synchronous checks may fail immediately.
34 if (running_checks_ == 0)
35 return;
36 }
37 }
38
39 void PreloadCheckGroup::OnCheckComplete(Errors errors) {
40 DCHECK(thread_checker_.CalledOnValidThread());
41 errors_.insert(errors.begin(), errors.end());
42 running_checks_--;
43 MaybeInvokeCallback();
44 }
45
46 void PreloadCheckGroup::MaybeInvokeCallback() {
47 // Only invoke callback if all checks are complete, or if there was at least
48 // one failure and |stop_on_first_error_| is true.
49 if (running_checks_ > 0 && (errors_.empty() || !stop_on_first_error_))
50 return;
51
52 // If we are failing fast, discard any pending results.
53 weak_ptr_factory_.InvalidateWeakPtrs();
54 running_checks_ = 0;
55
56 DCHECK(!callback_.is_null());
57 base::ResetAndReturn(&callback_).Run(errors_);
58 }
59
60 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/preload_check_group.h ('k') | extensions/browser/preload_check_group_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698