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 #include "chrome/browser/after_startup_task_utils.h" | 5 #include "chrome/browser/after_startup_task_utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 const int kMinDelaySec = 0; | 68 const int kMinDelaySec = 0; |
69 const int kMaxDelaySec = 10; | 69 const int kMaxDelaySec = 10; |
70 scoped_refptr<base::TaskRunner> target_runner = queued_task->task_runner; | 70 scoped_refptr<base::TaskRunner> target_runner = queued_task->task_runner; |
71 tracked_objects::Location from_here = queued_task->from_here; | 71 tracked_objects::Location from_here = queued_task->from_here; |
72 target_runner->PostDelayedTask( | 72 target_runner->PostDelayedTask( |
73 from_here, base::Bind(&RunTask, base::Passed(std::move(queued_task))), | 73 from_here, base::Bind(&RunTask, base::Passed(std::move(queued_task))), |
74 base::TimeDelta::FromSeconds(base::RandInt(kMinDelaySec, kMaxDelaySec))); | 74 base::TimeDelta::FromSeconds(base::RandInt(kMinDelaySec, kMaxDelaySec))); |
75 } | 75 } |
76 | 76 |
77 void QueueTask(std::unique_ptr<AfterStartupTask> queued_task) { | 77 void QueueTask(std::unique_ptr<AfterStartupTask> queued_task) { |
| 78 DCHECK(queued_task); |
| 79 DCHECK(queued_task->task); |
78 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 80 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
79 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
80 BrowserThread::UI, FROM_HERE, | 82 BrowserThread::UI, FROM_HERE, |
81 base::Bind(QueueTask, base::Passed(std::move(queued_task)))); | 83 base::Bind(QueueTask, base::Passed(std::move(queued_task)))); |
82 return; | 84 return; |
83 } | 85 } |
84 | 86 |
85 // The flag may have been set while the task to invoke this method | 87 // The flag may have been set while the task to invoke this method |
86 // on the UI thread was inflight. | 88 // on the UI thread was inflight. |
87 if (IsBrowserStartupComplete()) { | 89 if (IsBrowserStartupComplete()) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 return ::IsBrowserStartupComplete(); | 247 return ::IsBrowserStartupComplete(); |
246 } | 248 } |
247 | 249 |
248 void AfterStartupTaskUtils::UnsafeResetForTesting() { | 250 void AfterStartupTaskUtils::UnsafeResetForTesting() { |
249 DCHECK(g_after_startup_tasks.Get().empty()); | 251 DCHECK(g_after_startup_tasks.Get().empty()); |
250 if (!IsBrowserStartupComplete()) | 252 if (!IsBrowserStartupComplete()) |
251 return; | 253 return; |
252 g_startup_complete_flag.Get().UnsafeResetForTesting(); | 254 g_startup_complete_flag.Get().UnsafeResetForTesting(); |
253 DCHECK(!IsBrowserStartupComplete()); | 255 DCHECK(!IsBrowserStartupComplete()); |
254 } | 256 } |
OLD | NEW |