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