OLD | NEW |
| (Empty) |
1 // Copyright 2005-2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // The configuration manager that is used to provide the locations of the | |
17 // directory and the registration entries that are to be used by goopdate. | |
18 | |
19 // TODO(omaha): consider removing some of the functions below and have a | |
20 // parameter is_machine instead. This is consistent with the rest of the code | |
21 // and it reduces the number of functions in the public interface. | |
22 | |
23 #ifndef OMAHA_COMMON_CONFIG_MANAGER_H_ | |
24 #define OMAHA_COMMON_CONFIG_MANAGER_H_ | |
25 | |
26 #include <windows.h> | |
27 #include <atlstr.h> | |
28 #include "base/basictypes.h" | |
29 #include "omaha/base/constants.h" | |
30 #include "omaha/base/synchronized.h" | |
31 | |
32 namespace omaha { | |
33 | |
34 class ConfigManager { | |
35 public: | |
36 const TCHAR* user_registry_clients() const { return USER_REG_CLIENTS; } | |
37 const TCHAR* user_registry_clients_goopdate() const { | |
38 return USER_REG_CLIENTS_GOOPDATE; | |
39 } | |
40 const TCHAR* user_registry_client_state() const { | |
41 return USER_REG_CLIENT_STATE; | |
42 } | |
43 const TCHAR* user_registry_client_state_goopdate() const { | |
44 return USER_REG_CLIENT_STATE_GOOPDATE; | |
45 } | |
46 const TCHAR* user_registry_update() const { return USER_REG_UPDATE; } | |
47 const TCHAR* user_registry_google() const { return USER_REG_GOOGLE; } | |
48 | |
49 const TCHAR* machine_registry_clients() const { return MACHINE_REG_CLIENTS; } | |
50 const TCHAR* machine_registry_clients_goopdate() const { | |
51 return MACHINE_REG_CLIENTS_GOOPDATE; | |
52 } | |
53 const TCHAR* machine_registry_client_state() const { | |
54 return MACHINE_REG_CLIENT_STATE; | |
55 } | |
56 const TCHAR* machine_registry_client_state_goopdate() const { | |
57 return MACHINE_REG_CLIENT_STATE_GOOPDATE; | |
58 } | |
59 const TCHAR* machine_registry_client_state_medium() const { | |
60 return MACHINE_REG_CLIENT_STATE_MEDIUM; | |
61 } | |
62 const TCHAR* machine_registry_update() const { return MACHINE_REG_UPDATE; } | |
63 const TCHAR* machine_registry_google() const { return MACHINE_REG_GOOGLE; } | |
64 | |
65 const TCHAR* registry_clients(bool is_machine) const { | |
66 return is_machine ? machine_registry_clients() : user_registry_clients(); | |
67 } | |
68 const TCHAR* registry_clients_goopdate(bool is_machine) const { | |
69 return is_machine ? machine_registry_clients_goopdate() : | |
70 user_registry_clients_goopdate(); | |
71 } | |
72 const TCHAR* registry_client_state(bool is_machine) const { | |
73 return is_machine ? machine_registry_client_state() : | |
74 user_registry_client_state(); | |
75 } | |
76 const TCHAR* registry_client_state_goopdate(bool is_machine) const { | |
77 return is_machine ? machine_registry_client_state_goopdate() : | |
78 user_registry_client_state_goopdate(); | |
79 } | |
80 const TCHAR* registry_update(bool is_machine) const { | |
81 return is_machine ? machine_registry_update() : user_registry_update(); | |
82 } | |
83 const TCHAR* registry_google(bool is_machine) const { | |
84 return is_machine ? machine_registry_google() : user_registry_google(); | |
85 } | |
86 | |
87 // Gets the temporary download dir for the current thread token: | |
88 // %UserProfile%/AppData/Local/Temp | |
89 CString GetTempDownloadDir() const; | |
90 | |
91 // Gets the total disk size limit for cached packages. When this limit is hit, | |
92 // packages should be deleted from oldest until total size is below the limit. | |
93 int GetPackageCacheSizeLimitMBytes() const; | |
94 | |
95 // Gets the package cache life limit. If a cached package is older than this | |
96 // limit, it should be removed. | |
97 int GetPackageCacheExpirationTimeDays() const; | |
98 | |
99 // Creates download data dir: | |
100 // %UserProfile%/Application Data/Google/Update/Download | |
101 // This is the root of the package cache for the user. | |
102 // TODO(omaha): consider renaming. | |
103 CString GetUserDownloadStorageDir() const; | |
104 | |
105 // Creates install data dir: | |
106 // %UserProfile%/Application Data/Google/Update/Install | |
107 // Files pending user installs are copied in this directory. | |
108 CString GetUserInstallWorkingDir() const; | |
109 | |
110 // Creates offline data dir: | |
111 // %UserProfile%/Application Data/Google/Update/Offline | |
112 CString GetUserOfflineStorageDir() const; | |
113 | |
114 // Returns goopdate install dir: | |
115 // %UserProfile%/Application Data/Google/Update | |
116 CString GetUserGoopdateInstallDirNoCreate() const; | |
117 | |
118 // Creates goopdate install dir: | |
119 // %UserProfile%/Application Data/Google/Update | |
120 CString GetUserGoopdateInstallDir() const; | |
121 | |
122 // Checks if the running program is executing from the User Goopdate dir. | |
123 bool IsRunningFromUserGoopdateInstallDir() const; | |
124 | |
125 // Creates crash reports dir: | |
126 // %UserProfile%/Local Settings/Application Data/Google/CrashReports | |
127 CString GetUserCrashReportsDir() const; | |
128 | |
129 // Creates crash reports dir: %ProgramFiles%/Google/CrashReports | |
130 CString GetMachineCrashReportsDir() const; | |
131 | |
132 // Creates machine download data dir: | |
133 // %ProgramFiles%/Google/Update/Download | |
134 // This directory is the root of the package cache for the machine. | |
135 // TODO(omaha): consider renaming. | |
136 CString GetMachineSecureDownloadStorageDir() const; | |
137 | |
138 // Creates install data dir: | |
139 // %ProgramFiles%/Google/Update/Install | |
140 // Files pending machine installs are copied in this directory. | |
141 CString GetMachineInstallWorkingDir() const; | |
142 | |
143 // Creates machine offline data dir: | |
144 // %ProgramFiles%/Google/Update/Offline | |
145 CString GetMachineSecureOfflineStorageDir() const; | |
146 | |
147 // Creates machine Gogole Update install dir: | |
148 // %ProgramFiles%/Google/Update | |
149 CString GetMachineGoopdateInstallDirNoCreate() const; | |
150 | |
151 // Creates machine Gogole Update install dir: | |
152 // %ProgramFiles%/Google/Update | |
153 CString GetMachineGoopdateInstallDir() const; | |
154 | |
155 // Checks if the running program is executing from the User Goopdate dir. | |
156 bool IsRunningFromMachineGoopdateInstallDir() const; | |
157 | |
158 // Returns the service endpoint where the install/update/uninstall pings | |
159 // are being sent. | |
160 HRESULT GetPingUrl(CString* url) const; | |
161 | |
162 // Returns the service endpoint where the update checks are sent. | |
163 HRESULT GetUpdateCheckUrl(CString* url) const; | |
164 | |
165 // Returns the service endpoint where the crashes are sent. | |
166 HRESULT GetCrashReportUrl(CString* url) const; | |
167 | |
168 // Returns the web page url where the 'Get Help' requests are sent. | |
169 HRESULT GetMoreInfoUrl(CString* url) const; | |
170 | |
171 // Returns the service endpoint where the usage stats requests are sent. | |
172 HRESULT GetUsageStatsReportUrl(CString* url) const; | |
173 | |
174 // Returns the time interval between update checks in seconds. | |
175 // 0 indicates updates are disabled. | |
176 int GetLastCheckPeriodSec(bool* is_overridden) const; | |
177 | |
178 // Returns the number of seconds since the last successful update check. | |
179 int GetTimeSinceLastCheckedSec(bool is_machine) const; | |
180 | |
181 // Gets and sets the last time a successful server update check was made. | |
182 DWORD GetLastCheckedTime(bool is_machine) const; | |
183 HRESULT SetLastCheckedTime(bool is_machine, DWORD time) const; | |
184 | |
185 // Checks registry to see if user has enabled us to collect anonymous | |
186 // usage stats. | |
187 bool CanCollectStats(bool is_machine) const; | |
188 | |
189 // Returns true if over-installing with the same version is allowed. | |
190 bool CanOverInstall() const; | |
191 | |
192 // Returns the Autoupdate timer interval. This is the frequency of the | |
193 // auto update timer run by the core. | |
194 int GetAutoUpdateTimerIntervalMs() const; | |
195 | |
196 // Returns the wait time in ms to start the first worker. | |
197 int GetUpdateWorkerStartUpDelayMs() const; | |
198 | |
199 // Returns the Code Red timer interval. This is the frequency of the | |
200 // code red timer run by the core. | |
201 int GetCodeRedTimerIntervalMs() const; | |
202 | |
203 // Returns true if event logging to the Windows Event Log is enabled. | |
204 bool CanLogEvents(WORD event_type) const; | |
205 | |
206 // Retrieves TestSource which is to be set on dev, qa, and prober machines. | |
207 CString GetTestSource() const; | |
208 | |
209 // Returns true if it is okay to do update checks and send pings. | |
210 bool CanUseNetwork(bool is_machine) const; | |
211 | |
212 // Returns true if running in Windows Audit mode (OEM install). | |
213 // USE OemInstall::IsOemInstalling() INSTEAD in most cases. | |
214 bool IsWindowsInstalling() const; | |
215 | |
216 // Returns true if the user is considered an internal user. | |
217 bool IsInternalUser() const; | |
218 | |
219 // Returns true if installation of the specified app is allowed. | |
220 bool CanInstallApp(const GUID& app_guid) const; | |
221 | |
222 // Returns true if updates are allowed for the specified app. | |
223 bool CanUpdateApp(const GUID& app_guid, bool is_manual) const; | |
224 | |
225 // Returns true if crash uploading is allowed all the time, no matter the | |
226 // build flavor or other configuration parameters. | |
227 bool AlwaysAllowCrashUploads() const; | |
228 | |
229 // Returns the network configuration override as a string. | |
230 static HRESULT GetNetConfig(CString* configuration_override); | |
231 | |
232 // Gets the time when Goopdate was last updated or installed. | |
233 static DWORD GetInstallTime(bool is_machine); | |
234 | |
235 // Returns true if it has been more than 24 hours since Goopdate was updated | |
236 // or installed. | |
237 static bool Is24HoursSinceInstall(bool is_machine); | |
238 | |
239 static ConfigManager* Instance(); | |
240 static void DeleteInstance(); | |
241 | |
242 private: | |
243 static LLock lock_; | |
244 static ConfigManager* config_manager_; | |
245 | |
246 ConfigManager(); | |
247 | |
248 bool is_running_from_official_user_dir_; | |
249 bool is_running_from_official_machine_dir_; | |
250 | |
251 DISALLOW_EVIL_CONSTRUCTORS(ConfigManager); | |
252 }; | |
253 | |
254 } // namespace omaha | |
255 | |
256 #endif // OMAHA_COMMON_CONFIG_MANAGER_H_ | |
OLD | NEW |