OLD | NEW |
---|---|
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 Loading... | |
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(keep_alive::Origin::BACKGROUND_MODE_MANAGER)); | 314 new ScopedKeepAlive(keep_alive::Origin::BACKGROUND_MODE_MANAGER_STARTUP, |
Bernhard Bauer
2016/02/24 16:54:33
Are we ever going to use the same origin with diff
dgn
2016/02/24 19:08:32
Up to callers to decide what to do with their orig
| |
315 keep_alive::RestartOption::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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 UpdateKeepAliveAndTrayIcon(); | 759 UpdateKeepAliveAndTrayIcon(); |
759 } | 760 } |
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_) |
Bernhard Bauer
2016/02/24 16:54:33
Keep the braces, as the body is more than one line
| |
769 keep_alive_.reset( | 770 keep_alive_.reset( |
770 new ScopedKeepAlive(keep_alive::Origin::BACKGROUND_MODE_MANAGER)); | 771 new ScopedKeepAlive(keep_alive::Origin::BACKGROUND_MODE_MANAGER, |
771 } | 772 keep_alive::RestartOption::ENABLED)); |
772 CreateStatusTrayIcon(); | 773 CreateStatusTrayIcon(); |
773 return; | 774 return; |
774 } | 775 } |
775 | 776 |
776 RemoveStatusTrayIcon(); | 777 RemoveStatusTrayIcon(); |
777 keep_alive_.reset(); | 778 keep_alive_.reset(); |
778 } | 779 } |
779 | 780 |
780 void BackgroundModeManager::OnBrowserAdded(Browser* browser) { | 781 void BackgroundModeManager::OnBrowserAdded(Browser* browser) { |
781 ResumeBackgroundMode(); | 782 ResumeBackgroundMode(); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1027 } | 1028 } |
1028 } | 1029 } |
1029 return profile_it; | 1030 return profile_it; |
1030 } | 1031 } |
1031 | 1032 |
1032 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 1033 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
1033 PrefService* service = g_browser_process->local_state(); | 1034 PrefService* service = g_browser_process->local_state(); |
1034 DCHECK(service); | 1035 DCHECK(service); |
1035 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 1036 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
1036 } | 1037 } |
OLD | NEW |