blob: 4da640c6d4f35f13acf71def2f88e4de0b4278d6 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2015 The Chromium Authors
michaeln96f887e22015-04-13 23:58:312// 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
michaeln96f887e22015-04-13 23:58:318#include "base/bind.h"
tzik070c8ffb2017-03-29 05:28:129#include "base/callback.h"
Gabriel Charettee926fc12019-12-16 19:00:0210#include "base/location.h"
michaeln96f887e22015-04-13 23:58:3111#include "base/memory/ref_counted.h"
12
michaeln68bf4a8e2015-08-11 01:37:3113namespace android {
14class AfterStartupTaskUtilsJNI;
15}
16
Gabriel Charettee926fc12019-12-16 19:00:0217namespace base {
18class SequencedTaskRunner;
19}
20
michaeln96f887e22015-04-13 23:58:3121class AfterStartupTaskUtils {
22 public:
Peter Boströmfadb1752021-09-30 19:17:0123 AfterStartupTaskUtils() = delete;
24 AfterStartupTaskUtils(const AfterStartupTaskUtils&) = delete;
25 AfterStartupTaskUtils& operator=(const AfterStartupTaskUtils&) = delete;
26
michaeln96f887e22015-04-13 23:58:3127 // Observes startup and when complete runs tasks that have accrued.
28 static void StartMonitoringStartup();
29
Joe Masoncaa690542022-07-12 11:02:1630 // 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.
gab27e6d33f2016-08-11 13:15:3335 static void PostTask(
Brett Wilsone1a70422017-09-12 05:10:0936 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:0237 const scoped_refptr<base::SequencedTaskRunner>& destination_runner,
tzik6e427842017-04-05 10:13:2138 base::OnceClosure task);
michaeln96f887e22015-04-13 23:58:3139
fserb3f669c52015-06-26 16:45:0940 // 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
wkorman8a21c4f2015-11-18 19:06:1145 // 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
michaeln96f887e22015-04-13 23:58:3151 private:
wkorman8a21c4f2015-11-18 19:06:1152 // TODO(wkorman): Look into why Android calls
53 // SetBrowserStartupIsComplete() directly. Ideally it would use
54 // StartMonitoringStartup() as the normal approach.
michaeln68bf4a8e2015-08-11 01:37:3155 friend class android::AfterStartupTaskUtilsJNI;
michaeln96f887e22015-04-13 23:58:3156
michaeln96f887e22015-04-13 23:58:3157 static void SetBrowserStartupIsComplete();
michaeln96f887e22015-04-13 23:58:3158};
59
60#endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_