product.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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 // Returns the path(s) to the directory that holds the user data (primary 85 // and, if applicable to |dist|, alternate). This is always inside a user's 86 // local application data folder (e.g., "AppData\Local or "Local 87 // Settings\Application Data" in %USERPROFILE%). Note that these are the 88 // defaults and do not take into account that they can be overriden with a 89 // command line parameter. |paths| may be empty on return, but is guaranteed 90 // not to contain empty paths otherwise. If more than one path is returned, 91 // they are guaranteed to be siblings. 92 void GetUserDataPaths(std::vector<base::FilePath>* paths) const; 93 94 // Launches Chrome without waiting for it to exit. 95 bool LaunchChrome(const base::FilePath& application_path) const; 96 97 // Launches Chrome with given command line, waits for Chrome indefinitely 98 // (until it terminates), and gets the process exit code if available. 99 // The function returns true as long as Chrome is successfully launched. 100 // The status of Chrome at the return of the function is given by exit_code. 101 // NOTE: The 'options' CommandLine object should only contain parameters. 102 // The program part will be ignored. 103 bool LaunchChromeAndWait(const base::FilePath& application_path, 104 const base::CommandLine& options, 105 int32* exit_code) const; 106 107 // Sets the boolean MSI marker for this installation if set is true or clears 108 // it otherwise. The MSI marker is stored in the registry under the 109 // ClientState key. 110 bool SetMsiMarker(bool system_install, bool set) const; 111 112 // Returns true if setup should create an entry in the Add/Remove list 113 // of installed applications. 114 bool ShouldCreateUninstallEntry() const; 115 116 // See ProductOperations::AddKeyFiles. 117 void AddKeyFiles(std::vector<base::FilePath>* key_files) const; 118 119 // See ProductOperations::AddComDllList. 120 void AddComDllList(std::vector<base::FilePath>* com_dll_list) const; 121 122 // See ProductOperations::AppendProductFlags. 123 void AppendProductFlags(base::CommandLine* command_line) const; 124 125 // See ProductOperations::AppendRenameFlags. 126 void AppendRenameFlags(base::CommandLine* command_line) const; 127 128 // See Productoperations::SetChannelFlags. 129 bool SetChannelFlags(bool set, ChannelInfo* channel_info) const; 130 131 // See ProductOperations::AddDefaultShortcutProperties. 132 void AddDefaultShortcutProperties( 133 const base::FilePath& target_exe, 134 ShellUtil::ShortcutProperties* properties) const; 135 136 void LaunchUserExperiment(const base::FilePath& setup_path, 137 InstallStatus status, 138 bool system_level) const; 139 140 protected: 141 enum CacheStateFlags { 142 MSI_STATE = 0x01 143 }; 144 145 BrowserDistribution* distribution_; 146 scoped_ptr<ProductOperations> operations_; 147 std::set<std::wstring> options_; 148 149 private: 150 DISALLOW_COPY_AND_ASSIGN(Product); 151}; 152 153} // namespace installer 154 155#endif // CHROME_INSTALLER_UTIL_PRODUCT_H_ 156