Moved Linux specific shell integration declarations into own header.

This continues refactoring started in http://codereview.chromium.org/9958006/

BUG=None
TEST=Refactor; covered by existing tests


Review URL: http://codereview.chromium.org/10097004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132489 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/background/background_mode_manager_gtk.cc b/chrome/browser/background/background_mode_manager_gtk.cc
index 26f2b1e..890b437 100644
--- a/chrome/browser/background/background_mode_manager_gtk.cc
+++ b/chrome/browser/background/background_mode_manager_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
 
@@ -12,7 +12,7 @@
 #include "base/logging.h"
 #include "base/nix/xdg_util.h"
 #include "chrome/browser/background/background_mode_manager.h"
-#include "chrome/browser/shell_integration.h"
+#include "chrome/browser/shell_integration_linux.h"
 #include "chrome/browser/ui/gtk/gtk_util.h"
 #include "chrome/common/auto_start_linux.h"
 #include "chrome/common/chrome_switches.h"
@@ -40,7 +40,7 @@
   std::string command_line = wrapper_script +
       " --" + switches::kNoStartupWindow;
   if (!AutoStart::AddApplication(
-          ShellIntegration::GetDesktopName(environment.get()),
+          ShellIntegrationLinux::GetDesktopName(environment.get()),
           version_info->Name(),
           command_line,
           false)) {
@@ -50,7 +50,8 @@
 
 void DisableLaunchOnStartupCallback() {
   scoped_ptr<base::Environment> environment(base::Environment::Create());
-  if (!AutoStart::Remove(ShellIntegration::GetDesktopName(environment.get()))) {
+  if (!AutoStart::Remove(
+          ShellIntegrationLinux::GetDesktopName(environment.get()))) {
     NOTREACHED() << "Failed to deregister launch on login.";
   }
 }
diff --git a/chrome/browser/shell_integration.h b/chrome/browser/shell_integration.h
index a96e16e..5571da1 100644
--- a/chrome/browser/shell_integration.h
+++ b/chrome/browser/shell_integration.h
@@ -17,12 +17,6 @@
 
 class CommandLine;
 
-#if defined(USE_X11)
-namespace base {
-class Environment;
-}
-#endif
-
 class ShellIntegration {
  public:
   // Sets Chrome as the default browser (only for the current user). Returns
@@ -119,34 +113,6 @@
       const FilePath& user_data_dir,
       const FilePath& extension_path);
 
-#if defined(USE_X11)
-  // Returns filename of the desktop shortcut used to launch the browser.
-  static std::string GetDesktopName(base::Environment* env);
-
-  static bool GetDesktopShortcutTemplate(base::Environment* env,
-                                         std::string* output);
-
-  // Returns filename for .desktop file based on |url|, sanitized for security.
-  static FilePath GetDesktopShortcutFilename(const GURL& url);
-
-  // Returns contents for .desktop file based on |template_contents|, |url|
-  // and |title|. The |template_contents| should be contents of .desktop file
-  // used to launch Chrome.
-  static std::string GetDesktopFileContents(
-      const std::string& template_contents,
-      const std::string& app_name,
-      const GURL& url,
-      const std::string& extension_id,
-      const bool is_platform_app,
-      const FilePath& web_app_path,
-      const FilePath& extension_path,
-      const string16& title,
-      const std::string& icon_name);
-
-  static bool CreateDesktopShortcut(const ShortcutInfo& shortcut_info,
-                                    const std::string& shortcut_template);
-#endif  // defined(USE_X11)
-
 #if defined(OS_WIN)
   // Generates Win7 app id for given app name and profile path. The returned app
   // id is in the format of "|app_name|[.<profile_id>]". "profile_id" is
diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc
index 4f9caced..f58b7e6 100644
--- a/chrome/browser/shell_integration_linux.cc
+++ b/chrome/browser/shell_integration_linux.cc
@@ -232,21 +232,6 @@
 
 }  // namespace
 
-// static
-std::string ShellIntegration::GetDesktopName(base::Environment* env) {
-#if defined(GOOGLE_CHROME_BUILD)
-  return "google-chrome.desktop";
-#else  // CHROMIUM_BUILD
-  // Allow $CHROME_DESKTOP to override the built-in value, so that development
-  // versions can set themselves as the default without interfering with
-  // non-official, packaged versions using the built-in value.
-  std::string name;
-  if (env->GetVar("CHROME_DESKTOP", &name) && !name.empty())
-    return name;
-  return "chromium-browser.desktop";
-#endif
-}
-
 namespace {
 
 // Utility function to get the path to the version of a script shipped with
@@ -307,7 +292,7 @@
     argv.push_back(kXdgSettingsDefaultSchemeHandler);
     argv.push_back(protocol);
   }
-  argv.push_back(ShellIntegration::GetDesktopName(env.get()));
+  argv.push_back(ShellIntegrationLinux::GetDesktopName(env.get()));
 
   int exit_code;
   bool ran_ok = LaunchXdgUtility(argv, &exit_code);
@@ -338,7 +323,7 @@
     argv.push_back(kXdgSettingsDefaultSchemeHandler);
     argv.push_back(protocol);
   }
-  argv.push_back(ShellIntegration::GetDesktopName(env.get()));
+  argv.push_back(ShellIntegrationLinux::GetDesktopName(env.get()));
 
   std::string reply;
   int success_code;
@@ -402,9 +387,24 @@
   return browser.find("irefox") != std::string::npos;
 }
 
-// static
-bool ShellIntegration::GetDesktopShortcutTemplate(
-    base::Environment* env, std::string* output) {
+namespace ShellIntegrationLinux {
+
+std::string GetDesktopName(base::Environment* env) {
+#if defined(GOOGLE_CHROME_BUILD)
+  return "google-chrome.desktop";
+#else  // CHROMIUM_BUILD
+  // Allow $CHROME_DESKTOP to override the built-in value, so that development
+  // versions can set themselves as the default without interfering with
+  // non-official, packaged versions using the built-in value.
+  std::string name;
+  if (env->GetVar("CHROME_DESKTOP", &name) && !name.empty())
+    return name;
+  return "chromium-browser.desktop";
+#endif
+}
+
+bool GetDesktopShortcutTemplate(base::Environment* env,
+                                std::string* output) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
 
   std::vector<FilePath> search_paths;
@@ -446,8 +446,7 @@
   return false;
 }
 
-// static
-FilePath ShellIntegration::GetDesktopShortcutFilename(const GURL& url) {
+FilePath GetDesktopShortcutFilename(const GURL& url) {
   // Use a prefix, because xdg-desktop-menu requires it.
   std::string filename =
       std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec();
@@ -471,8 +470,7 @@
   return FilePath();
 }
 
-// static
-std::string ShellIntegration::GetDesktopFileContents(
+std::string GetDesktopFileContents(
     const std::string& template_contents,
     const std::string& app_name,
     const GURL& url,
@@ -590,9 +588,8 @@
   return output_buffer;
 }
 
-// static
-bool ShellIntegration::CreateDesktopShortcut(
-    const ShortcutInfo& shortcut_info,
+bool CreateDesktopShortcut(
+    const ShellIntegration::ShortcutInfo& shortcut_info,
     const std::string& shortcut_template) {
   DCHECK(!shortcut_info.is_platform_app);
   DCHECK(shortcut_info.extension_id.empty());
@@ -601,24 +598,22 @@
       shortcut_info, FilePath(), shortcut_template);
 }
 
-namespace ShellIntegrationLinux {
-
 bool CreateDesktopShortcutForChromeApp(
     const ShellIntegration::ShortcutInfo& shortcut_info,
     const FilePath& web_app_path,
     const std::string& shortcut_template) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
 
-  FilePath shortcut_filename = ShellIntegration::GetDesktopShortcutFilename(
-      shortcut_info.url);
+  FilePath shortcut_filename =
+      ShellIntegrationLinux::GetDesktopShortcutFilename(shortcut_info.url);
   if (shortcut_filename.empty())
     return false;
 
-  std::string icon_name = CreateShortcutIcon(shortcut_info, shortcut_filename);
+  std::string icon_name =CreateShortcutIcon(shortcut_info, shortcut_filename);
 
   std::string app_name =
       web_app::GenerateApplicationNameFromInfo(shortcut_info);
-  std::string contents = ShellIntegration::GetDesktopFileContents(
+  std::string contents = ShellIntegrationLinux::GetDesktopFileContents(
       shortcut_template,
       app_name,
       shortcut_info.url,
diff --git a/chrome/browser/shell_integration_linux.h b/chrome/browser/shell_integration_linux.h
index 2e839a5..c3a3a59 100644
--- a/chrome/browser/shell_integration_linux.h
+++ b/chrome/browser/shell_integration_linux.h
@@ -11,9 +11,39 @@
 #include "base/basictypes.h"
 #include "base/file_path.h"
 #include "chrome/browser/shell_integration.h"
+#include "googleurl/src/gurl.h"
+
+namespace base {
+class Environment;
+}
 
 namespace ShellIntegrationLinux {
 
+// Returns filename of the desktop shortcut used to launch the browser.
+std::string GetDesktopName(base::Environment* env);
+
+bool GetDesktopShortcutTemplate(base::Environment* env,
+                                std::string* output);
+
+// Returns filename for .desktop file based on |url|, sanitized for security.
+FilePath GetDesktopShortcutFilename(const GURL& url);
+
+// Returns contents for .desktop file based on |template_contents|, |url|
+// and |title|. The |template_contents| should be contents of .desktop file
+// used to launch Chrome.
+std::string GetDesktopFileContents(const std::string& template_contents,
+                                   const std::string& app_name,
+                                   const GURL& url,
+                                   const std::string& extension_id,
+                                   const bool is_platform_app,
+                                   const FilePath& web_app_path,
+                                   const FilePath& extension_path,
+                                   const string16& title,
+                                   const std::string& icon_name);
+
+bool CreateDesktopShortcut(const ShellIntegration::ShortcutInfo& shortcut_info,
+                           const std::string& shortcut_template);
+
 bool CreateDesktopShortcutForChromeApp(
     const ShellIntegration::ShortcutInfo& shortcut_info,
     const FilePath& web_app_path,
diff --git a/chrome/browser/shell_integration_unittest.cc b/chrome/browser/shell_integration_unittest.cc
index b0264314..51f9183c 100644
--- a/chrome/browser/shell_integration_unittest.cc
+++ b/chrome/browser/shell_integration_unittest.cc
@@ -24,6 +24,7 @@
 #include "chrome/installer/util/browser_distribution.h"
 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
 #include "base/environment.h"
+#include "chrome/browser/shell_integration_linux.h"
 #endif
 
 #define FPL FILE_PATH_LITERAL
@@ -92,8 +93,8 @@
         temp_dir.path().AppendASCII(kTemplateFilename),
         kTestData1, strlen(kTestData1)));
     std::string contents;
-    ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env,
-                                                             &contents));
+    ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
+                                                                  &contents));
     EXPECT_EQ(kTestData1, contents);
   }
 
@@ -110,8 +111,8 @@
             .AppendASCII(kTemplateFilename),
         kTestData2, strlen(kTestData2)));
     std::string contents;
-    ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env,
-                                                             &contents));
+    ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
+                                                                  &contents));
     EXPECT_EQ(kTestData2, contents);
   }
 
@@ -132,8 +133,8 @@
             .AppendASCII(kTemplateFilename),
         kTestData2, strlen(kTestData2)));
     std::string contents;
-    ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env,
-                                                             &contents));
+    ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
+                                                                  &contents));
     EXPECT_EQ(kTestData1, contents);
   }
 }
@@ -155,7 +156,7 @@
   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) {
     EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" +
               test_cases[i].path,
-              ShellIntegration::GetDesktopShortcutFilename(
+              ShellIntegrationLinux::GetDesktopShortcutFilename(
                   GURL(test_cases[i].url)).value()) <<
         " while testing " << test_cases[i].url;
   }
@@ -352,7 +353,7 @@
     SCOPED_TRACE(i);
     EXPECT_EQ(
         test_cases[i].expected_output,
-        ShellIntegration::GetDesktopFileContents(
+        ShellIntegrationLinux::GetDesktopFileContents(
             test_cases[i].template_contents,
             web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)),
             GURL(test_cases[i].url),
diff --git a/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc b/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc
index 0955b8a7..1ae913b 100644
--- a/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc
+++ b/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc
@@ -11,6 +11,7 @@
 #include "base/utf_string_conversions.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/shell_integration.h"
+#include "chrome/browser/shell_integration_linux.h"
 #include "chrome/browser/ui/gtk/gtk_util.h"
 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
 #include "chrome/browser/ui/web_applications/web_app_ui.h"
@@ -219,10 +220,10 @@
   scoped_ptr<base::Environment> env(base::Environment::Create());
 
   std::string shortcut_template;
-  if (ShellIntegration::GetDesktopShortcutTemplate(env.get(),
-                                                   &shortcut_template)) {
-    ShellIntegration::CreateDesktopShortcut(shortcut_info,
-                                            shortcut_template);
+  if (ShellIntegrationLinux::GetDesktopShortcutTemplate(env.get(),
+                                                        &shortcut_template)) {
+    ShellIntegrationLinux::CreateDesktopShortcut(shortcut_info,
+                                                 shortcut_template);
     Release();
   } else {
     BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
diff --git a/chrome/browser/ui/gtk/unity_service.cc b/chrome/browser/ui/gtk/unity_service.cc
index 7adc936..79f8de2f 100644
--- a/chrome/browser/ui/gtk/unity_service.cc
+++ b/chrome/browser/ui/gtk/unity_service.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
 
@@ -9,7 +9,7 @@
 
 #include "base/environment.h"
 #include "base/memory/scoped_ptr.h"
-#include "chrome/browser/shell_integration.h"
+#include "chrome/browser/shell_integration_linux.h"
 
 // Unity data typedefs.
 typedef struct _UnityInspector UnityInspector;
@@ -77,7 +77,7 @@
           dlsym(unity_lib, "unity_launcher_entry_get_for_desktop_id"));
   if (entry_get_for_desktop_id) {
     scoped_ptr<base::Environment> env(base::Environment::Create());
-    std::string desktop_id = ShellIntegration::GetDesktopName(env.get());
+    std::string desktop_id = ShellIntegrationLinux::GetDesktopName(env.get());
     chrome_entry = entry_get_for_desktop_id(desktop_id.c_str());
 
     entry_set_count =
diff --git a/chrome/browser/web_applications/web_app_linux.cc b/chrome/browser/web_applications/web_app_linux.cc
index 4bfb301a..85efd432 100644
--- a/chrome/browser/web_applications/web_app_linux.cc
+++ b/chrome/browser/web_applications/web_app_linux.cc
@@ -21,8 +21,8 @@
   scoped_ptr<base::Environment> env(base::Environment::Create());
 
   std::string shortcut_template;
-  if (!ShellIntegration::GetDesktopShortcutTemplate(env.get(),
-                                                    &shortcut_template)) {
+  if (!ShellIntegrationLinux::GetDesktopShortcutTemplate(env.get(),
+                                                         &shortcut_template)) {
     return false;
   }
   return ShellIntegrationLinux::CreateDesktopShortcutForChromeApp(