[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / after_startup_task_utils.h
1 // Copyright 2015 The Chromium Authors
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 CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_
6 #define CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_
7
8 #include "base/functional/bind.h"
9 #include "base/functional/callback.h"
10 #include "base/location.h"
11 #include "base/memory/ref_counted.h"
12
13 namespace android {
14 class AfterStartupTaskUtilsJNI;
15 }
16
17 namespace base {
18 class SequencedTaskRunner;
19 }
20
21 class AfterStartupTaskUtils {
22  public:
23   AfterStartupTaskUtils() = delete;
24   AfterStartupTaskUtils(const AfterStartupTaskUtils&) = delete;
25   AfterStartupTaskUtils& operator=(const AfterStartupTaskUtils&) = delete;
26
27   // Observes startup and when complete runs tasks that have accrued.
28   static void StartMonitoringStartup();
29
30   // Queues `task` to run on `destination_runner` after startup is complete.
31   // Note: prefer to simply post a task with BEST_EFFORT priority. This will
32   // delay the task until higher priority tasks are finished, which includes
33   // critical startup tasks. The BrowserThread::PostBestEffortTask() helper can
34   // post a BEST_EFFORT task to an arbitrary task runner.
35   static void PostTask(
36       const base::Location& from_here,
37       const scoped_refptr<base::SequencedTaskRunner>& destination_runner,
38       base::OnceClosure task);
39
40   // Returns true if browser startup is complete. Only use this on a one-off
41   // basis; If you need to poll this function constantly, use the above
42   // PostTask() API instead.
43   static bool IsBrowserStartupComplete();
44
45   // For use by unit tests where we don't have normal content loading
46   // infrastructure and thus StartMonitoringStartup() is unsuitable.
47   static void SetBrowserStartupIsCompleteForTesting();
48
49   static void UnsafeResetForTesting();
50
51  private:
52   // TODO(wkorman): Look into why Android calls
53   // SetBrowserStartupIsComplete() directly. Ideally it would use
54   // StartMonitoringStartup() as the normal approach.
55   friend class android::AfterStartupTaskUtilsJNI;
56
57   static void SetBrowserStartupIsComplete();
58 };
59
60 #endif  // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_