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.
5 #ifndef CHROME_INSTALLER_UTIL_INSTALLATION_STATE_H_
6 #define CHROME_INSTALLER_UTIL_INSTALLATION_STATE_H_
10 #include "base/basictypes.h"
11 #include "base/command_line.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/installer/util/app_commands.h"
15 #include "chrome/installer/util/browser_distribution.h"
16 #include "chrome/installer/util/channel_info.h"
27 class InstallationState
;
29 // A representation of a product's state on the machine based on the contents
30 // of the Windows registry.
31 // TODO(grt): Pull this out into its own file.
37 // Returns true if the product is installed (i.e., the product's Clients key
38 // exists and has a "pv" value); false otherwise.
39 bool Initialize(bool system_install
,
40 BrowserDistribution::Type type
);
41 bool Initialize(bool system_install
,
42 BrowserDistribution
* distribution
);
44 // Returns the product's channel info (i.e., the Google Update "ap" value).
45 const ChannelInfo
& channel() const { return channel_
; }
47 // Returns the path to the product's "setup.exe"; may be empty.
48 base::FilePath
GetSetupPath() const;
50 // Returns the product's version. This method may only be called on an
51 // instance that has been initialized for an installed product.
52 const base::Version
& version() const;
54 // Returns the current version of the product if a new version is awaiting
55 // update; may be NULL. Ownership of a returned value is not passed to the
57 const base::Version
* old_version() const { return old_version_
.get(); }
59 // Returns the brand code the product is currently installed with.
60 const std::wstring
& brand() const { return brand_
; }
62 // Returns the command to be used to update to the new version that is
63 // awaiting update; may be empty.
64 const std::wstring
& rename_cmd() const { return rename_cmd_
; }
66 // Returns true and populates |eula_accepted| if the product has such a value;
67 // otherwise, returns false and does not modify |eula_accepted|. Expected
68 // values are 0 (false) and 1 (true), although |eula_accepted| is given
70 bool GetEulaAccepted(DWORD
* eula_accepted
) const;
72 // Returns true and populates |oem_install| if the product has such a value;
73 // otherwise, returns false and does not modify |oem_install|. Expected
74 // value is "1", although |oem_install| is given whatever is found.
75 bool GetOemInstall(std::wstring
* oem_install
) const;
77 // Returns true and populates |usagestats| if the product has such a value;
78 // otherwise, returns false and does not modify |usagestats|. Expected values
79 // are 0 (false) and 1 (true), although |usagestats| is given whatever is
81 bool GetUsageStats(DWORD
* usagestats
) const;
83 // True if the "msi" value in the ClientState key is present and non-zero.
84 bool is_msi() const { return msi_
; }
86 // The command to uninstall the product; may be empty.
87 const base::CommandLine
& uninstall_command() const {
88 return uninstall_command_
;
91 // True if |uninstall_command| contains --multi-install.
92 bool is_multi_install() const { return multi_install_
; }
94 // Returns the set of Google Update commands.
95 const AppCommands
& commands() const { return commands_
; }
97 // Returns this object a la operator=().
98 ProductState
& CopyFrom(const ProductState
& other
);
100 // Clears the state of this object.
104 static bool InitializeCommands(const base::win::RegKey
& version_key
,
105 AppCommands
* commands
);
107 ChannelInfo channel_
;
108 scoped_ptr
<Version
> version_
;
109 scoped_ptr
<Version
> old_version_
;
111 std::wstring rename_cmd_
;
112 std::wstring oem_install_
;
113 base::CommandLine uninstall_command_
;
114 AppCommands commands_
;
115 DWORD eula_accepted_
;
118 bool multi_install_
: 1;
119 bool has_eula_accepted_
: 1;
120 bool has_oem_install_
: 1;
121 bool has_usagestats_
: 1;
124 friend class InstallationState
;
126 DISALLOW_COPY_AND_ASSIGN(ProductState
);
127 }; // class ProductState
129 // Encapsulates the state of all products on the system.
130 // TODO(grt): Rename this to MachineState and put it in its own file.
131 class InstallationState
{
135 // Initializes this object with the machine's current state.
138 // Returns the state of a product or NULL if not installed.
139 // Caller does NOT assume ownership of returned pointer.
140 const ProductState
* GetProductState(bool system_install
,
141 BrowserDistribution::Type type
) const;
143 // Returns the state of a product, even one that has not yet been installed.
144 // This is useful during first install, when some but not all ProductState
145 // information has been written by Omaha. Notably absent from the
146 // ProductState returned here are the version numbers. Do NOT try to access
147 // the version numbers from a ProductState returned by this method.
148 // Caller does NOT assume ownership of returned pointer. This method will
149 // never return NULL.
150 const ProductState
* GetNonVersionedProductState(
151 bool system_install
, BrowserDistribution::Type type
) const;
155 CHROME_BROWSER_INDEX
,
157 CHROME_BINARIES_INDEX
,
161 static int IndexFromDistType(BrowserDistribution::Type type
);
163 ProductState user_products_
[NUM_PRODUCTS
];
164 ProductState system_products_
[NUM_PRODUCTS
];
167 DISALLOW_COPY_AND_ASSIGN(InstallationState
);
168 }; // class InstallationState
170 } // namespace installer
172 #endif // CHROME_INSTALLER_UTIL_INSTALLATION_STATE_H_