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 <unistd.h> | 5 #include <unistd.h> |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/environment.h" | 9 #include "base/environment.h" |
9 #include "base/file_path.h" | 10 #include "base/file_path.h" |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/nix/xdg_util.h" | 13 #include "base/nix/xdg_util.h" |
13 #include "base/task.h" | 14 #include "base/task.h" |
14 #include "chrome/browser/background/background_mode_manager.h" | 15 #include "chrome/browser/background/background_mode_manager.h" |
15 #include "chrome/browser/shell_integration.h" | 16 #include "chrome/browser/shell_integration.h" |
16 #include "chrome/browser/ui/gtk/gtk_util.h" | 17 #include "chrome/browser/ui/gtk/gtk_util.h" |
17 #include "chrome/common/auto_start_linux.h" | 18 #include "chrome/common/auto_start_linux.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 | 24 |
24 using content::BrowserThread; | 25 using content::BrowserThread; |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 class DisableLaunchOnStartupTask : public Task { | |
29 public: | |
30 virtual void Run(); | |
31 }; | |
32 | |
33 class EnableLaunchOnStartupTask : public Task { | |
34 public: | |
35 virtual void Run(); | |
36 }; | |
37 | |
38 } // namespace | |
39 | |
40 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { | |
41 // This functionality is only defined for default profile, currently. | |
42 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) | |
43 return; | |
44 if (should_launch) { | |
45 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
46 new EnableLaunchOnStartupTask()); | |
47 } else { | |
48 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
49 new DisableLaunchOnStartupTask()); | |
50 } | |
51 } | |
52 | |
53 void DisableLaunchOnStartupTask::Run() { | |
54 scoped_ptr<base::Environment> environment(base::Environment::Create()); | |
55 if (!AutoStart::Remove(ShellIntegration::GetDesktopName(environment.get()))) { | |
56 NOTREACHED() << "Failed to deregister launch on login."; | |
57 } | |
58 } | |
59 | |
60 // TODO(rickcam): Bug 56280: Share implementation with ShellIntegration | 29 // TODO(rickcam): Bug 56280: Share implementation with ShellIntegration |
61 void EnableLaunchOnStartupTask::Run() { | 30 void EnableLaunchOnStartupCallback() { |
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
63 scoped_ptr<base::Environment> environment(base::Environment::Create()); | 32 scoped_ptr<base::Environment> environment(base::Environment::Create()); |
64 scoped_ptr<chrome::VersionInfo> version_info(new chrome::VersionInfo()); | 33 scoped_ptr<chrome::VersionInfo> version_info(new chrome::VersionInfo()); |
65 | 34 |
66 std::string wrapper_script; | 35 std::string wrapper_script; |
67 if (!environment->GetVar("CHROME_WRAPPER", &wrapper_script)) { | 36 if (!environment->GetVar("CHROME_WRAPPER", &wrapper_script)) { |
68 LOG(WARNING) | 37 LOG(WARNING) |
69 << "Failed to register launch on login. CHROME_WRAPPER not set."; | 38 << "Failed to register launch on login. CHROME_WRAPPER not set."; |
70 return; | 39 return; |
71 } | 40 } |
72 std::string command_line = wrapper_script + | 41 std::string command_line = wrapper_script + |
73 " --" + switches::kNoStartupWindow; | 42 " --" + switches::kNoStartupWindow; |
74 if (!AutoStart::AddApplication( | 43 if (!AutoStart::AddApplication( |
75 ShellIntegration::GetDesktopName(environment.get()), | 44 ShellIntegration::GetDesktopName(environment.get()), |
76 version_info->Name(), | 45 version_info->Name(), |
77 command_line, | 46 command_line, |
78 false)) { | 47 false)) { |
79 NOTREACHED() << "Failed to register launch on login."; | 48 NOTREACHED() << "Failed to register launch on login."; |
80 } | 49 } |
81 } | 50 } |
82 | 51 |
| 52 void DisableLaunchOnStartupCallback() { |
| 53 scoped_ptr<base::Environment> environment(base::Environment::Create()); |
| 54 if (!AutoStart::Remove(ShellIntegration::GetDesktopName(environment.get()))) { |
| 55 NOTREACHED() << "Failed to deregister launch on login."; |
| 56 } |
| 57 } |
| 58 |
| 59 } // namespace |
| 60 |
| 61 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { |
| 62 // This functionality is only defined for default profile, currently. |
| 63 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) |
| 64 return; |
| 65 if (should_launch) { |
| 66 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 67 base::Bind(EnableLaunchOnStartupCallback)); |
| 68 } else { |
| 69 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 70 base::Bind(DisableLaunchOnStartupCallback)); |
| 71 } |
| 72 } |
| 73 |
83 void BackgroundModeManager::DisplayAppInstalledNotification( | 74 void BackgroundModeManager::DisplayAppInstalledNotification( |
84 const Extension* extension) { | 75 const Extension* extension) { |
85 // TODO(atwilson): Display a platform-appropriate notification here. | 76 // TODO(atwilson): Display a platform-appropriate notification here. |
86 // http://crbug.com/74970 | 77 // http://crbug.com/74970 |
87 } | 78 } |
88 | 79 |
89 string16 BackgroundModeManager::GetPreferencesMenuLabel() { | 80 string16 BackgroundModeManager::GetPreferencesMenuLabel() { |
90 string16 result = gtk_util::GetStockPreferencesMenuLabel(); | 81 string16 result = gtk_util::GetStockPreferencesMenuLabel(); |
91 if (!result.empty()) | 82 if (!result.empty()) |
92 return result; | 83 return result; |
93 return l10n_util::GetStringUTF16(IDS_PREFERENCES); | 84 return l10n_util::GetStringUTF16(IDS_PREFERENCES); |
94 } | 85 } |
OLD | NEW |