Home | History | Annotate | Download | only in util
      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 "chrome/installer/util/chrome_app_host_operations.h"
      6 
      7 #include "base/command_line.h"
      8 #include "base/files/file_path.h"
      9 #include "base/logging.h"
     10 #include "chrome/common/chrome_switches.h"
     11 #include "chrome/installer/util/browser_distribution.h"
     12 #include "chrome/installer/util/channel_info.h"
     13 #include "chrome/installer/util/helper.h"
     14 #include "chrome/installer/util/master_preferences.h"
     15 #include "chrome/installer/util/master_preferences_constants.h"
     16 #include "chrome/installer/util/shell_util.h"
     17 #include "chrome/installer/util/util_constants.h"
     18 
     19 namespace installer {
     20 
     21 void ChromeAppHostOperations::ReadOptions(const MasterPreferences& prefs,
     22                                           std::set<base::string16>* options)
     23     const {
     24   DCHECK(options);
     25 
     26   bool pref_value;
     27   if (prefs.GetBool(master_preferences::kMultiInstall, &pref_value) &&
     28       pref_value) {
     29     options->insert(kOptionMultiInstall);
     30   }
     31 }
     32 
     33 void ChromeAppHostOperations::ReadOptions(const CommandLine& uninstall_command,
     34                                           std::set<base::string16>* options)
     35     const {
     36   DCHECK(options);
     37 
     38   if (uninstall_command.HasSwitch(switches::kMultiInstall))
     39     options->insert(kOptionMultiInstall);
     40 }
     41 
     42 void ChromeAppHostOperations::AddKeyFiles(
     43     const std::set<base::string16>& options,
     44     std::vector<base::FilePath>* key_files) const {
     45 }
     46 
     47 void ChromeAppHostOperations::AddComDllList(
     48     const std::set<base::string16>& options,
     49     std::vector<base::FilePath>* com_dll_list) const {
     50 }
     51 
     52 void ChromeAppHostOperations::AppendProductFlags(
     53     const std::set<base::string16>& options,
     54     CommandLine* cmd_line) const {
     55   DCHECK(cmd_line);
     56   bool is_multi_install = options.find(kOptionMultiInstall) != options.end();
     57 
     58   // Non-multi-install not supported for the app host.
     59   DCHECK(is_multi_install);
     60 
     61   // Add --multi-install if it isn't already there.
     62   if (is_multi_install && !cmd_line->HasSwitch(switches::kMultiInstall))
     63     cmd_line->AppendSwitch(switches::kMultiInstall);
     64 
     65   // Add --app-launcher.
     66   cmd_line->AppendSwitch(switches::kChromeAppLauncher);
     67 }
     68 
     69 void ChromeAppHostOperations::AppendRenameFlags(
     70     const std::set<base::string16>& options,
     71     CommandLine* cmd_line) const {
     72   DCHECK(cmd_line);
     73   bool is_multi_install = options.find(kOptionMultiInstall) != options.end();
     74 
     75   // Non-multi-install not supported for the app host.
     76   DCHECK(is_multi_install);
     77 
     78   // Add --multi-install if it isn't already there.
     79   if (is_multi_install && !cmd_line->HasSwitch(switches::kMultiInstall))
     80     cmd_line->AppendSwitch(switches::kMultiInstall);
     81 }
     82 
     83 bool ChromeAppHostOperations::SetChannelFlags(
     84     const std::set<base::string16>& options,
     85     bool set,
     86     ChannelInfo* channel_info) const {
     87 #if defined(GOOGLE_CHROME_BUILD)
     88   DCHECK(channel_info);
     89   return channel_info->SetAppLauncher(set);
     90 #else
     91   return false;
     92 #endif
     93 }
     94 
     95 bool ChromeAppHostOperations::ShouldCreateUninstallEntry(
     96     const std::set<base::string16>& options) const {
     97   return true;
     98 }
     99 
    100 void ChromeAppHostOperations::AddDefaultShortcutProperties(
    101     BrowserDistribution* dist,
    102     const base::FilePath& target_exe,
    103     ShellUtil::ShortcutProperties* properties) const {
    104   if (!properties->has_target())
    105     properties->set_target(target_exe);
    106 
    107   if (!properties->has_arguments()) {
    108     CommandLine app_host_args(CommandLine::NO_PROGRAM);
    109     app_host_args.AppendSwitch(::switches::kShowAppList);
    110     properties->set_arguments(app_host_args.GetCommandLineString());
    111   }
    112 
    113   if (!properties->has_icon())
    114     properties->set_icon(target_exe,
    115         dist->GetIconIndex(BrowserDistribution::SHORTCUT_APP_LAUNCHER));
    116 
    117   if (!properties->has_app_id()) {
    118     std::vector<base::string16> components;
    119     components.push_back(dist->GetBaseAppId());
    120     properties->set_app_id(ShellUtil::BuildAppModelId(components));
    121   }
    122 }
    123 
    124 void ChromeAppHostOperations::LaunchUserExperiment(
    125     const base::FilePath& setup_path,
    126     const std::set<base::string16>& options,
    127     InstallStatus status,
    128     bool system_level) const {
    129   // No experiments yet.  If adding some in the future, need to have
    130   // ChromeAppHostDistribution::HasUserExperiments() return true.
    131   NOTREACHED();
    132 }
    133 
    134 }  // namespace installer
    135