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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 std::move(queued_task->task).Run(); | 63 std::move(queued_task->task).Run(); |
64 } | 64 } |
65 | 65 |
66 void ScheduleTask(std::unique_ptr<AfterStartupTask> queued_task) { | 66 void ScheduleTask(std::unique_ptr<AfterStartupTask> queued_task) { |
67 // Spread their execution over a brief time. | 67 // Spread their execution over a brief time. |
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::BindOnce(&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); | 78 DCHECK(queued_task); |
79 | 79 |
80 // Use CHECK instead of DCHECK to crash earlier. See http://crbug.com/711167 | 80 // Use CHECK instead of DCHECK to crash earlier. See http://crbug.com/711167 |
81 // for details. | 81 // for details. |
82 CHECK(queued_task->task); | 82 CHECK(queued_task->task); |
83 | 83 |
84 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 84 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
85 BrowserThread::PostTask( | 85 BrowserThread::PostTask( |
86 BrowserThread::UI, FROM_HERE, | 86 BrowserThread::UI, FROM_HERE, |
87 base::Bind(QueueTask, base::Passed(std::move(queued_task)))); | 87 base::BindOnce(QueueTask, base::Passed(std::move(queued_task)))); |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 // The flag may have been set while the task to invoke this method | 91 // The flag may have been set while the task to invoke this method |
92 // on the UI thread was inflight. | 92 // on the UI thread was inflight. |
93 if (IsBrowserStartupComplete()) { | 93 if (IsBrowserStartupComplete()) { |
94 ScheduleTask(std::move(queued_task)); | 94 ScheduleTask(std::move(queued_task)); |
95 return; | 95 return; |
96 } | 96 } |
97 g_after_startup_tasks.Get().push_back(queued_task.release()); | 97 g_after_startup_tasks.Get().push_back(queued_task.release()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 Observe(contents); | 183 Observe(contents); |
184 delay = base::TimeDelta::FromMinutes(kLongerDelayMins); | 184 delay = base::TimeDelta::FromMinutes(kLongerDelayMins); |
185 } | 185 } |
186 #else | 186 #else |
187 // Startup completion is signaled via AfterStartupTaskUtils.java, | 187 // Startup completion is signaled via AfterStartupTaskUtils.java, |
188 // this is just a failsafe timeout. | 188 // this is just a failsafe timeout. |
189 const int kLongerDelayMins = 3; | 189 const int kLongerDelayMins = 3; |
190 delay = base::TimeDelta::FromMinutes(kLongerDelayMins); | 190 delay = base::TimeDelta::FromMinutes(kLongerDelayMins); |
191 #endif // !defined(OS_ANDROID) | 191 #endif // !defined(OS_ANDROID) |
192 | 192 |
193 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 193 BrowserThread::PostDelayedTask( |
194 base::Bind(&StartupObserver::OnFailsafeTimeout, | 194 BrowserThread::UI, FROM_HERE, |
195 weak_factory_.GetWeakPtr()), | 195 base::BindOnce(&StartupObserver::OnFailsafeTimeout, |
196 delay); | 196 weak_factory_.GetWeakPtr()), |
| 197 delay); |
197 } | 198 } |
198 | 199 |
199 } // namespace | 200 } // namespace |
200 | 201 |
201 AfterStartupTaskUtils::Runner::Runner( | 202 AfterStartupTaskUtils::Runner::Runner( |
202 scoped_refptr<base::TaskRunner> destination_runner) | 203 scoped_refptr<base::TaskRunner> destination_runner) |
203 : destination_runner_(std::move(destination_runner)) { | 204 : destination_runner_(std::move(destination_runner)) { |
204 DCHECK(destination_runner_); | 205 DCHECK(destination_runner_); |
205 } | 206 } |
206 | 207 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 return ::IsBrowserStartupComplete(); | 252 return ::IsBrowserStartupComplete(); |
252 } | 253 } |
253 | 254 |
254 void AfterStartupTaskUtils::UnsafeResetForTesting() { | 255 void AfterStartupTaskUtils::UnsafeResetForTesting() { |
255 DCHECK(g_after_startup_tasks.Get().empty()); | 256 DCHECK(g_after_startup_tasks.Get().empty()); |
256 if (!IsBrowserStartupComplete()) | 257 if (!IsBrowserStartupComplete()) |
257 return; | 258 return; |
258 g_startup_complete_flag.Get().UnsafeResetForTesting(); | 259 g_startup_complete_flag.Get().UnsafeResetForTesting(); |
259 DCHECK(!IsBrowserStartupComplete()); | 260 DCHECK(!IsBrowserStartupComplete()); |
260 } | 261 } |
OLD | NEW |