| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 bool IsBrowserStartupComplete() { | 52 bool IsBrowserStartupComplete() { |
| 53 // Be sure to initialize the LazyInstance on the main thread since the flag | 53 // Be sure to initialize the LazyInstance on the main thread since the flag |
| 54 // may only be set on it's initializing thread. | 54 // may only be set on it's initializing thread. |
| 55 if (g_startup_complete_flag == nullptr) | 55 if (g_startup_complete_flag == nullptr) |
| 56 return false; | 56 return false; |
| 57 return g_startup_complete_flag.Get().IsSet(); | 57 return g_startup_complete_flag.Get().IsSet(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void RunTask(std::unique_ptr<AfterStartupTask> queued_task) { | 60 void RunTask(std::unique_ptr<AfterStartupTask> queued_task) { |
| 61 // We're careful to delete the caller's |task| on the target runner's thread. | 61 // We're careful to delete the caller's |task| on the target runner's thread. |
| 62 DCHECK(queued_task->task_runner->RunsTasksOnCurrentThread()); | 62 DCHECK(queued_task->task_runner->RunsTasksInCurrentSequence()); |
| 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( |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 return ::IsBrowserStartupComplete(); | 252 return ::IsBrowserStartupComplete(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void AfterStartupTaskUtils::UnsafeResetForTesting() { | 255 void AfterStartupTaskUtils::UnsafeResetForTesting() { |
| 256 DCHECK(g_after_startup_tasks.Get().empty()); | 256 DCHECK(g_after_startup_tasks.Get().empty()); |
| 257 if (!IsBrowserStartupComplete()) | 257 if (!IsBrowserStartupComplete()) |
| 258 return; | 258 return; |
| 259 g_startup_complete_flag.Get().UnsafeResetForTesting(); | 259 g_startup_complete_flag.Get().UnsafeResetForTesting(); |
| 260 DCHECK(!IsBrowserStartupComplete()); | 260 DCHECK(!IsBrowserStartupComplete()); |
| 261 } | 261 } |
| OLD | NEW |