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

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: Eliminating excess header includes: Windows 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 "base/file_path.h"
6 #include "base/logging.h"
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/background_mode_manager.h"
9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/shell_integration.h"
11 #include "chrome/common/pref_names.h"
12 #include "grit/generated_resources.h"
13
14 #include <unistd.h>
15 #include "base/environment.h"
16 #include "base/file_util.h"
17 #include "base/nix/xdg_util.h"
Andrew T Wilson (Slow) 2010/12/03 02:06:59 I think all of these header files (other than unis
The wrong rickcam account 2010/12/04 02:08:04 Done.
18 #include "base/task.h"
19 #include "chrome/common/chrome_version_info.h"
20
21 #include "chrome/browser/gtk/gtk_util.h"
22
23 static const FilePath::CharType kAutostart[] = "autostart";
24 static const FilePath::CharType kConfig[] = ".config";
25 static const char kXdgConfigHome[] = "XDG_CONFIG_HOME";
26
27 namespace {
28
29 FilePath GetAutostartDirectory(base::Environment* environment) {
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
31 FilePath result =
32 base::nix::GetXDGDirectory(environment, kXdgConfigHome, kConfig);
33 result = result.Append(kAutostart);
34 return result;
35 }
36
37 FilePath GetAutostartFilename(base::Environment* environment) {
38 FilePath directory = GetAutostartDirectory(environment);
39 return directory.Append(ShellIntegration::GetDesktopName(environment));
40 }
41
42 } // namespace
43
44 void BackgroundModeManager::DisableLaunchOnStartupTask::Run() {
45 scoped_ptr<base::Environment> environment(base::Environment::Create());
46 if (!file_util::Delete(GetAutostartFilename(environment.get()), false)) {
47 LOG(WARNING) << "Failed to deregister launch on login.";
48 }
49 }
50
51 // TODO(rickcam): Bug 56280: Share implementation with ShellIntegration
52 void BackgroundModeManager::EnableLaunchOnStartupTask::Run() {
53 scoped_ptr<base::Environment> environment(base::Environment::Create());
54 scoped_ptr<chrome::VersionInfo> version_info(new chrome::VersionInfo());
55 FilePath autostart_directory = GetAutostartDirectory(environment.get());
56 FilePath autostart_file = GetAutostartFilename(environment.get());
57 if (!file_util::DirectoryExists(autostart_directory) &&
58 !file_util::CreateDirectory(autostart_directory)) {
59 LOG(WARNING)
60 << "Failed to register launch on login. No autostart directory.";
61 return;
62 }
63 std::string wrapper_script;
64 if (!environment->GetVar("CHROME_WRAPPER", &wrapper_script)) {
65 LOG(WARNING)
66 << "Failed to register launch on login. CHROME_WRAPPER not set.";
67 return;
68 }
69 std::string autostart_file_contents =
70 "[Desktop Entry]\n"
71 "Type=Application\n"
72 "Terminal=false\n"
73 "Exec=" + wrapper_script +
74 " --enable-background-mode --no-startup-window\n"
75 "Name=" + version_info->Name() + "\n";
76 std::string::size_type content_length = autostart_file_contents.length();
77 if (file_util::WriteFile(autostart_file, autostart_file_contents.c_str(),
78 content_length) !=
79 static_cast<int>(content_length)) {
80 LOG(WARNING) << "Failed to register launch on login. Failed to write "
81 << autostart_file.value();
82 file_util::Delete(GetAutostartFilename(environment.get()), false);
83 }
84 }
85
86 void BackgroundModeManager::AddPreferencesItem(menus::SimpleMenuModel* menu) {
87 string16 preferences = gtk_util::GetStockPreferencesMenuLabel();
88 if (!preferences.empty())
89 menu->AddItem(IDC_OPTIONS, preferences);
90 else
91 menu->AddItemWithStringId(IDC_OPTIONS, IDS_PREFERENCES);
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698