Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: chrome/browser/background_mode_manager_linux.cc

Issue 5368002: Move Mac LaunchOnStartup enable/disable to File thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changing Mac LaunchOnStartupResetAllowed to accommodate FILE thread issues Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 <unistd.h>
6
7 #include "app/l10n_util.h"
8 #include "base/command_line.h"
9 #include "base/environment.h"
10 #include "base/file_path.h"
11 #include "base/file_util.h"
12 #include "base/logging.h"
13 #include "base/nix/xdg_util.h"
14 #include "base/task.h"
15 #include "chrome/app/chrome_command_ids.h"
Andrew T Wilson (Slow) 2010/12/04 18:49:48 I don't think this is needed any more (chrome_comm
The wrong rickcam account 2010/12/07 22:59:57 Done.
16 #include "chrome/browser/background_mode_manager.h"
17 #include "chrome/browser/browser_thread.h"
18 #include "chrome/browser/gtk/gtk_util.h"
19 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/shell_integration.h"
21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/chrome_version_info.h"
23 #include "chrome/common/pref_names.h"
24 #include "grit/generated_resources.h"
25
26 class DisableLaunchOnStartupTask : public Task {
27 public:
28 virtual void Run();
Andrew T Wilson (Slow) 2010/12/04 18:49:48 BTW, one thing I sometimes do for these private cl
The wrong rickcam account 2010/12/07 22:59:57 Two-part answer: (1) I'd like to leave the defini
29 };
30
31 class EnableLaunchOnStartupTask : public Task {
32 public:
33 virtual void Run();
34 };
35
36 static const FilePath::CharType kAutostart[] = "autostart";
37 static const FilePath::CharType kConfig[] = ".config";
38 static const char kXdgConfigHome[] = "XDG_CONFIG_HOME";
39
40 namespace {
41
42 FilePath GetAutostartDirectory(base::Environment* environment) {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
44 FilePath result =
45 base::nix::GetXDGDirectory(environment, kXdgConfigHome, kConfig);
46 result = result.Append(kAutostart);
47 return result;
48 }
49
50 FilePath GetAutostartFilename(base::Environment* environment) {
51 FilePath directory = GetAutostartDirectory(environment);
52 return directory.Append(ShellIntegration::GetDesktopName(environment));
53 }
54
55 } // namespace
56
57 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
58 // This functionality is only defined for default profile, currently.
59 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir))
60 return;
61 if (should_launch) {
62 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
63 new EnableLaunchOnStartupTask());
64 } else {
65 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
66 new DisableLaunchOnStartupTask());
67 }
68 }
69
70 void DisableLaunchOnStartupTask::Run() {
71 scoped_ptr<base::Environment> environment(base::Environment::Create());
72 if (!file_util::Delete(GetAutostartFilename(environment.get()), false)) {
73 LOG(WARNING) << "Failed to deregister launch on login.";
Andrew T Wilson (Slow) 2010/12/04 18:49:48 I might add a NOT_REACHED here as I think we'd lik
The wrong rickcam account 2010/12/07 22:59:57 Done. I replaced LOG(...) with NOTREACHED() throu
74 }
75 }
76
77 // TODO(rickcam): Bug 56280: Share implementation with ShellIntegration
78 void EnableLaunchOnStartupTask::Run() {
79 scoped_ptr<base::Environment> environment(base::Environment::Create());
80 scoped_ptr<chrome::VersionInfo> version_info(new chrome::VersionInfo());
81 FilePath autostart_directory = GetAutostartDirectory(environment.get());
82 FilePath autostart_file = GetAutostartFilename(environment.get());
83 if (!file_util::DirectoryExists(autostart_directory) &&
84 !file_util::CreateDirectory(autostart_directory)) {
85 LOG(WARNING)
86 << "Failed to register launch on login. No autostart directory.";
87 return;
88 }
89 std::string wrapper_script;
90 if (!environment->GetVar("CHROME_WRAPPER", &wrapper_script)) {
91 LOG(WARNING)
92 << "Failed to register launch on login. CHROME_WRAPPER not set.";
93 return;
94 }
95 std::string autostart_file_contents =
96 "[Desktop Entry]\n"
97 "Type=Application\n"
98 "Terminal=false\n"
99 "Exec=" + wrapper_script +
100 " --enable-background-mode --no-startup-window\n"
101 "Name=" + version_info->Name() + "\n";
102 std::string::size_type content_length = autostart_file_contents.length();
103 if (file_util::WriteFile(autostart_file, autostart_file_contents.c_str(),
104 content_length) !=
105 static_cast<int>(content_length)) {
106 LOG(WARNING) << "Failed to register launch on login. Failed to write "
107 << autostart_file.value();
108 file_util::Delete(GetAutostartFilename(environment.get()), false);
109 }
110 }
111
112 string16 BackgroundModeManager::GetPreferencesMenuLabel() {
113 string16 result = gtk_util::GetStockPreferencesMenuLabel();
114 if (!result.empty())
115 return result;
116 return l10n_util::GetStringUTF16(IDS_PREFERENCES);
117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698