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#ifndef CHROME_INSTALLER_UTIL_PRODUCT_H_ 6#define CHROME_INSTALLER_UTIL_PRODUCT_H_ 7 8#include <set> 9#include <string> 10#include <vector> 11 12#include "base/memory/scoped_ptr.h" 13#include "chrome/installer/util/browser_distribution.h" 14#include "chrome/installer/util/shell_util.h" 15#include "chrome/installer/util/util_constants.h" 16 17namespace base { 18class CommandLine; 19} 20 21namespace installer { 22 23class ChannelInfo; 24class MasterPreferences; 25class Product; 26class ProductOperations; 27 28// Represents an installation of a specific product which has a one-to-one 29// relation to a BrowserDistribution. A product has registry settings, related 30// installation/uninstallation actions and exactly one Package that represents 31// the files on disk. The Package may be shared with other Product instances, 32// so only the last Product to be uninstalled should remove the package. 33// Right now there are no classes that derive from Product, but in 34// the future, as we move away from global functions and towards a data driven 35// installation, each distribution could derive from this class and provide 36// distribution specific functionality. 37class Product { 38 public: 39 explicit Product(BrowserDistribution* distribution); 40 41 ~Product(); 42 43 void InitializeFromPreferences(const MasterPreferences& prefs); 44 45 void InitializeFromUninstallCommand( 46 const base::CommandLine& uninstall_command); 47 48 BrowserDistribution* distribution() const { 49 return distribution_; 50 } 51 52 bool is_type(BrowserDistribution::Type type) const { 53 return distribution_->GetType() == type; 54 } 55 56 bool is_chrome() const { 57 return distribution_->GetType() == BrowserDistribution::CHROME_BROWSER; 58 } 59 60 bool is_chrome_frame() const { 61 return distribution_->GetType() == BrowserDistribution::CHROME_FRAME; 62 } 63 64 bool is_chrome_app_host() const { 65 return distribution_->GetType() == BrowserDistribution::CHROME_APP_HOST; 66 } 67 68 bool is_chrome_binaries() const { 69 return distribution_->GetType() == BrowserDistribution::CHROME_BINARIES; 70 } 71 72 bool HasOption(const std::wstring& option) const { 73 return options_.find(option) != options_.end(); 74 } 75 76 // Returns true if the set of options is mutated by this operation. 77 bool SetOption(const std::wstring& option, bool set) { 78 if (set) 79 return options_.insert(option).second; 80 else 81 return options_.erase(option) != 0; 82 } 83 84 // Launches Chrome without waiting for it to exit. 85 bool LaunchChrome(const base::FilePath& application_path) const; 86 87 // Launches Chrome with given command line, waits for Chrome indefinitely 88 // (until it terminates), and gets the process exit code if available. 89 // The function returns true as long as Chrome is successfully launched. 90 // The status of Chrome at the return of the function is given by exit_code. 91 // NOTE: The 'options' CommandLine object should only contain parameters. 92 // The program part will be ignored. 93 bool LaunchChromeAndWait(const base::FilePath& application_path, 94 const base::CommandLine& options, 95 int32* exit_code) const; 96 97 // Sets the boolean MSI marker for this installation if set is true or clears 98 // it otherwise. The MSI marker is stored in the registry under the 99 // ClientState key. 100 bool SetMsiMarker(bool system_install, bool set) const; 101 102 // Returns true if setup should create an entry in the Add/Remove list 103 // of installed applications. 104 bool ShouldCreateUninstallEntry() const; 105 106 // See ProductOperations::AddKeyFiles. 107 void AddKeyFiles(std::vector<base::FilePath>* key_files) const; 108 109 // See ProductOperations::AddComDllList. 110 void AddComDllList(std::vector<base::FilePath>* com_dll_list) const; 111 112 // See ProductOperations::AppendProductFlags. 113 void AppendProductFlags(base::CommandLine* command_line) const; 114 115 // See ProductOperations::AppendRenameFlags. 116 void AppendRenameFlags(base::CommandLine* command_line) const; 117 118 // See Productoperations::SetChannelFlags. 119 bool SetChannelFlags(bool set, ChannelInfo* channel_info) const; 120 121 // See ProductOperations::AddDefaultShortcutProperties. 122 void AddDefaultShortcutProperties( 123 const base::FilePath& target_exe, 124 ShellUtil::ShortcutProperties* properties) const; 125 126 void LaunchUserExperiment(const base::FilePath& setup_path, 127 InstallStatus status, 128 bool system_level) const; 129 130 protected: 131 enum CacheStateFlags { 132 MSI_STATE = 0x01 133 }; 134 135 BrowserDistribution* distribution_; 136 scoped_ptr<ProductOperations> operations_; 137 std::set<std::wstring> options_; 138 139 private: 140 DISALLOW_COPY_AND_ASSIGN(Product); 141}; 142 143} // namespace installer 144 145#endif // CHROME_INSTALLER_UTIL_PRODUCT_H_ 146