| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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_INSTALLATION_VALIDATOR_H_ |
| 6 #define CHROME_INSTALLER_UTIL_INSTALLATION_VALIDATOR_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <utility> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" |
| 15 #include "base/ref_counted.h" |
| 16 #include "base/scoped_ptr.h" |
| 17 #include "chrome/installer/util/browser_distribution.h" |
| 18 #include "chrome/installer/util/channel_info.h" |
| 19 |
| 20 class FilePath; |
| 21 class Version; |
| 22 |
| 23 namespace installer { |
| 24 |
| 25 class InstallationState; |
| 26 class ProductState; |
| 27 |
| 28 // A class that validates the state of an installation. Violations are logged |
| 29 // via LOG(ERROR). |
| 30 class InstallationValidator { |
| 31 public: |
| 32 class ProductBits { |
| 33 public: |
| 34 // Bits that form the components of an installation type. |
| 35 enum { |
| 36 CHROME_SINGLE = 0x01, |
| 37 CHROME_MULTI = 0x02, |
| 38 CHROME_FRAME_SINGLE = 0x04, |
| 39 CHROME_FRAME_MULTI = 0x08, |
| 40 CHROME_FRAME_READY_MODE = 0x10, |
| 41 }; |
| 42 }; // class ProductBits |
| 43 |
| 44 // Identifiers of all valid installation types. |
| 45 enum InstallationType { |
| 46 NO_PRODUCTS = 0, |
| 47 CHROME_SINGLE = |
| 48 ProductBits::CHROME_SINGLE, |
| 49 CHROME_MULTI = |
| 50 ProductBits::CHROME_MULTI, |
| 51 CHROME_FRAME_SINGLE = |
| 52 ProductBits::CHROME_FRAME_SINGLE, |
| 53 CHROME_FRAME_SINGLE_CHROME_SINGLE = |
| 54 ProductBits::CHROME_FRAME_SINGLE | ProductBits::CHROME_SINGLE, |
| 55 CHROME_FRAME_SINGLE_CHROME_MULTI = |
| 56 ProductBits::CHROME_FRAME_SINGLE | ProductBits::CHROME_MULTI, |
| 57 CHROME_FRAME_MULTI = |
| 58 ProductBits::CHROME_FRAME_MULTI, |
| 59 CHROME_FRAME_MULTI_CHROME_MULTI = |
| 60 ProductBits::CHROME_FRAME_MULTI | ProductBits::CHROME_MULTI, |
| 61 CHROME_FRAME_READY_MODE_CHROME_MULTI = |
| 62 ProductBits::CHROME_FRAME_READY_MODE | ProductBits::CHROME_MULTI, |
| 63 }; |
| 64 |
| 65 // Validates |machine_state| at user or system level, returning true if valid. |
| 66 // |type| is populated in either case, although it is a best-guess when the |
| 67 // method returns false. |
| 68 static bool ValidateInstallationTypeForState( |
| 69 const InstallationState& machine_state, |
| 70 bool system_level, |
| 71 InstallationType* type); |
| 72 |
| 73 // Validates the machine's current installation at user or system level, |
| 74 // returning true and populating |type| if valid. |
| 75 static bool ValidateInstallationType(bool system_level, |
| 76 InstallationType* type); |
| 77 |
| 78 protected: |
| 79 typedef std::vector<std::pair<std::string, bool> > SwitchExpectations; |
| 80 |
| 81 // An interface to product-specific validation rules. |
| 82 class ProductRules { |
| 83 public: |
| 84 virtual ~ProductRules() { } |
| 85 virtual BrowserDistribution::Type distribution_type() const = 0; |
| 86 virtual void AddUninstallSwitchExpectations( |
| 87 const InstallationState& machine_state, |
| 88 bool system_install, |
| 89 const ProductState& product_state, |
| 90 SwitchExpectations* expectations) const = 0; |
| 91 }; |
| 92 |
| 93 // Validation rules for the Chrome browser. |
| 94 class ChromeRules : public ProductRules { |
| 95 public: |
| 96 virtual BrowserDistribution::Type distribution_type() const OVERRIDE; |
| 97 virtual void AddUninstallSwitchExpectations( |
| 98 const InstallationState& machine_state, |
| 99 bool system_install, |
| 100 const ProductState& product_state, |
| 101 SwitchExpectations* expectations) const OVERRIDE; |
| 102 }; |
| 103 |
| 104 // Validation rules for Chrome Frame. |
| 105 class ChromeFrameRules : public ProductRules { |
| 106 public: |
| 107 virtual BrowserDistribution::Type distribution_type() const OVERRIDE; |
| 108 virtual void AddUninstallSwitchExpectations( |
| 109 const InstallationState& machine_state, |
| 110 bool system_install, |
| 111 const ProductState& product_state, |
| 112 SwitchExpectations* expectations) const OVERRIDE; |
| 113 }; |
| 114 |
| 115 struct ProductContext { |
| 116 const InstallationState& machine_state; |
| 117 bool system_install; |
| 118 BrowserDistribution* dist; |
| 119 const ProductState& state; |
| 120 const ProductRules& rules; |
| 121 }; |
| 122 |
| 123 static void ValidateBinaries(const InstallationState& machine_state, |
| 124 bool system_install, |
| 125 const ProductState& binaries_state, |
| 126 bool* is_valid); |
| 127 static void ValidateSetupPath(const ProductContext& ctx, |
| 128 const FilePath& setup_exe, |
| 129 const char* purpose, |
| 130 bool* is_valid); |
| 131 static void ValidateCommandExpectations(const ProductContext& ctx, |
| 132 const CommandLine& command, |
| 133 const SwitchExpectations& expected, |
| 134 const char* source, |
| 135 bool* is_valid); |
| 136 static void ValidateUninstallCommand(const ProductContext& ctx, |
| 137 const CommandLine& command, |
| 138 const char* source, |
| 139 bool* is_valid); |
| 140 static void ValidateRenameCommand(const ProductContext& ctx, |
| 141 bool* is_valid); |
| 142 static void ValidateOldVersionValues(const ProductContext& ctx, |
| 143 bool* is_valid); |
| 144 static void ValidateMultiInstallProduct(const ProductContext& ctx, |
| 145 bool* is_valid); |
| 146 static void ValidateProduct(const InstallationState& machine_state, |
| 147 bool system_install, |
| 148 const ProductState& product_state, |
| 149 const ProductRules& rules, |
| 150 bool* is_valid); |
| 151 |
| 152 // A collection of all valid installation types. |
| 153 static const InstallationType kInstallationTypes[]; |
| 154 |
| 155 private: |
| 156 DISALLOW_IMPLICIT_CONSTRUCTORS(InstallationValidator); |
| 157 }; |
| 158 |
| 159 } // namespace installer |
| 160 |
| 161 #endif // CHROME_INSTALLER_UTIL_INSTALLATION_VALIDATOR_H_ |
| OLD | NEW |