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

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

Issue 2238603002: Introduce AfterStartupTaskUtils::Runner for callsites that want to use AfterStartupTaskUtils but ne… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b9_sequenced_worker_pool_redirection
Patch Set: merge up to r411308 Created 4 years, 4 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 <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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 #endif // !defined(OS_ANDROID) 185 #endif // !defined(OS_ANDROID)
186 186
187 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, 187 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
188 base::Bind(&StartupObserver::OnFailsafeTimeout, 188 base::Bind(&StartupObserver::OnFailsafeTimeout,
189 weak_factory_.GetWeakPtr()), 189 weak_factory_.GetWeakPtr()),
190 delay); 190 delay);
191 } 191 }
192 192
193 } // namespace 193 } // namespace
194 194
195 AfterStartupTaskUtils::Runner::Runner(
196 scoped_refptr<base::TaskRunner> destination_runner)
197 : destination_runner_(std::move(destination_runner)) {
198 DCHECK(destination_runner_);
199 }
200
201 AfterStartupTaskUtils::Runner::~Runner() = default;
202
203 bool AfterStartupTaskUtils::Runner::PostDelayedTask(
204 const tracked_objects::Location& from_here,
205 const base::Closure& task,
206 base::TimeDelta delay) {
207 DCHECK(delay.is_zero());
208 AfterStartupTaskUtils::PostTask(from_here, destination_runner_, task);
209 return true;
210 }
211
212 bool AfterStartupTaskUtils::Runner::RunsTasksOnCurrentThread() const {
213 return destination_runner_->RunsTasksOnCurrentThread();
214 }
215
195 void AfterStartupTaskUtils::StartMonitoringStartup() { 216 void AfterStartupTaskUtils::StartMonitoringStartup() {
196 // The observer is self-deleting. 217 // The observer is self-deleting.
197 (new StartupObserver)->Start(); 218 (new StartupObserver)->Start();
198 } 219 }
199 220
200 void AfterStartupTaskUtils::PostTask( 221 void AfterStartupTaskUtils::PostTask(
201 const tracked_objects::Location& from_here, 222 const tracked_objects::Location& from_here,
202 const scoped_refptr<base::TaskRunner>& task_runner, 223 const scoped_refptr<base::TaskRunner>& destination_runner,
203 const base::Closure& task) { 224 const base::Closure& task) {
204 if (IsBrowserStartupComplete()) { 225 if (IsBrowserStartupComplete()) {
205 task_runner->PostTask(from_here, task); 226 destination_runner->PostTask(from_here, task);
206 return; 227 return;
207 } 228 }
208 229
209 std::unique_ptr<AfterStartupTask> queued_task( 230 std::unique_ptr<AfterStartupTask> queued_task(
210 new AfterStartupTask(from_here, task_runner, task)); 231 new AfterStartupTask(from_here, destination_runner, task));
211 QueueTask(std::move(queued_task)); 232 QueueTask(std::move(queued_task));
212 } 233 }
213 234
214 void AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting() { 235 void AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting() {
215 ::SetBrowserStartupIsComplete(); 236 ::SetBrowserStartupIsComplete();
216 } 237 }
217 238
218 void AfterStartupTaskUtils::SetBrowserStartupIsComplete() { 239 void AfterStartupTaskUtils::SetBrowserStartupIsComplete() {
219 ::SetBrowserStartupIsComplete(); 240 ::SetBrowserStartupIsComplete();
220 } 241 }
221 242
222 bool AfterStartupTaskUtils::IsBrowserStartupComplete() { 243 bool AfterStartupTaskUtils::IsBrowserStartupComplete() {
223 return ::IsBrowserStartupComplete(); 244 return ::IsBrowserStartupComplete();
224 } 245 }
225 246
226 void AfterStartupTaskUtils::UnsafeResetForTesting() { 247 void AfterStartupTaskUtils::UnsafeResetForTesting() {
227 DCHECK(g_after_startup_tasks.Get().empty()); 248 DCHECK(g_after_startup_tasks.Get().empty());
228 if (!IsBrowserStartupComplete()) 249 if (!IsBrowserStartupComplete())
229 return; 250 return;
230 g_startup_complete_flag.Get().UnsafeResetForTesting(); 251 g_startup_complete_flag.Get().UnsafeResetForTesting();
231 DCHECK(!IsBrowserStartupComplete()); 252 DCHECK(!IsBrowserStartupComplete());
232 } 253 }
OLDNEW
« no previous file with comments | « chrome/browser/after_startup_task_utils.h ('k') | chrome/browser/after_startup_task_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698