Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: chrome/browser/after_startup_task_utils.cc

Issue 1551503002: Convert Pass()→std::move() in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility>
8
7 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
11 #include "base/process/process_info.h" 13 #include "base/process/process_info.h"
12 #include "base/rand_util.h" 14 #include "base/rand_util.h"
13 #include "base/synchronization/cancellation_flag.h" 15 #include "base/synchronization/cancellation_flag.h"
14 #include "base/task_runner.h" 16 #include "base/task_runner.h"
15 #include "base/tracked_objects.h" 17 #include "base/tracked_objects.h"
16 #include "build/build_config.h" 18 #include "build/build_config.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 queued_task->task.Run(); 63 queued_task->task.Run();
62 } 64 }
63 65
64 void ScheduleTask(scoped_ptr<AfterStartupTask> queued_task) { 66 void ScheduleTask(scoped_ptr<AfterStartupTask> queued_task) {
65 // Spread their execution over a brief time. 67 // Spread their execution over a brief time.
66 const int kMinDelaySec = 0; 68 const int kMinDelaySec = 0;
67 const int kMaxDelaySec = 10; 69 const int kMaxDelaySec = 10;
68 scoped_refptr<base::TaskRunner> target_runner = queued_task->task_runner; 70 scoped_refptr<base::TaskRunner> target_runner = queued_task->task_runner;
69 tracked_objects::Location from_here = queued_task->from_here; 71 tracked_objects::Location from_here = queued_task->from_here;
70 target_runner->PostDelayedTask( 72 target_runner->PostDelayedTask(
71 from_here, base::Bind(&RunTask, base::Passed(queued_task.Pass())), 73 from_here, base::Bind(&RunTask, base::Passed(std::move(queued_task))),
72 base::TimeDelta::FromSeconds(base::RandInt(kMinDelaySec, kMaxDelaySec))); 74 base::TimeDelta::FromSeconds(base::RandInt(kMinDelaySec, kMaxDelaySec)));
73 } 75 }
74 76
75 void QueueTask(scoped_ptr<AfterStartupTask> queued_task) { 77 void QueueTask(scoped_ptr<AfterStartupTask> queued_task) {
76 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 78 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
77 BrowserThread::PostTask( 79 BrowserThread::PostTask(
78 BrowserThread::UI, FROM_HERE, 80 BrowserThread::UI, FROM_HERE,
79 base::Bind(QueueTask, base::Passed(queued_task.Pass()))); 81 base::Bind(QueueTask, base::Passed(std::move(queued_task))));
80 return; 82 return;
81 } 83 }
82 84
83 // The flag may have been set while the task to invoke this method 85 // The flag may have been set while the task to invoke this method
84 // on the UI thread was inflight. 86 // on the UI thread was inflight.
85 if (IsBrowserStartupComplete()) { 87 if (IsBrowserStartupComplete()) {
86 ScheduleTask(queued_task.Pass()); 88 ScheduleTask(std::move(queued_task));
87 return; 89 return;
88 } 90 }
89 g_after_startup_tasks.Get().push_back(queued_task.release()); 91 g_after_startup_tasks.Get().push_back(queued_task.release());
90 } 92 }
91 93
92 void SetBrowserStartupIsComplete() { 94 void SetBrowserStartupIsComplete() {
93 DCHECK_CURRENTLY_ON(BrowserThread::UI); 95 DCHECK_CURRENTLY_ON(BrowserThread::UI);
94 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) 96 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
95 // CurrentProcessInfo::CreationTime() is not available on all platforms. 97 // CurrentProcessInfo::CreationTime() is not available on all platforms.
96 const base::Time process_creation_time = 98 const base::Time process_creation_time =
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 const tracked_objects::Location& from_here, 201 const tracked_objects::Location& from_here,
200 const scoped_refptr<base::TaskRunner>& task_runner, 202 const scoped_refptr<base::TaskRunner>& task_runner,
201 const base::Closure& task) { 203 const base::Closure& task) {
202 if (IsBrowserStartupComplete()) { 204 if (IsBrowserStartupComplete()) {
203 task_runner->PostTask(from_here, task); 205 task_runner->PostTask(from_here, task);
204 return; 206 return;
205 } 207 }
206 208
207 scoped_ptr<AfterStartupTask> queued_task( 209 scoped_ptr<AfterStartupTask> queued_task(
208 new AfterStartupTask(from_here, task_runner, task)); 210 new AfterStartupTask(from_here, task_runner, task));
209 QueueTask(queued_task.Pass()); 211 QueueTask(std::move(queued_task));
210 } 212 }
211 213
212 void AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting() { 214 void AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting() {
213 ::SetBrowserStartupIsComplete(); 215 ::SetBrowserStartupIsComplete();
214 } 216 }
215 217
216 void AfterStartupTaskUtils::SetBrowserStartupIsComplete() { 218 void AfterStartupTaskUtils::SetBrowserStartupIsComplete() {
217 ::SetBrowserStartupIsComplete(); 219 ::SetBrowserStartupIsComplete();
218 } 220 }
219 221
220 bool AfterStartupTaskUtils::IsBrowserStartupComplete() { 222 bool AfterStartupTaskUtils::IsBrowserStartupComplete() {
221 return ::IsBrowserStartupComplete(); 223 return ::IsBrowserStartupComplete();
222 } 224 }
223 225
224 void AfterStartupTaskUtils::UnsafeResetForTesting() { 226 void AfterStartupTaskUtils::UnsafeResetForTesting() {
225 DCHECK(g_after_startup_tasks.Get().empty()); 227 DCHECK(g_after_startup_tasks.Get().empty());
226 if (!IsBrowserStartupComplete()) 228 if (!IsBrowserStartupComplete())
227 return; 229 return;
228 g_startup_complete_flag.Get().UnsafeResetForTesting(); 230 g_startup_complete_flag.Get().UnsafeResetForTesting();
229 DCHECK(!IsBrowserStartupComplete()); 231 DCHECK(!IsBrowserStartupComplete());
230 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698