| OLD | NEW |
| 1 // Copyright (c) 2011 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 "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/win/registry.h" | 12 #include "base/win/registry.h" |
| 13 #include "chrome/browser/background/background_mode_manager.h" | 13 #include "chrome/browser/background/background_mode_manager.h" |
| 14 #include "chrome/installer/util/auto_launch_util.h" |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
| 17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 | 21 |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 namespace { | |
| 24 | |
| 25 const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER; | |
| 26 const wchar_t* kBackgroundModeRegistrySubkey = | |
| 27 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; | |
| 28 const wchar_t* kBackgroundModeRegistryKeyName = L"chromium"; | |
| 29 | |
| 30 void DisableLaunchOnStartupCallback() { | |
| 31 const wchar_t* key_name = kBackgroundModeRegistryKeyName; | |
| 32 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, | |
| 33 kBackgroundModeRegistrySubkey, KEY_READ); | |
| 34 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, | |
| 35 kBackgroundModeRegistrySubkey, KEY_WRITE); | |
| 36 if (read_key.HasValue(key_name)) { | |
| 37 LONG result = write_key.DeleteValue(key_name); | |
| 38 DCHECK_EQ(ERROR_SUCCESS, result) << | |
| 39 "Failed to deregister launch on login. error: " << result; | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 void EnableLaunchOnStartupCallback() { | |
| 44 // TODO(rickcam): Bug 53597: Make RegKey mockable. | |
| 45 // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile. | |
| 46 const wchar_t* key_name = kBackgroundModeRegistryKeyName; | |
| 47 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, | |
| 48 kBackgroundModeRegistrySubkey, KEY_READ); | |
| 49 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, | |
| 50 kBackgroundModeRegistrySubkey, KEY_WRITE); | |
| 51 FilePath executable; | |
| 52 if (!PathService::Get(base::FILE_EXE, &executable)) | |
| 53 return; | |
| 54 std::wstring new_value = executable.value() + | |
| 55 L" --" + ASCIIToUTF16(switches::kNoStartupWindow); | |
| 56 if (read_key.HasValue(key_name)) { | |
| 57 std::wstring current_value; | |
| 58 if ((read_key.ReadValue(key_name, ¤t_value) == ERROR_SUCCESS) && | |
| 59 (current_value == new_value)) { | |
| 60 return; | |
| 61 } | |
| 62 } | |
| 63 LONG result = write_key.WriteValue(key_name, new_value.c_str()); | |
| 64 DCHECK_EQ(ERROR_SUCCESS, result) << | |
| 65 "Failed to register launch on login. error: " << result; | |
| 66 } | |
| 67 | |
| 68 } // namespace | |
| 69 | |
| 70 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { | 24 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { |
| 71 // This functionality is only defined for default profile, currently. | 25 // This functionality is only defined for default profile, currently. |
| 72 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) | 26 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) |
| 73 return; | 27 return; |
| 74 if (should_launch) { | 28 BrowserThread::PostTask( |
| 75 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 29 BrowserThread::FILE, FROM_HERE, |
| 76 base::Bind(EnableLaunchOnStartupCallback)); | 30 should_launch ? |
| 77 } else { | 31 base::Bind(auto_launch_util::EnableBackgroundStartAtLogin) : |
| 78 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 32 base::Bind(auto_launch_util::DisableBackgroundStartAtLogin)); |
| 79 base::Bind(DisableLaunchOnStartupCallback)); | |
| 80 } | |
| 81 } | 33 } |
| 82 | 34 |
| 83 void BackgroundModeManager::DisplayAppInstalledNotification( | 35 void BackgroundModeManager::DisplayAppInstalledNotification( |
| 84 const Extension* extension) { | 36 const Extension* extension) { |
| 85 // Create a status tray notification balloon explaining to the user that | 37 // Create a status tray notification balloon explaining to the user that |
| 86 // a background app has been installed. | 38 // a background app has been installed. |
| 87 CreateStatusTrayIcon(); | 39 CreateStatusTrayIcon(); |
| 88 status_icon_->DisplayBalloon( | 40 status_icon_->DisplayBalloon( |
| 89 SkBitmap(), | 41 SkBitmap(), |
| 90 l10n_util::GetStringUTF16(IDS_BACKGROUND_APP_INSTALLED_BALLOON_TITLE), | 42 l10n_util::GetStringUTF16(IDS_BACKGROUND_APP_INSTALLED_BALLOON_TITLE), |
| 91 l10n_util::GetStringFUTF16( | 43 l10n_util::GetStringFUTF16( |
| 92 IDS_BACKGROUND_APP_INSTALLED_BALLOON_BODY, | 44 IDS_BACKGROUND_APP_INSTALLED_BALLOON_BODY, |
| 93 UTF8ToUTF16(extension->name()), | 45 UTF8ToUTF16(extension->name()), |
| 94 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 46 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 95 } | 47 } |
| 96 | 48 |
| 97 string16 BackgroundModeManager::GetPreferencesMenuLabel() { | 49 string16 BackgroundModeManager::GetPreferencesMenuLabel() { |
| 98 return l10n_util::GetStringUTF16(IDS_OPTIONS); | 50 return l10n_util::GetStringUTF16(IDS_OPTIONS); |
| 99 } | 51 } |
| OLD | NEW |