diff options
author | rickcam@chromium.org <rickcam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 00:36:17 +0000 |
---|---|---|
committer | rickcam@chromium.org <rickcam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 00:36:17 +0000 |
commit | 70dd60bfabf67faab1041ce3e927bf207e12cc12 (patch) | |
tree | 5ff499596652b89988bab8e9dab3afa692c24ebc /chrome/browser/background_mode_manager_mac.mm | |
parent | e7f249b1630ebd949f11a466ce523d069550f5a4 (diff) | |
download | chromium_src-70dd60bfabf67faab1041ce3e927bf207e12cc12.zip chromium_src-70dd60bfabf67faab1041ce3e927bf207e12cc12.tar.gz chromium_src-70dd60bfabf67faab1041ce3e927bf207e12cc12.tar.bz2 |
Follow pattern used for Linux and Windows to move the appropriate bits of Mac code to the file thread.
BUG=59265
TEST=none
This patch also splits platform-specific LaunchOnStartup code to platform-specific files, eliminating #if blocks from the primary source file.
Review URL: http://codereview.chromium.org/5368002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68678 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/background_mode_manager_mac.mm')
-rw-r--r-- | chrome/browser/background_mode_manager_mac.mm | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/chrome/browser/background_mode_manager_mac.mm b/chrome/browser/background_mode_manager_mac.mm new file mode 100644 index 0000000..cc6ab4b --- /dev/null +++ b/chrome/browser/background_mode_manager_mac.mm @@ -0,0 +1,78 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "app/l10n_util.h" +#include "base/command_line.h" +#include "base/mac_util.h" +#include "chrome/browser/background_mode_manager.h" +#include "chrome/browser/browser_thread.h" +#include "chrome/common/app_mode_common_mac.h" +#include "chrome/common/chrome_switches.h" +#include "grit/generated_resources.h" + +namespace { + +class DisableLaunchOnStartupTask : public Task { + public: + virtual void Run(); +}; + +class EnableLaunchOnStartupTask : public Task { + public: + virtual void Run(); +}; + +const CFStringRef kLaunchOnStartupResetAllowedPrefsKey = + CFSTR("LaunchOnStartupResetAllowed"); + +void DisableLaunchOnStartupTask::Run() { + Boolean key_exists_and_has_valid_format; // ignored + if (!CFPreferencesGetAppBooleanValue(kLaunchOnStartupResetAllowedPrefsKey, + app_mode::kAppPrefsID, + &key_exists_and_has_valid_format)) + return; + + CFPreferencesSetAppValue(kLaunchOnStartupResetAllowedPrefsKey, + kCFBooleanFalse, + app_mode::kAppPrefsID); + + // 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 (!mac_util::CheckLoginItemStatus(&is_hidden) || !is_hidden) + return; + + mac_util::RemoveFromLoginItems(); +} + +void EnableLaunchOnStartupTask::Run() { + // Return if Chrome is already a Login Item (avoid overriding user choice). + if (mac_util::CheckLoginItemStatus(NULL)) + return; + + mac_util::AddToLoginItems(true); // Hide on startup. + CFPreferencesSetAppValue(kLaunchOnStartupResetAllowedPrefsKey, + kCFBooleanTrue, + app_mode::kAppPrefsID); +} + +} // namespace + +void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { + // This functionality is only defined for default profile, currently. + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) + return; + + if (should_launch) { + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, + new EnableLaunchOnStartupTask()); + } else { + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, + new DisableLaunchOnStartupTask()); + } +} + +string16 BackgroundModeManager::GetPreferencesMenuLabel() { + return l10n_util::GetStringUTF16(IDS_OPTIONS); +} |