michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1 | // 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 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 8 | #include "base/bind.h" |
tzik | 070c8ffb | 2017-03-29 05:28:12 | [diff] [blame] | 9 | #include "base/callback.h" |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 10 | #include "base/location.h" |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
| 12 | |
michaeln | 68bf4a8e | 2015-08-11 01:37:31 | [diff] [blame] | 13 | namespace android { |
| 14 | class AfterStartupTaskUtilsJNI; |
| 15 | } |
| 16 | |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 17 | namespace base { |
| 18 | class SequencedTaskRunner; |
| 19 | } |
| 20 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 21 | class AfterStartupTaskUtils { |
| 22 | public: |
Peter Boström | fadb175 | 2021-09-30 19:17:01 | [diff] [blame] | 23 | AfterStartupTaskUtils() = delete; |
| 24 | AfterStartupTaskUtils(const AfterStartupTaskUtils&) = delete; |
| 25 | AfterStartupTaskUtils& operator=(const AfterStartupTaskUtils&) = delete; |
| 26 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 27 | // 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 |
gab | 27e6d33f | 2016-08-11 13:15:33 | [diff] [blame] | 33 | static void PostTask( |
Brett Wilson | e1a7042 | 2017-09-12 05:10:09 | [diff] [blame] | 34 | const base::Location& from_here, |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 35 | const scoped_refptr<base::SequencedTaskRunner>& destination_runner, |
tzik | 6e42784 | 2017-04-05 10:13:21 | [diff] [blame] | 36 | base::OnceClosure task); |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 37 | |
fserb | 3f669c5 | 2015-06-26 16:45:09 | [diff] [blame] | 38 | // 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 | |
wkorman | 8a21c4f | 2015-11-18 19:06:11 | [diff] [blame] | 43 | // 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 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 49 | private: |
wkorman | 8a21c4f | 2015-11-18 19:06:11 | [diff] [blame] | 50 | // TODO(wkorman): Look into why Android calls |
| 51 | // SetBrowserStartupIsComplete() directly. Ideally it would use |
| 52 | // StartMonitoringStartup() as the normal approach. |
michaeln | 68bf4a8e | 2015-08-11 01:37:31 | [diff] [blame] | 53 | friend class android::AfterStartupTaskUtilsJNI; |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 54 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 55 | static void SetBrowserStartupIsComplete(); |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ |