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

Unified Diff: chrome/browser/background/background_mode_manager.cc

Issue 1376063005: Cleanup: Pull some browser keep alive functions into its own file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more fixes Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/background/background_mode_manager.cc
diff --git a/chrome/browser/background/background_mode_manager.cc b/chrome/browser/background/background_mode_manager.cc
index 5bd2c6c5fa8186d2801aa1bd30ec1263283e66fd..117da57f8ae2147e02706c2163d56e44d18b2bb0 100644
--- a/chrome/browser/background/background_mode_manager.cc
+++ b/chrome/browser/background/background_mode_manager.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/lifetime/application_lifetime.h"
+#include "chrome/browser/lifetime/browser_keep_alive.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
@@ -121,6 +122,14 @@ void RecordMenuItemClick(MenuItem item) {
UMA_HISTOGRAM_ENUMERATION("BackgroundMode.MenuItemClick", item,
MENU_ITEM_NUM_STATES);
}
+
+// Helper function for DecrementKeepAliveCountForStartup() to actually decrement
+// the keep alive.
+void DoDecrementKeepAliveCountForStartup(
+ scoped_ptr<browser_lifetime::ScopedKeepAlive> keep_alive) {
+ keep_alive.reset(); // Explicitly reset().
sky 2015/10/07 17:27:24 You don't actually need this.
+}
+
} // namespace
BackgroundModeManager::BackgroundModeData::BackgroundModeData(
@@ -310,10 +319,8 @@ BackgroundModeManager::BackgroundModeManager(
status_icon_(NULL),
context_menu_(NULL),
in_background_mode_(false),
- keep_alive_for_startup_(false),
keep_alive_for_test_(false),
background_mode_suspended_(false),
- keeping_alive_(false),
weak_factory_(this) {
// We should never start up if there is no browser process or if we are
// currently quitting.
@@ -342,8 +349,7 @@ BackgroundModeManager::BackgroundModeManager(
// extensions, at which point we should either run in background mode (if
// there are background apps) or exit if there are none.
if (command_line.HasSwitch(switches::kNoStartupWindow)) {
- keep_alive_for_startup_ = true;
- chrome::IncrementKeepAliveCount();
+ keep_alive_for_startup_.reset(new browser_lifetime::ScopedKeepAlive);
} else {
// Otherwise, start with background mode suspended in case we're launching
// in a mode that doesn't open a browser window. It will be resumed when the
@@ -680,7 +686,7 @@ void BackgroundModeManager::ExecuteCommand(int command_id, int event_flags) {
// Background mode must already be enabled (as otherwise this menu would
// not be visible).
DCHECK(IsBackgroundModePrefEnabled());
- DCHECK(chrome::WillKeepAlive());
+ DCHECK(browser_lifetime::WillKeepAlive());
RecordMenuItemClick(MENU_ITEM_KEEP_RUNNING);
@@ -708,12 +714,13 @@ void BackgroundModeManager::ExecuteCommand(int command_id, int event_flags) {
// BackgroundModeManager, private
void BackgroundModeManager::DecrementKeepAliveCountForStartup() {
if (keep_alive_for_startup_) {
- keep_alive_for_startup_ = false;
// We call this via the message queue to make sure we don't try to end
// keep-alive (which can shutdown Chrome) before the message loop has
// started.
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(&chrome::DecrementKeepAliveCount));
+ FROM_HERE,
+ base::Bind(&DoDecrementKeepAliveCountForStartup,
+ base::Passed(&keep_alive_for_startup_)));
}
}
@@ -792,9 +799,9 @@ void BackgroundModeManager::ResumeBackgroundMode() {
void BackgroundModeManager::UpdateKeepAliveAndTrayIcon() {
if (in_background_mode_ && !background_mode_suspended_) {
- if (!keeping_alive_) {
- keeping_alive_ = true;
- chrome::IncrementKeepAliveCount();
+ if (!keep_alive_for_background_mode_) {
+ keep_alive_for_background_mode_.reset(
+ new browser_lifetime::ScopedKeepAlive);
#if defined(OS_WIN)
browser_watcher::ExitFunnel::RecordSingleEvent(
@@ -806,9 +813,8 @@ void BackgroundModeManager::UpdateKeepAliveAndTrayIcon() {
}
RemoveStatusTrayIcon();
- if (keeping_alive_) {
- keeping_alive_ = false;
- chrome::DecrementKeepAliveCount();
+ if (keep_alive_for_background_mode_) {
+ keep_alive_for_background_mode_.reset();
#if defined(OS_WIN)
browser_watcher::ExitFunnel::RecordSingleEvent(
@@ -867,7 +873,7 @@ int BackgroundModeManager::GetBackgroundClientCount() const {
// clients.
for (const auto& it : background_mode_data_)
count += it.second->GetBackgroundClientCount();
- DCHECK(count >= 0);
+ DCHECK_GE(count, 0);
return count;
}

Powered by Google App Engine
This is Rietveld 408576698