blob: fef680b3359f0e0b7127bf86d833bd5994c0b29b [file] [log] [blame]
michaelpg6a4874f2017-04-13 20:41:331// 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#ifndef EXTENSIONS_BROWSER_PRELOAD_CHECK_GROUP_H_
6#define EXTENSIONS_BROWSER_PRELOAD_CHECK_GROUP_H_
7
8#include <vector>
9
michaelpg6a4874f2017-04-13 20:41:3310#include "base/memory/weak_ptr.h"
11#include "base/threading/thread_checker.h"
12#include "extensions/browser/preload_check.h"
13
14namespace extensions {
15
16// PreloadCheckGroup runs a collection of other PreloadChecks and reports their
17// collective status once they have all finished. To stop the remaining checks
18// upon hitting the first error, use set_stop_on_first_error().
19class PreloadCheckGroup : public PreloadCheck {
20 public:
21 PreloadCheckGroup();
Peter Boström951cf77e2021-09-22 00:02:5922
23 PreloadCheckGroup(const PreloadCheckGroup&) = delete;
24 PreloadCheckGroup& operator=(const PreloadCheckGroup&) = delete;
25
michaelpg6a4874f2017-04-13 20:41:3326 ~PreloadCheckGroup() override;
27
28 // Adds a check to run. Not owned. Must be called before Start().
29 void AddCheck(PreloadCheck* check);
30
31 // PreloadCheck:
32 void Start(ResultCallback callback) override;
33
34 void set_stop_on_first_error(bool value) { stop_on_first_error_ = value; }
35
36 private:
37 // Saves any errors and may invoke the callback.
Istiaque Ahmed400c83a2017-10-11 02:39:3538 virtual void OnCheckComplete(const Errors& errors);
michaelpg6a4874f2017-04-13 20:41:3339
40 // Invokes the callback if the checks are considered finished.
41 void MaybeInvokeCallback();
42
43 base::ThreadChecker thread_checker_;
44
45 // If true, the callback is invoked early when the first check fails,
46 // stopping the remaining checks.
47 bool stop_on_first_error_ = false;
48
49 // Checks to run. Not owned.
50 std::vector<PreloadCheck*> checks_;
51
52 ResultCallback callback_;
53 int running_checks_ = 0;
54 Errors errors_;
55
Jeremy Roman9fc2de62019-07-12 14:15:0356 base::WeakPtrFactory<PreloadCheckGroup> weak_ptr_factory_{this};
michaelpg6a4874f2017-04-13 20:41:3357};
58
59} // namespace extensions
60
61#endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_GROUP_H_