OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "app/l10n_util.h" |
| 6 #include "base/command_line.h" |
| 7 #include "base/mac_util.h" |
| 8 #include "chrome/browser/background_mode_manager.h" |
| 9 #include "chrome/browser/browser_thread.h" |
| 10 #include "chrome/common/app_mode_common_mac.h" |
| 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "grit/generated_resources.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 class DisableLaunchOnStartupTask : public Task { |
| 17 public: |
| 18 virtual void Run(); |
| 19 }; |
| 20 |
| 21 class EnableLaunchOnStartupTask : public Task { |
| 22 public: |
| 23 virtual void Run(); |
| 24 }; |
| 25 |
| 26 const CFStringRef kLaunchOnStartupResetAllowedPrefsKey = |
| 27 CFSTR("LaunchOnStartupResetAllowed"); |
| 28 |
| 29 void DisableLaunchOnStartupTask::Run() { |
| 30 Boolean key_exists_and_has_valid_format; // ignored |
| 31 if (!CFPreferencesGetAppBooleanValue(kLaunchOnStartupResetAllowedPrefsKey, |
| 32 app_mode::kAppPrefsID, |
| 33 &key_exists_and_has_valid_format)) |
| 34 return; |
| 35 |
| 36 CFPreferencesSetAppValue(kLaunchOnStartupResetAllowedPrefsKey, |
| 37 kCFBooleanFalse, |
| 38 app_mode::kAppPrefsID); |
| 39 |
| 40 // Check if Chrome is not a login Item, or is a Login Item but w/o 'hidden' |
| 41 // flag - most likely user has modified the setting, don't override it. |
| 42 bool is_hidden = false; |
| 43 if (!mac_util::CheckLoginItemStatus(&is_hidden) || !is_hidden) |
| 44 return; |
| 45 |
| 46 mac_util::RemoveFromLoginItems(); |
| 47 } |
| 48 |
| 49 void EnableLaunchOnStartupTask::Run() { |
| 50 // Return if Chrome is already a Login Item (avoid overriding user choice). |
| 51 if (mac_util::CheckLoginItemStatus(NULL)) |
| 52 return; |
| 53 |
| 54 mac_util::AddToLoginItems(true); // Hide on startup. |
| 55 CFPreferencesSetAppValue(kLaunchOnStartupResetAllowedPrefsKey, |
| 56 kCFBooleanTrue, |
| 57 app_mode::kAppPrefsID); |
| 58 } |
| 59 |
| 60 } // namespace |
| 61 |
| 62 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { |
| 63 // This functionality is only defined for default profile, currently. |
| 64 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) |
| 65 return; |
| 66 |
| 67 if (should_launch) { |
| 68 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 69 new EnableLaunchOnStartupTask()); |
| 70 } else { |
| 71 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 72 new DisableLaunchOnStartupTask()); |
| 73 } |
| 74 } |
| 75 |
| 76 string16 BackgroundModeManager::GetPreferencesMenuLabel() { |
| 77 return l10n_util::GetStringUTF16(IDS_OPTIONS); |
| 78 } |
OLD | NEW |