blob: b78840545b797a8ebfab7c84e96a5958d0d3721b [file] [log] [blame]
michaeln96f887e22015-04-13 23:58:311// Copyright 2015 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 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
30 // Used to augment the behavior of BrowserThread::PostAfterStartupTask
31 // for chrome. Tasks are queued until startup is complete.
32 // Note: see browser_thread.h
gab27e6d33f2016-08-11 13:15:3333 static void PostTask(
Brett Wilsone1a70422017-09-12 05:10:0934 const base::Location& from_here,
Gabriel Charettee926fc12019-12-16 19:00:0235 const scoped_refptr<base::SequencedTaskRunner>& destination_runner,
tzik6e427842017-04-05 10:13:2136 base::OnceClosure task);
michaeln96f887e22015-04-13 23:58:3137
fserb3f669c52015-06-26 16:45:0938 // Returns true if browser startup is complete. Only use this on a one-off
39 // basis; If you need to poll this function constantly, use the above
40 // PostTask() API instead.
41 static bool IsBrowserStartupComplete();
42
wkorman8a21c4f2015-11-18 19:06:1143 // For use by unit tests where we don't have normal content loading
44 // infrastructure and thus StartMonitoringStartup() is unsuitable.
45 static void SetBrowserStartupIsCompleteForTesting();
46
47 static void UnsafeResetForTesting();
48
michaeln96f887e22015-04-13 23:58:3149 private:
wkorman8a21c4f2015-11-18 19:06:1150 // TODO(wkorman): Look into why Android calls
51 // SetBrowserStartupIsComplete() directly. Ideally it would use
52 // StartMonitoringStartup() as the normal approach.
michaeln68bf4a8e2015-08-11 01:37:3153 friend class android::AfterStartupTaskUtilsJNI;
michaeln96f887e22015-04-13 23:58:3154
michaeln96f887e22015-04-13 23:58:3155 static void SetBrowserStartupIsComplete();
michaeln96f887e22015-04-13 23:58:3156};
57
58#endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_