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/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/gtest_prod_util.h" | |
11 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
12 | 11 |
13 class ExtensionServiceTest; | |
14 | |
15 namespace android { | 12 namespace android { |
16 class AfterStartupTaskUtilsJNI; | 13 class AfterStartupTaskUtilsJNI; |
17 } | 14 } |
18 | 15 |
19 namespace base { | 16 namespace base { |
20 class TaskRunner; | 17 class TaskRunner; |
21 } | 18 } |
22 namespace tracked_objects { | 19 namespace tracked_objects { |
23 class Location; | 20 class Location; |
24 }; | 21 }; |
25 | 22 |
26 class AfterStartupTaskUtils { | 23 class AfterStartupTaskUtils { |
27 public: | 24 public: |
28 // Observes startup and when complete runs tasks that have accrued. | 25 // Observes startup and when complete runs tasks that have accrued. |
29 static void StartMonitoringStartup(); | 26 static void StartMonitoringStartup(); |
30 | 27 |
31 // Used to augment the behavior of BrowserThread::PostAfterStartupTask | 28 // Used to augment the behavior of BrowserThread::PostAfterStartupTask |
32 // for chrome. Tasks are queued until startup is complete. | 29 // for chrome. Tasks are queued until startup is complete. |
33 // Note: see browser_thread.h | 30 // Note: see browser_thread.h |
34 static void PostTask(const tracked_objects::Location& from_here, | 31 static void PostTask(const tracked_objects::Location& from_here, |
35 const scoped_refptr<base::TaskRunner>& task_runner, | 32 const scoped_refptr<base::TaskRunner>& task_runner, |
36 const base::Closure& task); | 33 const base::Closure& task); |
37 | 34 |
38 // Returns true if browser startup is complete. Only use this on a one-off | 35 // 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 | 36 // basis; If you need to poll this function constantly, use the above |
40 // PostTask() API instead. | 37 // PostTask() API instead. |
41 static bool IsBrowserStartupComplete(); | 38 static bool IsBrowserStartupComplete(); |
42 | 39 |
| 40 // For use by unit tests where we don't have normal content loading |
| 41 // infrastructure and thus StartMonitoringStartup() is unsuitable. |
| 42 static void SetBrowserStartupIsCompleteForTesting(); |
| 43 |
| 44 static void UnsafeResetForTesting(); |
| 45 |
43 private: | 46 private: |
44 friend class AfterStartupTaskTest; | 47 // TODO(wkorman): Look into why Android calls |
| 48 // SetBrowserStartupIsComplete() directly. Ideally it would use |
| 49 // StartMonitoringStartup() as the normal approach. |
45 friend class android::AfterStartupTaskUtilsJNI; | 50 friend class android::AfterStartupTaskUtilsJNI; |
46 friend class ::ExtensionServiceTest; | |
47 friend class InProcessBrowserTest; | |
48 FRIEND_TEST_ALL_PREFIXES(AfterStartupTaskTest, IsStartupComplete); | |
49 FRIEND_TEST_ALL_PREFIXES(AfterStartupTaskTest, PostTask); | |
50 | 51 |
51 static void SetBrowserStartupIsComplete(); | 52 static void SetBrowserStartupIsComplete(); |
52 static void UnsafeResetForTesting(); | |
53 | 53 |
54 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils); | 54 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils); |
55 }; | 55 }; |
56 | 56 |
57 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ | 57 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ |
OLD | NEW |