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

Side by Side Diff: chrome/browser/background/background_mode_manager.cc

Issue 1725883002: Add KeepAliveStateObserver, add the Restart option (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@KeepAlive
Patch Set: Address comments Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/lifetime/keep_alive_registry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/background/background_mode_manager.h" 5 #include "chrome/browser/background/background_mode_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 base::Bind(&BackgroundModeManager::OnBackgroundModeEnabledPrefChanged, 304 base::Bind(&BackgroundModeManager::OnBackgroundModeEnabledPrefChanged,
305 base::Unretained(this))); 305 base::Unretained(this)));
306 } 306 }
307 307
308 // Keep the browser alive until extensions are done loading - this is needed 308 // Keep the browser alive until extensions are done loading - this is needed
309 // by the --no-startup-window flag. We want to stay alive until we load 309 // by the --no-startup-window flag. We want to stay alive until we load
310 // extensions, at which point we should either run in background mode (if 310 // extensions, at which point we should either run in background mode (if
311 // there are background apps) or exit if there are none. 311 // there are background apps) or exit if there are none.
312 if (command_line.HasSwitch(switches::kNoStartupWindow)) { 312 if (command_line.HasSwitch(switches::kNoStartupWindow)) {
313 keep_alive_for_startup_.reset( 313 keep_alive_for_startup_.reset(
314 new ScopedKeepAlive(KeepAliveOrigin::BACKGROUND_MODE_MANAGER)); 314 new ScopedKeepAlive(KeepAliveOrigin::BACKGROUND_MODE_MANAGER_STARTUP,
315 KeepAliveRestartOption::DISABLED));
315 } else { 316 } else {
316 // Otherwise, start with background mode suspended in case we're launching 317 // Otherwise, start with background mode suspended in case we're launching
317 // in a mode that doesn't open a browser window. It will be resumed when the 318 // in a mode that doesn't open a browser window. It will be resumed when the
318 // first browser window is opened. 319 // first browser window is opened.
319 SuspendBackgroundMode(); 320 SuspendBackgroundMode();
320 } 321 }
321 322
322 // If the -keep-alive-for-test flag is passed, then always keep chrome running 323 // If the -keep-alive-for-test flag is passed, then always keep chrome running
323 // in the background until the user explicitly terminates it. 324 // in the background until the user explicitly terminates it.
324 if (command_line.HasSwitch(switches::kKeepAliveForTest)) 325 if (command_line.HasSwitch(switches::kKeepAliveForTest))
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 761
761 void BackgroundModeManager::ResumeBackgroundMode() { 762 void BackgroundModeManager::ResumeBackgroundMode() {
762 background_mode_suspended_ = false; 763 background_mode_suspended_ = false;
763 UpdateKeepAliveAndTrayIcon(); 764 UpdateKeepAliveAndTrayIcon();
764 } 765 }
765 766
766 void BackgroundModeManager::UpdateKeepAliveAndTrayIcon() { 767 void BackgroundModeManager::UpdateKeepAliveAndTrayIcon() {
767 if (in_background_mode_ && !background_mode_suspended_) { 768 if (in_background_mode_ && !background_mode_suspended_) {
768 if (!keep_alive_) { 769 if (!keep_alive_) {
769 keep_alive_.reset( 770 keep_alive_.reset(
770 new ScopedKeepAlive(KeepAliveOrigin::BACKGROUND_MODE_MANAGER)); 771 new ScopedKeepAlive(KeepAliveOrigin::BACKGROUND_MODE_MANAGER,
772 KeepAliveRestartOption::ENABLED));
771 } 773 }
772 CreateStatusTrayIcon(); 774 CreateStatusTrayIcon();
773 return; 775 return;
774 } 776 }
775 777
776 RemoveStatusTrayIcon(); 778 RemoveStatusTrayIcon();
777 keep_alive_.reset(); 779 keep_alive_.reset();
778 } 780 }
779 781
780 void BackgroundModeManager::OnBrowserAdded(Browser* browser) { 782 void BackgroundModeManager::OnBrowserAdded(Browser* browser) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 1029 }
1028 } 1030 }
1029 return profile_it; 1031 return profile_it;
1030 } 1032 }
1031 1033
1032 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { 1034 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const {
1033 PrefService* service = g_browser_process->local_state(); 1035 PrefService* service = g_browser_process->local_state();
1034 DCHECK(service); 1036 DCHECK(service);
1035 return service->GetBoolean(prefs::kBackgroundModeEnabled); 1037 return service->GetBoolean(prefs::kBackgroundModeEnabled);
1036 } 1038 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/lifetime/keep_alive_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698