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

Unified Diff: chrome/browser/background/background_mode_manager_mac.mm

Issue 10823221: Do not create login items if the user deleted a previous one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « chrome/browser/background/background_mode_manager.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/background/background_mode_manager_mac.mm
diff --git a/chrome/browser/background/background_mode_manager_mac.mm b/chrome/browser/background/background_mode_manager_mac.mm
index 03c3366972a1b0165b2701bf8f3cc5283cce4b98..8d23618e9d189a58c4997d8719332997780b6f35 100644
--- a/chrome/browser/background/background_mode_manager_mac.mm
+++ b/chrome/browser/background/background_mode_manager_mac.mm
@@ -18,13 +18,30 @@ using content::BrowserThread;
namespace {
+void SetUserRemovedLoginItemPrefCallback() {
+ PrefService* service = g_browser_process->local_state();
+ service->SetBoolean(prefs::kUserRemovedLoginItem, true);
+}
+
void DisableLaunchOnStartupCallback() {
// Check if Chrome is not a login Item, or is a Login Item but w/o 'hidden'
// flag - most likely user has modified the setting, don't override it.
bool is_hidden = false;
- if (!base::mac::CheckLoginItemStatus(&is_hidden) || !is_hidden)
+ if (!base::mac::CheckLoginItemStatus(&is_hidden)) {
+ // No login item - this means the user must have already removed it, so
+ // call back to the UI thread to set a preference so we don't try to
+ // recreate it the next time they enable/install a background app.
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
Dmitry Titov 2012/08/09 18:22:23 So the detection of the user action (when user cle
+ base::Bind(SetUserRemovedLoginItemPrefCallback));
+ return;
+ }
+
+ // If the login item does not have the "hidden" flag set, just leave it there
+ // since it means the user must have created it.
+ if (!is_hidden)
return;
+ // Remove the login item we created.
base::mac::RemoveFromLoginItems();
}
@@ -33,8 +50,8 @@ void SetUserCreatedLoginItemPrefCallback() {
service->SetBoolean(prefs::kUserCreatedLoginItem, true);
}
-void EnableLaunchOnStartupCallback() {
- // Return if Chrome is already a Login Item (avoid overriding user choice).
+void EnableLaunchOnStartupCallback(bool should_add_login_item) {
+ // Check if Chrome is already a Login Item (avoid overriding user choice).
if (base::mac::CheckLoginItemStatus(NULL)) {
// Call back to the UI thread to set our preference so we don't delete the
// user's login item when we disable launch on startup. There's a race
@@ -46,7 +63,8 @@ void EnableLaunchOnStartupCallback() {
return;
}
- base::mac::AddToLoginItems(true); // Hide on startup.
+ if (should_add_login_item)
+ base::mac::AddToLoginItems(true); // Hide on startup.
}
} // namespace
@@ -57,13 +75,23 @@ void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
return;
if (should_launch) {
+ PrefService* service = g_browser_process->local_state();
+ // Create a login item if the user did not remove our login item
+ // previously. We call out to the FILE thread either way since we
+ // want to check for a user-created login item.
+ bool should_add_login_item =
+ !service->GetBoolean(prefs::kUserRemovedLoginItem);
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- base::Bind(EnableLaunchOnStartupCallback));
+ base::Bind(EnableLaunchOnStartupCallback,
+ should_add_login_item));
} else {
PrefService* service = g_browser_process->local_state();
if (service->GetBoolean(prefs::kUserCreatedLoginItem)) {
- // We didn't create the login item, so nothing to do here.
+ // We didn't create the login item, so nothing to do here. Clear our
+ // prefs so if the user removes the login item before installing a
+ // background app, we will revert to the default behavior.
service->ClearPref(prefs::kUserCreatedLoginItem);
+ service->ClearPref(prefs::kUserRemovedLoginItem);
return;
}
// Call to the File thread to remove the login item since it requires
« no previous file with comments | « chrome/browser/background/background_mode_manager.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698