blob: e9c039c36899f03cd259dd9d5464d8f0443de853 [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"
avie4d7b6f2015-12-26 00:59:1810#include "base/macros.h"
michaeln96f887e22015-04-13 23:58:3111#include "base/memory/ref_counted.h"
gab27e6d33f2016-08-11 13:15:3312#include "base/task_runner.h"
michaeln96f887e22015-04-13 23:58:3113
michaeln68bf4a8e2015-08-11 01:37:3114namespace android {
15class AfterStartupTaskUtilsJNI;
16}
17
michaeln96f887e22015-04-13 23:58:3118class AfterStartupTaskUtils {
19 public:
gab27e6d33f2016-08-11 13:15:3320 // A helper TaskRunner which merely forwards to
21 // AfterStartupTaskUtils::PostTask(). Doesn't support tasks with a non-zero
22 // delay.
23 class Runner : public base::TaskRunner {
24 public:
25 explicit Runner(scoped_refptr<base::TaskRunner> destination_runner);
26
27 // Overrides from base::TaskRunner:
Brett Wilsone1a70422017-09-12 05:10:0928 bool PostDelayedTask(const base::Location& from_here,
tzik6e427842017-04-05 10:13:2129 base::OnceClosure task,
gab27e6d33f2016-08-11 13:15:3330 base::TimeDelta delay) override;
peary23322df62017-05-09 03:55:4831 bool RunsTasksInCurrentSequence() const override;
gab27e6d33f2016-08-11 13:15:3332
33 private:
34 ~Runner() override;
35
36 const scoped_refptr<base::TaskRunner> destination_runner_;
37
38 DISALLOW_COPY_AND_ASSIGN(Runner);
39 };
40
michaeln96f887e22015-04-13 23:58:3141 // Observes startup and when complete runs tasks that have accrued.
42 static void StartMonitoringStartup();
43
44 // Used to augment the behavior of BrowserThread::PostAfterStartupTask
45 // for chrome. Tasks are queued until startup is complete.
46 // Note: see browser_thread.h
gab27e6d33f2016-08-11 13:15:3347 static void PostTask(
Brett Wilsone1a70422017-09-12 05:10:0948 const base::Location& from_here,
gab27e6d33f2016-08-11 13:15:3349 const scoped_refptr<base::TaskRunner>& destination_runner,
tzik6e427842017-04-05 10:13:2150 base::OnceClosure task);
michaeln96f887e22015-04-13 23:58:3151
fserb3f669c52015-06-26 16:45:0952 // Returns true if browser startup is complete. Only use this on a one-off
53 // basis; If you need to poll this function constantly, use the above
54 // PostTask() API instead.
55 static bool IsBrowserStartupComplete();
56
wkorman8a21c4f2015-11-18 19:06:1157 // For use by unit tests where we don't have normal content loading
58 // infrastructure and thus StartMonitoringStartup() is unsuitable.
59 static void SetBrowserStartupIsCompleteForTesting();
60
61 static void UnsafeResetForTesting();
62
michaeln96f887e22015-04-13 23:58:3163 private:
wkorman8a21c4f2015-11-18 19:06:1164 // TODO(wkorman): Look into why Android calls
65 // SetBrowserStartupIsComplete() directly. Ideally it would use
66 // StartMonitoringStartup() as the normal approach.
michaeln68bf4a8e2015-08-11 01:37:3167 friend class android::AfterStartupTaskUtilsJNI;
michaeln96f887e22015-04-13 23:58:3168
michaeln96f887e22015-04-13 23:58:3169 static void SetBrowserStartupIsComplete();
michaeln96f887e22015-04-13 23:58:3170
71 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils);
72};
73
74#endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_