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