OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ | 5 #ifndef CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ |
6 #define CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ | 6 #define CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
13 | 13 |
14 namespace android { | 14 namespace android { |
15 class AfterStartupTaskUtilsJNI; | 15 class AfterStartupTaskUtilsJNI; |
16 } | 16 } |
17 | 17 |
18 class AfterStartupTaskUtils { | 18 class AfterStartupTaskUtils { |
19 public: | 19 public: |
20 // A helper TaskRunner which merely forwards to | 20 // A helper TaskRunner which merely forwards to |
21 // AfterStartupTaskUtils::PostTask(). Doesn't support tasks with a non-zero | 21 // AfterStartupTaskUtils::PostTask(). Doesn't support tasks with a non-zero |
22 // delay. | 22 // delay. |
23 class Runner : public base::TaskRunner { | 23 class Runner : public base::TaskRunner { |
24 public: | 24 public: |
25 explicit Runner(scoped_refptr<base::TaskRunner> destination_runner); | 25 explicit Runner(scoped_refptr<base::TaskRunner> destination_runner); |
26 | 26 |
27 // Overrides from base::TaskRunner: | 27 // Overrides from base::TaskRunner: |
28 bool PostDelayedTask(const tracked_objects::Location& from_here, | 28 bool PostDelayedTask(const tracked_objects::Location& from_here, |
29 base::Closure task, | 29 base::OnceClosure task, |
30 base::TimeDelta delay) override; | 30 base::TimeDelta delay) override; |
31 bool RunsTasksOnCurrentThread() const override; | 31 bool RunsTasksOnCurrentThread() const override; |
32 | 32 |
33 private: | 33 private: |
34 ~Runner() override; | 34 ~Runner() override; |
35 | 35 |
36 const scoped_refptr<base::TaskRunner> destination_runner_; | 36 const scoped_refptr<base::TaskRunner> destination_runner_; |
37 | 37 |
38 DISALLOW_COPY_AND_ASSIGN(Runner); | 38 DISALLOW_COPY_AND_ASSIGN(Runner); |
39 }; | 39 }; |
40 | 40 |
41 // Observes startup and when complete runs tasks that have accrued. | 41 // Observes startup and when complete runs tasks that have accrued. |
42 static void StartMonitoringStartup(); | 42 static void StartMonitoringStartup(); |
43 | 43 |
44 // Used to augment the behavior of BrowserThread::PostAfterStartupTask | 44 // Used to augment the behavior of BrowserThread::PostAfterStartupTask |
45 // for chrome. Tasks are queued until startup is complete. | 45 // for chrome. Tasks are queued until startup is complete. |
46 // Note: see browser_thread.h | 46 // Note: see browser_thread.h |
47 static void PostTask( | 47 static void PostTask( |
48 const tracked_objects::Location& from_here, | 48 const tracked_objects::Location& from_here, |
49 const scoped_refptr<base::TaskRunner>& destination_runner, | 49 const scoped_refptr<base::TaskRunner>& destination_runner, |
50 base::Closure task); | 50 base::OnceClosure task); |
51 | 51 |
52 // Returns true if browser startup is complete. Only use this on a one-off | 52 // 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 | 53 // basis; If you need to poll this function constantly, use the above |
54 // PostTask() API instead. | 54 // PostTask() API instead. |
55 static bool IsBrowserStartupComplete(); | 55 static bool IsBrowserStartupComplete(); |
56 | 56 |
57 // For use by unit tests where we don't have normal content loading | 57 // For use by unit tests where we don't have normal content loading |
58 // infrastructure and thus StartMonitoringStartup() is unsuitable. | 58 // infrastructure and thus StartMonitoringStartup() is unsuitable. |
59 static void SetBrowserStartupIsCompleteForTesting(); | 59 static void SetBrowserStartupIsCompleteForTesting(); |
60 | 60 |
61 static void UnsafeResetForTesting(); | 61 static void UnsafeResetForTesting(); |
62 | 62 |
63 private: | 63 private: |
64 // TODO(wkorman): Look into why Android calls | 64 // TODO(wkorman): Look into why Android calls |
65 // SetBrowserStartupIsComplete() directly. Ideally it would use | 65 // SetBrowserStartupIsComplete() directly. Ideally it would use |
66 // StartMonitoringStartup() as the normal approach. | 66 // StartMonitoringStartup() as the normal approach. |
67 friend class android::AfterStartupTaskUtilsJNI; | 67 friend class android::AfterStartupTaskUtilsJNI; |
68 | 68 |
69 static void SetBrowserStartupIsComplete(); | 69 static void SetBrowserStartupIsComplete(); |
70 | 70 |
71 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils); | 71 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils); |
72 }; | 72 }; |
73 | 73 |
74 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ | 74 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ |
OLD | NEW |