| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
| 7 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 10 #include "base/task.h" | 11 #include "base/task.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "base/win/registry.h" | 13 #include "base/win/registry.h" |
| 13 #include "chrome/browser/background/background_mode_manager.h" | 14 #include "chrome/browser/background/background_mode_manager.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 namespace { |
| 24 | 25 |
| 25 class DisableLaunchOnStartupTask : public Task { | |
| 26 public: | |
| 27 virtual void Run(); | |
| 28 }; | |
| 29 | |
| 30 class EnableLaunchOnStartupTask : public Task { | |
| 31 public: | |
| 32 virtual void Run(); | |
| 33 }; | |
| 34 | |
| 35 const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER; | 26 const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER; |
| 36 const wchar_t* kBackgroundModeRegistrySubkey = | 27 const wchar_t* kBackgroundModeRegistrySubkey = |
| 37 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; | 28 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; |
| 38 const wchar_t* kBackgroundModeRegistryKeyName = L"chromium"; | 29 const wchar_t* kBackgroundModeRegistryKeyName = L"chromium"; |
| 39 | 30 |
| 40 void DisableLaunchOnStartupTask::Run() { | 31 void DisableLaunchOnStartupCallback() { |
| 41 const wchar_t* key_name = kBackgroundModeRegistryKeyName; | 32 const wchar_t* key_name = kBackgroundModeRegistryKeyName; |
| 42 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, | 33 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, |
| 43 kBackgroundModeRegistrySubkey, KEY_READ); | 34 kBackgroundModeRegistrySubkey, KEY_READ); |
| 44 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, | 35 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, |
| 45 kBackgroundModeRegistrySubkey, KEY_WRITE); | 36 kBackgroundModeRegistrySubkey, KEY_WRITE); |
| 46 if (read_key.HasValue(key_name)) { | 37 if (read_key.HasValue(key_name)) { |
| 47 LONG result = write_key.DeleteValue(key_name); | 38 LONG result = write_key.DeleteValue(key_name); |
| 48 DCHECK_EQ(ERROR_SUCCESS, result) << | 39 DCHECK_EQ(ERROR_SUCCESS, result) << |
| 49 "Failed to deregister launch on login. error: " << result; | 40 "Failed to deregister launch on login. error: " << result; |
| 50 } | 41 } |
| 51 } | 42 } |
| 52 | 43 |
| 53 void EnableLaunchOnStartupTask::Run() { | 44 void EnableLaunchOnStartupCallback() { |
| 54 // TODO(rickcam): Bug 53597: Make RegKey mockable. | 45 // TODO(rickcam): Bug 53597: Make RegKey mockable. |
| 55 // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile. | 46 // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile. |
| 56 const wchar_t* key_name = kBackgroundModeRegistryKeyName; | 47 const wchar_t* key_name = kBackgroundModeRegistryKeyName; |
| 57 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, | 48 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, |
| 58 kBackgroundModeRegistrySubkey, KEY_READ); | 49 kBackgroundModeRegistrySubkey, KEY_READ); |
| 59 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, | 50 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, |
| 60 kBackgroundModeRegistrySubkey, KEY_WRITE); | 51 kBackgroundModeRegistrySubkey, KEY_WRITE); |
| 61 FilePath executable; | 52 FilePath executable; |
| 62 if (!PathService::Get(base::FILE_EXE, &executable)) | 53 if (!PathService::Get(base::FILE_EXE, &executable)) |
| 63 return; | 54 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 76 } | 67 } |
| 77 | 68 |
| 78 } // namespace | 69 } // namespace |
| 79 | 70 |
| 80 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { | 71 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { |
| 81 // This functionality is only defined for default profile, currently. | 72 // This functionality is only defined for default profile, currently. |
| 82 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) | 73 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) |
| 83 return; | 74 return; |
| 84 if (should_launch) { | 75 if (should_launch) { |
| 85 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 76 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 86 new EnableLaunchOnStartupTask()); | 77 base::Bind(EnableLaunchOnStartupCallback)); |
| 87 } else { | 78 } else { |
| 88 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 79 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 89 new DisableLaunchOnStartupTask()); | 80 base::Bind(DisableLaunchOnStartupCallback)); |
| 90 } | 81 } |
| 91 } | 82 } |
| 92 | 83 |
| 93 void BackgroundModeManager::DisplayAppInstalledNotification( | 84 void BackgroundModeManager::DisplayAppInstalledNotification( |
| 94 const Extension* extension) { | 85 const Extension* extension) { |
| 95 // Create a status tray notification balloon explaining to the user that | 86 // Create a status tray notification balloon explaining to the user that |
| 96 // a background app has been installed. | 87 // a background app has been installed. |
| 97 CreateStatusTrayIcon(); | 88 CreateStatusTrayIcon(); |
| 98 status_icon_->DisplayBalloon( | 89 status_icon_->DisplayBalloon( |
| 99 SkBitmap(), | 90 SkBitmap(), |
| 100 l10n_util::GetStringUTF16(IDS_BACKGROUND_APP_INSTALLED_BALLOON_TITLE), | 91 l10n_util::GetStringUTF16(IDS_BACKGROUND_APP_INSTALLED_BALLOON_TITLE), |
| 101 l10n_util::GetStringFUTF16( | 92 l10n_util::GetStringFUTF16( |
| 102 IDS_BACKGROUND_APP_INSTALLED_BALLOON_BODY, | 93 IDS_BACKGROUND_APP_INSTALLED_BALLOON_BODY, |
| 103 UTF8ToUTF16(extension->name()), | 94 UTF8ToUTF16(extension->name()), |
| 104 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 95 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 105 } | 96 } |
| 106 | 97 |
| 107 string16 BackgroundModeManager::GetPreferencesMenuLabel() { | 98 string16 BackgroundModeManager::GetPreferencesMenuLabel() { |
| 108 return l10n_util::GetStringUTF16(IDS_OPTIONS); | 99 return l10n_util::GetStringUTF16(IDS_OPTIONS); |
| 109 } | 100 } |
| OLD | NEW |