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

Side by Side Diff: chrome/browser/lifetime/application_lifetime.cc

Issue 1086733002: Ensure tests have an active task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add loop to DataReductionProxyConfiguratorTest. Created 5 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/lifetime/application_lifetime.h" 5 #include "chrome/browser/lifetime/application_lifetime.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // Check TabsNeedBeforeUnloadFired(). 75 // Check TabsNeedBeforeUnloadFired().
76 for (; !browser_it.done(); browser_it.Next()) { 76 for (; !browser_it.done(); browser_it.Next()) {
77 if (browser_it->TabsNeedBeforeUnloadFired()) 77 if (browser_it->TabsNeedBeforeUnloadFired())
78 return false; 78 return false;
79 } 79 }
80 return true; 80 return true;
81 } 81 }
82 #endif // !defined(OS_ANDROID) 82 #endif // !defined(OS_ANDROID)
83 83
84 int g_keep_alive_count = 0; 84 int g_keep_alive_count = 0;
85 bool g_disable_shutdown_for_testing = false;
85 86
86 #if defined(OS_CHROMEOS) 87 #if defined(OS_CHROMEOS)
87 // Whether chrome should send stop request to a session manager. 88 // Whether chrome should send stop request to a session manager.
88 bool g_send_stop_request_to_session_manager = false; 89 bool g_send_stop_request_to_session_manager = false;
89 #endif 90 #endif
90 91
91 } // namespace 92 } // namespace
92 93
93 void MarkAsCleanShutdown() { 94 void MarkAsCleanShutdown() {
94 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead? 95 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead?
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 326
326 DCHECK(g_browser_process); 327 DCHECK(g_browser_process);
327 // Although we should have a browser process, if there is none, 328 // Although we should have a browser process, if there is none,
328 // there is nothing to do. 329 // there is nothing to do.
329 if (!g_browser_process) return; 330 if (!g_browser_process) return;
330 331
331 // Allow the app to shutdown again. 332 // Allow the app to shutdown again.
332 if (!WillKeepAlive()) { 333 if (!WillKeepAlive()) {
333 g_browser_process->ReleaseModule(); 334 g_browser_process->ReleaseModule();
334 // If there are no browsers open and we aren't already shutting down, 335 // If there are no browsers open and we aren't already shutting down,
335 // initiate a shutdown. Also skips shutdown if this is a unit test 336 // initiate a shutdown. Also skips shutdown if this is a unit test.
336 // (MessageLoop::current() == null). 337 // (MessageLoop::current() == null or explicitly disabled).
337 if (chrome::GetTotalBrowserCount() == 0 && 338 if (chrome::GetTotalBrowserCount() == 0 &&
338 !browser_shutdown::IsTryingToQuit() && 339 !browser_shutdown::IsTryingToQuit() && base::MessageLoop::current() &&
339 base::MessageLoop::current()) { 340 !g_disable_shutdown_for_testing) {
340 CloseAllBrowsers(); 341 CloseAllBrowsers();
341 } 342 }
342 } 343 }
343 } 344 }
344 345
345 bool WillKeepAlive() { 346 bool WillKeepAlive() {
346 return g_keep_alive_count > 0; 347 return g_keep_alive_count > 0;
347 } 348 }
348 349
349 void NotifyAppTerminating() { 350 void NotifyAppTerminating() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // 2. If the desktop type of the browser going away is desktop and the ASH 416 // 2. If the desktop type of the browser going away is desktop and the ASH
416 // environment is still active. 417 // environment is still active.
417 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) 418 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE)
418 return !ash::Shell::HasInstance(); 419 return !ash::Shell::HasInstance();
419 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) 420 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH)
420 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); 421 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty();
421 #endif 422 #endif
422 return true; 423 return true;
423 } 424 }
424 425
426 void DisableShutdownForTesting(bool disable_shutdown_for_testing) {
427 g_disable_shutdown_for_testing = disable_shutdown_for_testing;
Andrew T Wilson (Slow) 2015/04/27 09:48:26 Should setting this to false also initiate a shutd
Sami 2015/04/27 11:31:40 That's a good thought, but unfortunately in Backgr
428 }
429
425 } // namespace chrome 430 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/lifetime/application_lifetime.h ('k') | chrome/browser/metrics/thread_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698