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

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

Issue 1931503002: Add BackgroundModeOptimizer that can restart the browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PushKeepAlive
Patch Set: fix BrowserListTest.AttemptRestart Created 4 years, 5 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/browser_shutdown.h" 5 #include "chrome/browser/browser_shutdown.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 29 matching lines...) Expand all
40 40
41 #if defined(OS_WIN) 41 #if defined(OS_WIN)
42 #include "chrome/browser/first_run/upgrade_util_win.h" 42 #include "chrome/browser/first_run/upgrade_util_win.h"
43 #include "chrome/browser/win/browser_util.h" 43 #include "chrome/browser/win/browser_util.h"
44 #endif 44 #endif
45 45
46 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 46 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
47 #include "chrome/browser/first_run/upgrade_util.h" 47 #include "chrome/browser/first_run/upgrade_util.h"
48 #endif 48 #endif
49 49
50 #if BUILDFLAG(ENABLE_BACKGROUND)
51 #include "chrome/browser/background/background_mode_manager.h"
52 #endif
53
50 #if defined(ENABLE_RLZ) 54 #if defined(ENABLE_RLZ)
51 #include "components/rlz/rlz_tracker.h" 55 #include "components/rlz/rlz_tracker.h"
52 #endif 56 #endif
53 57
54 #if defined(OS_CHROMEOS) 58 #if defined(OS_CHROMEOS)
55 #include "chrome/browser/chromeos/boot_times_recorder.h" 59 #include "chrome/browser/chromeos/boot_times_recorder.h"
56 #endif 60 #endif
57 61
58 #if defined(ENABLE_PRINT_PREVIEW) 62 #if defined(ENABLE_PRINT_PREVIEW)
59 #include "chrome/browser/service_process/service_process_control.h" 63 #include "chrome/browser/service_process/service_process_control.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 191
188 #if defined(ENABLE_RLZ) 192 #if defined(ENABLE_RLZ)
189 // Cleanup any statics created by RLZ. Must be done before NotificationService 193 // Cleanup any statics created by RLZ. Must be done before NotificationService
190 // is destroyed. 194 // is destroyed.
191 rlz::RLZTracker::CleanupRlz(); 195 rlz::RLZTracker::CleanupRlz();
192 #endif 196 #endif
193 197
194 return restart_last_session; 198 return restart_last_session;
195 } 199 }
196 200
197 void ShutdownPostThreadsStop(bool restart_last_session) { 201 void ShutdownPostThreadsStop(int shutdown_flags) {
198 delete g_browser_process; 202 delete g_browser_process;
199 g_browser_process = NULL; 203 g_browser_process = NULL;
200 204
201 // crbug.com/95079 - This needs to happen after the browser process object 205 // crbug.com/95079 - This needs to happen after the browser process object
202 // goes away. 206 // goes away.
203 ProfileManager::NukeDeletedProfilesFromDisk(); 207 ProfileManager::NukeDeletedProfilesFromDisk();
204 208
205 #if defined(OS_CHROMEOS) 209 #if defined(OS_CHROMEOS)
206 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker("BrowserDeleted", 210 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker("BrowserDeleted",
207 true); 211 true);
208 #endif 212 #endif
209 213
210 #if defined(OS_WIN) 214 #if defined(OS_WIN)
211 if (!browser_util::IsBrowserAlreadyRunning() && 215 if (!browser_util::IsBrowserAlreadyRunning() &&
212 g_shutdown_type != END_SESSION) { 216 g_shutdown_type != END_SESSION) {
213 upgrade_util::SwapNewChromeExeIfPresent(); 217 upgrade_util::SwapNewChromeExeIfPresent();
214 } 218 }
215 #endif 219 #endif
216 220
217 if (restart_last_session) { 221 if (shutdown_flags & RESTART_LAST_SESSION) {
218 #if !defined(OS_CHROMEOS) 222 #if !defined(OS_CHROMEOS)
219 // Make sure to relaunch the browser with the original command line plus 223 // Make sure to relaunch the browser with the original command line plus
220 // the Restore Last Session flag. Note that Chrome can be launched (ie. 224 // the Restore Last Session flag. Note that Chrome can be launched (ie.
221 // through ShellExecute on Windows) with a switch argument terminator at 225 // through ShellExecute on Windows) with a switch argument terminator at
222 // the end (double dash, as described in b/1366444) plus a URL, 226 // the end (double dash, as described in b/1366444) plus a URL,
223 // which prevents us from appending to the command line directly (issue 227 // which prevents us from appending to the command line directly (issue
224 // 46182). We therefore use GetSwitches to copy the command line (it stops 228 // 46182). We therefore use GetSwitches to copy the command line (it stops
225 // at the switch argument terminator). 229 // at the switch argument terminator).
226 base::CommandLine old_cl(*base::CommandLine::ForCurrentProcess()); 230 base::CommandLine old_cl(*base::CommandLine::ForCurrentProcess());
227 std::unique_ptr<base::CommandLine> new_cl( 231 std::unique_ptr<base::CommandLine> new_cl(
228 new base::CommandLine(old_cl.GetProgram())); 232 new base::CommandLine(old_cl.GetProgram()));
229 std::map<std::string, base::CommandLine::StringType> switches = 233 std::map<std::string, base::CommandLine::StringType> switches =
230 old_cl.GetSwitches(); 234 old_cl.GetSwitches();
231 // Remove the switches that shouldn't persist across restart. 235 // Remove the switches that shouldn't persist across restart.
232 about_flags::RemoveFlagsSwitches(&switches); 236 about_flags::RemoveFlagsSwitches(&switches);
233 switches::RemoveSwitchesForAutostart(&switches); 237 switches::RemoveSwitchesForAutostart(&switches);
234 // Append the old switches to the new command line. 238 // Append the old switches to the new command line.
235 for (const auto& it : switches) { 239 for (const auto& it : switches) {
236 const base::CommandLine::StringType& switch_value = it.second; 240 const base::CommandLine::StringType& switch_value = it.second;
237 if (!switch_value.empty()) 241 if (!switch_value.empty())
238 new_cl->AppendSwitchNative(it.first, it.second); 242 new_cl->AppendSwitchNative(it.first, it.second);
239 else 243 else
240 new_cl->AppendSwitch(it.first); 244 new_cl->AppendSwitch(it.first);
241 } 245 }
246 if (shutdown_flags & RESTART_IN_BACKGROUND)
247 new_cl->AppendSwitch(switches::kNoStartupWindow);
242 248
243 #if defined(OS_POSIX) || defined(OS_WIN) 249 #if defined(OS_POSIX) || defined(OS_WIN)
244 upgrade_util::RelaunchChromeBrowser(*new_cl.get()); 250 upgrade_util::RelaunchChromeBrowser(*new_cl.get());
245 #endif // defined(OS_WIN) 251 #endif // defined(OS_WIN)
246 252
247 #else 253 #else
248 NOTIMPLEMENTED(); 254 NOTIMPLEMENTED();
249 #endif // !defined(OS_CHROMEOS) 255 #endif // !defined(OS_CHROMEOS)
250 } 256 }
251 257
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 prefs->SetInteger(prefs::kShutdownNumProcessesSlow, 0); 328 prefs->SetInteger(prefs::kShutdownNumProcessesSlow, 0);
323 329
324 // Read and delete the file on the file thread. 330 // Read and delete the file on the file thread.
325 BrowserThread::PostTask( 331 BrowserThread::PostTask(
326 BrowserThread::FILE, FROM_HERE, 332 BrowserThread::FILE, FROM_HERE,
327 base::Bind(&ReadLastShutdownFile, type, num_procs, num_procs_slow)); 333 base::Bind(&ReadLastShutdownFile, type, num_procs, num_procs_slow));
328 } 334 }
329 335
330 void SetTryingToQuit(bool quitting) { 336 void SetTryingToQuit(bool quitting) {
331 g_trying_to_quit = quitting; 337 g_trying_to_quit = quitting;
338
339 if (quitting)
340 return;
341
342 // Reset the restart-related preferences.
sky 2016/07/22 16:57:52 This just documents what the code is doing. Instea
dgn 2016/07/25 17:32:28 Done.
343 PrefService* pref_service = g_browser_process->local_state();
344 if (pref_service) {
345 #if !defined(OS_ANDROID)
346 pref_service->ClearPref(prefs::kWasRestarted);
347 #endif // !defined(OS_ANDROID)
348 pref_service->ClearPref(prefs::kRestartLastSessionOnShutdown);
349 }
350
351 #if BUILDFLAG(ENABLE_BACKGROUND)
352 BackgroundModeManager::should_restart_in_background(false);
353 #endif // BUILDFLAG(ENABLE_BACKGROUND)
332 } 354 }
333 355
334 bool IsTryingToQuit() { 356 bool IsTryingToQuit() {
335 return g_trying_to_quit; 357 return g_trying_to_quit;
336 } 358 }
337 359
338 void StartShutdownTracing() { 360 void StartShutdownTracing() {
339 const base::CommandLine& command_line = 361 const base::CommandLine& command_line =
340 *base::CommandLine::ForCurrentProcess(); 362 *base::CommandLine::ForCurrentProcess();
341 if (command_line.HasSwitch(switches::kTraceShutdown)) { 363 if (command_line.HasSwitch(switches::kTraceShutdown)) {
342 base::trace_event::TraceConfig trace_config( 364 base::trace_event::TraceConfig trace_config(
343 command_line.GetSwitchValueASCII(switches::kTraceShutdown), ""); 365 command_line.GetSwitchValueASCII(switches::kTraceShutdown), "");
344 content::TracingController::GetInstance()->StartTracing( 366 content::TracingController::GetInstance()->StartTracing(
345 trace_config, 367 trace_config,
346 content::TracingController::StartTracingDoneCallback()); 368 content::TracingController::StartTracingDoneCallback());
347 } 369 }
348 TRACE_EVENT0("shutdown", "StartShutdownTracing"); 370 TRACE_EVENT0("shutdown", "StartShutdownTracing");
349 } 371 }
350 372
351 } // namespace browser_shutdown 373 } // namespace browser_shutdown
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698