OLD | NEW |
(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 #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 |
| 15 namespace 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(). |
| 20 class 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. |
| 35 virtual void OnCheckComplete(Errors errors); |
| 36 |
| 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 |
| 53 base::WeakPtrFactory<PreloadCheckGroup> weak_ptr_factory_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(PreloadCheckGroup); |
| 56 }; |
| 57 |
| 58 } // namespace extensions |
| 59 |
| 60 #endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_GROUP_H_ |
OLD | NEW |