Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / background / background_mode_manager_gtk.cc
1 // Copyright (c) 2012 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 "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/environment.h"
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
12 #include "base/nix/xdg_util.h"
13 #include "chrome/browser/background/background_mode_manager.h"
14 #include "chrome/browser/shell_integration_linux.h"
15 #include "chrome/browser/ui/gtk/gtk_util.h"
16 #include "chrome/common/auto_start_linux.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/chrome_version_info.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h"
22
23 using content::BrowserThread;
24 using extensions::Extension;
25
26 namespace {
27
28 // TODO(rickcam): Bug 56280: Share implementation with ShellIntegration
29 void EnableLaunchOnStartupCallback() {
30   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
31   scoped_ptr<base::Environment> environment(base::Environment::Create());
32   scoped_ptr<chrome::VersionInfo> version_info(new chrome::VersionInfo());
33
34   std::string wrapper_script;
35   if (!environment->GetVar("CHROME_WRAPPER", &wrapper_script)) {
36     LOG(WARNING)
37         << "Failed to register launch on login.  CHROME_WRAPPER not set.";
38     return;
39   }
40   std::string command_line = wrapper_script +
41       " --" + switches::kNoStartupWindow;
42   if (!AutoStart::AddApplication(
43           ShellIntegrationLinux::GetDesktopName(environment.get()),
44           version_info->Name(),
45           command_line,
46           false)) {
47     NOTREACHED() << "Failed to register launch on login.";
48   }
49 }
50
51 void DisableLaunchOnStartupCallback() {
52   scoped_ptr<base::Environment> environment(base::Environment::Create());
53   if (!AutoStart::Remove(
54           ShellIntegrationLinux::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
74 void BackgroundModeManager::DisplayAppInstalledNotification(
75     const Extension* extension) {
76   // TODO(atwilson): Display a platform-appropriate notification here.
77   // http://crbug.com/74970
78 }
79
80 base::string16 BackgroundModeManager::GetPreferencesMenuLabel() {
81   base::string16 result = gtk_util::GetStockPreferencesMenuLabel();
82   if (!result.empty())
83     return result;
84   return l10n_util::GetStringUTF16(IDS_PREFERENCES);
85 }