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.
5 #ifndef CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_
6 #define CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_
8 #include "base/functional/bind.h"
9 #include "base/functional/callback.h"
10 #include "base/location.h"
11 #include "base/memory/ref_counted.h"
14 class AfterStartupTaskUtilsJNI;
18 class SequencedTaskRunner;
21 class AfterStartupTaskUtils {
23 AfterStartupTaskUtils() = delete;
24 AfterStartupTaskUtils(const AfterStartupTaskUtils&) = delete;
25 AfterStartupTaskUtils& operator=(const AfterStartupTaskUtils&) = delete;
27 // Observes startup and when complete runs tasks that have accrued.
28 static void StartMonitoringStartup();
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.
36 const base::Location& from_here,
37 const scoped_refptr<base::SequencedTaskRunner>& destination_runner,
38 base::OnceClosure task);
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();
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();
49 static void UnsafeResetForTesting();
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;
57 static void SetBrowserStartupIsComplete();
60 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_