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_frame_operations.h"
      6 
      7 #include "base/command_line.h"
      8 #include "base/files/file_path.h"
      9 #include "base/logging.h"
     10 #include "chrome/installer/util/channel_info.h"
     11 #include "chrome/installer/util/helper.h"
     12 #include "chrome/installer/util/master_preferences.h"
     13 #include "chrome/installer/util/master_preferences_constants.h"
     14 #include "chrome/installer/util/util_constants.h"
     15 
     16 namespace installer {
     17 
     18 // Remove ready-mode if not multi-install.
     19 void ChromeFrameOperations::NormalizeOptions(
     20     std::set<string16>* options) const {
     21   std::set<string16>::iterator ready_mode(options->find(kOptionReadyMode));
     22   if (ready_mode != options->end() &&
     23       options->find(kOptionMultiInstall) == options->end()) {
     24     LOG(WARNING) << "--ready-mode option does not apply when --multi-install "
     25                     "is not also specified; ignoring.";
     26     options->erase(ready_mode);
     27   }
     28 }
     29 
     30 void ChromeFrameOperations::ReadOptions(const MasterPreferences& prefs,
     31                                         std::set<string16>* options) const {
     32   DCHECK(options);
     33 
     34   static const struct PrefToOption {
     35     const char* pref_name;
     36     const wchar_t* option_name;
     37   } map[] = {
     38     { master_preferences::kChromeFrameReadyMode, kOptionReadyMode },
     39     { master_preferences::kMultiInstall, kOptionMultiInstall }
     40   };
     41 
     42   bool pref_value;
     43 
     44   for (const PrefToOption* scan = &map[0], *end = &map[arraysize(map)];
     45        scan != end; ++scan) {
     46     if (prefs.GetBool(scan->pref_name, &pref_value) && pref_value)
     47       options->insert(scan->option_name);
     48   }
     49 
     50   NormalizeOptions(options);
     51 }
     52 
     53 void ChromeFrameOperations::ReadOptions(const CommandLine& uninstall_command,
     54                                         std::set<string16>* options) const {
     55   DCHECK(options);
     56 
     57   static const struct FlagToOption {
     58     const char* flag_name;
     59     const wchar_t* option_name;
     60   } map[] = {
     61     { switches::kChromeFrameReadyMode, kOptionReadyMode },
     62     { switches::kMultiInstall, kOptionMultiInstall }
     63   };
     64 
     65   for (const FlagToOption* scan = &map[0], *end = &map[arraysize(map)];
     66        scan != end; ++scan) {
     67     if (uninstall_command.HasSwitch(scan->flag_name))
     68       options->insert(scan->option_name);
     69   }
     70 
     71   NormalizeOptions(options);
     72 }
     73 
     74 void ChromeFrameOperations::AddKeyFiles(
     75     const std::set<string16>& options,
     76     std::vector<base::FilePath>* key_files) const {
     77   DCHECK(key_files);
     78   key_files->push_back(base::FilePath(installer::kChromeFrameDll));
     79   key_files->push_back(base::FilePath(installer::kChromeFrameHelperExe));
     80 }
     81 
     82 void ChromeFrameOperations::AddComDllList(
     83     const std::set<string16>& options,
     84     std::vector<base::FilePath>* com_dll_list) const {
     85   DCHECK(com_dll_list);
     86   com_dll_list->push_back(base::FilePath(installer::kChromeFrameDll));
     87 }
     88 
     89 void ChromeFrameOperations::AppendProductFlags(
     90     const std::set<string16>& options,
     91     CommandLine* cmd_line) const {
     92   DCHECK(cmd_line);
     93   bool is_multi_install = options.find(kOptionMultiInstall) != options.end();
     94 
     95   // Add --multi-install if it isn't already there.
     96   if (is_multi_install && !cmd_line->HasSwitch(switches::kMultiInstall))
     97     cmd_line->AppendSwitch(switches::kMultiInstall);
     98 
     99   // --chrome-frame is always needed.
    100   cmd_line->AppendSwitch(switches::kChromeFrame);
    101 
    102   // ready-mode is only supported in multi-installs of Chrome Frame.
    103   if (is_multi_install && options.find(kOptionReadyMode) != options.end())
    104     cmd_line->AppendSwitch(switches::kChromeFrameReadyMode);
    105 }
    106 
    107 void ChromeFrameOperations::AppendRenameFlags(const std::set<string16>& options,
    108                                               CommandLine* cmd_line) const {
    109   DCHECK(cmd_line);
    110   bool is_multi_install = options.find(kOptionMultiInstall) != options.end();
    111 
    112   // Add --multi-install if it isn't already there.
    113   if (is_multi_install && !cmd_line->HasSwitch(switches::kMultiInstall))
    114     cmd_line->AppendSwitch(switches::kMultiInstall);
    115 
    116   // --chrome-frame is needed for single installs.
    117   if (!is_multi_install)
    118     cmd_line->AppendSwitch(switches::kChromeFrame);
    119 }
    120 
    121 bool ChromeFrameOperations::SetChannelFlags(const std::set<string16>& options,
    122                                             bool set,
    123                                             ChannelInfo* channel_info) const {
    124 #if defined(GOOGLE_CHROME_BUILD)
    125   DCHECK(channel_info);
    126   bool modified = channel_info->SetChromeFrame(set);
    127 
    128   // Always remove the options if we're called to remove flags or if the
    129   // corresponding option isn't set.
    130   modified |= channel_info->SetReadyMode(
    131       set && options.find(kOptionReadyMode) != options.end());
    132 
    133   return modified;
    134 #else
    135   return false;
    136 #endif
    137 }
    138 
    139 bool ChromeFrameOperations::ShouldCreateUninstallEntry(
    140     const std::set<string16>& options) const {
    141   return options.find(kOptionReadyMode) == options.end();
    142 }
    143 
    144 void ChromeFrameOperations::AddDefaultShortcutProperties(
    145     BrowserDistribution* dist,
    146     const base::FilePath& target_exe,
    147     ShellUtil::ShortcutProperties* properties) const {
    148   NOTREACHED() << "Chrome Frame does not create shortcuts.";
    149 }
    150 
    151 void ChromeFrameOperations::LaunchUserExperiment(
    152     const base::FilePath& setup_path,
    153     const std::set<string16>& options,
    154     InstallStatus status,
    155     bool system_level) const {
    156   // No experiments yet.  If adding some in the future, need to have
    157   // ChromeFrameDistribution::HasUserExperiments() return true.
    158   NOTREACHED();
    159 }
    160 
    161 }  // namespace installer
    162