Chromium Code Reviews| Index: chrome/browser/background_mode_manager_linux.cc |
| diff --git a/chrome/browser/background_mode_manager_linux.cc b/chrome/browser/background_mode_manager_linux.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7891461f38d522896866115cda1f3e1cb09dd9ea |
| --- /dev/null |
| +++ b/chrome/browser/background_mode_manager_linux.cc |
| @@ -0,0 +1,92 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/file_path.h" |
| +#include "base/logging.h" |
| +#include "chrome/app/chrome_command_ids.h" |
| +#include "chrome/browser/background_mode_manager.h" |
| +#include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/browser/shell_integration.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "grit/generated_resources.h" |
| + |
| +#include <unistd.h> |
| +#include "base/environment.h" |
| +#include "base/file_util.h" |
| +#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.
|
| +#include "base/task.h" |
| +#include "chrome/common/chrome_version_info.h" |
| + |
| +#include "chrome/browser/gtk/gtk_util.h" |
| + |
| +static const FilePath::CharType kAutostart[] = "autostart"; |
| +static const FilePath::CharType kConfig[] = ".config"; |
| +static const char kXdgConfigHome[] = "XDG_CONFIG_HOME"; |
| + |
| +namespace { |
| + |
| +FilePath GetAutostartDirectory(base::Environment* environment) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + FilePath result = |
| + base::nix::GetXDGDirectory(environment, kXdgConfigHome, kConfig); |
| + result = result.Append(kAutostart); |
| + return result; |
| +} |
| + |
| +FilePath GetAutostartFilename(base::Environment* environment) { |
| + FilePath directory = GetAutostartDirectory(environment); |
| + return directory.Append(ShellIntegration::GetDesktopName(environment)); |
| +} |
| + |
| +} // namespace |
| + |
| +void BackgroundModeManager::DisableLaunchOnStartupTask::Run() { |
| + scoped_ptr<base::Environment> environment(base::Environment::Create()); |
| + if (!file_util::Delete(GetAutostartFilename(environment.get()), false)) { |
| + LOG(WARNING) << "Failed to deregister launch on login."; |
| + } |
| +} |
| + |
| +// TODO(rickcam): Bug 56280: Share implementation with ShellIntegration |
| +void BackgroundModeManager::EnableLaunchOnStartupTask::Run() { |
| + scoped_ptr<base::Environment> environment(base::Environment::Create()); |
| + scoped_ptr<chrome::VersionInfo> version_info(new chrome::VersionInfo()); |
| + FilePath autostart_directory = GetAutostartDirectory(environment.get()); |
| + FilePath autostart_file = GetAutostartFilename(environment.get()); |
| + if (!file_util::DirectoryExists(autostart_directory) && |
| + !file_util::CreateDirectory(autostart_directory)) { |
| + LOG(WARNING) |
| + << "Failed to register launch on login. No autostart directory."; |
| + return; |
| + } |
| + std::string wrapper_script; |
| + if (!environment->GetVar("CHROME_WRAPPER", &wrapper_script)) { |
| + LOG(WARNING) |
| + << "Failed to register launch on login. CHROME_WRAPPER not set."; |
| + return; |
| + } |
| + std::string autostart_file_contents = |
| + "[Desktop Entry]\n" |
| + "Type=Application\n" |
| + "Terminal=false\n" |
| + "Exec=" + wrapper_script + |
| + " --enable-background-mode --no-startup-window\n" |
| + "Name=" + version_info->Name() + "\n"; |
| + std::string::size_type content_length = autostart_file_contents.length(); |
| + if (file_util::WriteFile(autostart_file, autostart_file_contents.c_str(), |
| + content_length) != |
| + static_cast<int>(content_length)) { |
| + LOG(WARNING) << "Failed to register launch on login. Failed to write " |
| + << autostart_file.value(); |
| + file_util::Delete(GetAutostartFilename(environment.get()), false); |
| + } |
| +} |
| + |
| +void BackgroundModeManager::AddPreferencesItem(menus::SimpleMenuModel* menu) { |
| + string16 preferences = gtk_util::GetStockPreferencesMenuLabel(); |
| + if (!preferences.empty()) |
| + menu->AddItem(IDC_OPTIONS, preferences); |
| + else |
| + menu->AddItemWithStringId(IDC_OPTIONS, IDS_PREFERENCES); |
| +} |