OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 #include "chrome/installer/util/user_experiment.h" | |
6 | |
7 #include <sddl.h> | |
8 #include <wtsapi32.h> | |
9 #include <vector> | |
10 | |
11 #include "base/command_line.h" | |
12 #include "base/file_path.h" | |
13 #include "base/process_util.h" | |
14 #include "base/rand_util.h" | |
15 #include "base/string_split.h" | |
16 #include "base/string_util.h" | |
17 #include "base/strings/string_number_conversions.h" | |
18 #include "base/utf_string_conversions.h" | |
19 #include "base/version.h" | |
20 #include "base/win/windows_version.h" | |
21 #include "chrome/common/attrition_experiments.h" | |
22 #include "chrome/common/chrome_result_codes.h" | |
23 #include "chrome/common/chrome_switches.h" | |
24 #include "chrome/installer/util/browser_distribution.h" | |
25 #include "chrome/installer/util/google_update_constants.h" | |
26 #include "chrome/installer/util/google_update_settings.h" | |
27 #include "chrome/installer/util/install_util.h" | |
28 #include "chrome/installer/util/product.h" | |
29 #include "content/public/common/result_codes.h" | |
30 | |
31 #pragma comment(lib, "wtsapi32.lib") | |
32 | |
33 namespace installer { | |
34 | |
35 namespace { | |
36 | |
37 const wchar_t kChromeGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | |
grt (UTC plus 2)
2013/02/22 16:47:56
this and the next three constants appear to be unu
huangs
2013/02/22 20:32:37
Yes, missed a spot. Deleted.
| |
38 const wchar_t kBrowserAppId[] = L"Chrome"; | |
39 const wchar_t kCommandExecuteImplUuid[] = | |
40 L"{5C65F4B0-3651-4514-B207-D10CB699B14B}"; | |
41 | |
42 // The following strings are the possible outcomes of the toast experiment | |
43 // as recorded in the |client| field. | |
44 const wchar_t kToastExpControlGroup[] = L"01"; | |
45 const wchar_t kToastExpCancelGroup[] = L"02"; | |
46 const wchar_t kToastExpUninstallGroup[] = L"04"; | |
47 const wchar_t kToastExpTriesOkGroup[] = L"18"; | |
48 const wchar_t kToastExpTriesErrorGroup[] = L"28"; | |
49 const wchar_t kToastActiveGroup[] = L"40"; | |
50 const wchar_t kToastUDDirFailure[] = L"40"; | |
51 const wchar_t kToastExpBaseGroup[] = L"80"; | |
52 | |
53 // Substitute the locale parameter in uninstall URL with whatever | |
54 // Google Update tells us is the locale. In case we fail to find | |
55 // the locale, we use US English. | |
56 string16 LocalizeUrl(const wchar_t* url) { | |
57 string16 language; | |
58 if (!GoogleUpdateSettings::GetLanguage(&language)) | |
59 language = L"en-US"; // Default to US English. | |
60 return ReplaceStringPlaceholders(url, language.c_str(), NULL); | |
61 } | |
62 | |
63 string16 GetWelcomeBackUrl() { | |
64 const wchar_t kWelcomeUrl[] = L"http://www.google.com/chrome/intl/$1/" | |
65 L"welcomeback-new.html"; | |
66 return LocalizeUrl(kWelcomeUrl); | |
67 } | |
68 | |
69 // Converts FILETIME to hours. FILETIME times are absolute times in | |
70 // 100 nanosecond units. For example 5:30 pm of June 15, 2009 is 3580464. | |
71 int FileTimeToHours(const FILETIME& time) { | |
72 const ULONGLONG k100sNanoSecsToHours = 10000000LL * 60 * 60; | |
73 ULARGE_INTEGER uli = {time.dwLowDateTime, time.dwHighDateTime}; | |
74 return static_cast<int>(uli.QuadPart / k100sNanoSecsToHours); | |
75 } | |
76 | |
77 // Returns the directory last write time in hours since January 1, 1601. | |
78 // Returns -1 if there was an error retrieving the directory time. | |
79 int GetDirectoryWriteTimeInHours(const wchar_t* path) { | |
80 // To open a directory you need to pass FILE_FLAG_BACKUP_SEMANTICS. | |
81 DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; | |
82 HANDLE file = ::CreateFileW(path, 0, share, NULL, OPEN_EXISTING, | |
grt (UTC plus 2)
2013/02/22 16:47:56
use base::win::ScopedHandle and remove calls to Cl
huangs
2013/02/22 20:32:37
Done.
| |
83 FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
84 if (INVALID_HANDLE_VALUE == file) | |
85 return -1; | |
86 FILETIME time; | |
87 if (!::GetFileTime(file, NULL, NULL, &time)) { | |
88 ::CloseHandle(file); | |
89 return -1; | |
90 } | |
91 | |
92 ::CloseHandle(file); | |
93 return FileTimeToHours(time); | |
94 } | |
95 | |
96 // Returns the directory last-write time age in hours, relative to current | |
97 // time, so if it returns 14 it means that the directory was last written 14 | |
98 // hours ago. Returns -1 if there was an error retrieving the directory. | |
99 int GetDirectoryWriteAgeInHours(const wchar_t* path) { | |
100 int dir_time = GetDirectoryWriteTimeInHours(path); | |
101 if (dir_time < 0) | |
102 return dir_time; | |
103 FILETIME time; | |
104 GetSystemTimeAsFileTime(&time); | |
105 int now_time = FileTimeToHours(time); | |
106 if (dir_time >= now_time) | |
107 return 0; | |
108 return (now_time - dir_time); | |
109 } | |
110 | |
111 // Launches setup.exe (located at |setup_path|) with |cmd_line|. | |
112 // If system_level_toast is true, appends --system-level-toast. | |
113 // If handle to experiment result key was given at startup, re-add it. | |
114 // Does not wait for the process to terminate. | |
115 // |cmd_line| may be modified as a result of this call. | |
116 bool LaunchSetup(CommandLine* cmd_line, | |
117 const installer::Product& product, | |
118 bool system_level_toast) { | |
119 const CommandLine& current_cmd_line = *CommandLine::ForCurrentProcess(); | |
120 | |
121 // Propagate --verbose-logging to the invoked setup.exe. | |
122 if (current_cmd_line.HasSwitch(installer::switches::kVerboseLogging)) | |
123 cmd_line->AppendSwitch(installer::switches::kVerboseLogging); | |
124 | |
125 // Pass along product-specific options. | |
126 product.AppendProductFlags(cmd_line); | |
127 | |
128 // Re-add the system level toast flag. | |
129 if (system_level_toast) { | |
130 cmd_line->AppendSwitch(installer::switches::kSystemLevel); | |
131 cmd_line->AppendSwitch(installer::switches::kSystemLevelToast); | |
132 | |
133 // Re-add the toast result key. We need to do this because Setup running as | |
134 // system passes the key to Setup running as user, but that child process | |
135 // does not perform the actual toasting, it launches another Setup (as user) | |
136 // to do so. That is the process that needs the key. | |
137 std::string key(installer::switches::kToastResultsKey); | |
138 std::string toast_key = current_cmd_line.GetSwitchValueASCII(key); | |
139 if (!toast_key.empty()) { | |
140 cmd_line->AppendSwitchASCII(key, toast_key); | |
141 | |
142 // Use handle inheritance to make sure the duplicated toast results key | |
143 // gets inherited by the child process. | |
144 base::LaunchOptions options; | |
145 options.inherit_handles = true; | |
146 return base::LaunchProcess(*cmd_line, options, NULL); | |
147 } | |
148 } | |
149 | |
150 return base::LaunchProcess(*cmd_line, base::LaunchOptions(), NULL); | |
151 } | |
152 | |
153 // For System level installs, setup.exe lives in the system temp, which | |
154 // is normally c:\windows\temp. In many cases files inside this folder | |
155 // are not accessible for execution by regular user accounts. | |
156 // This function changes the permissions so that any authenticated user | |
157 // can launch |exe| later on. This function should only be called if the | |
158 // code is running at the system level. | |
159 bool FixDACLsForExecute(const base::FilePath& exe) { | |
160 // The general strategy to is to add an ACE to the exe DACL the quick | |
161 // and dirty way: a) read the DACL b) convert it to sddl string c) add the | |
162 // new ACE to the string d) convert sddl string back to DACL and finally | |
163 // e) write new dacl. | |
164 char buff[1024]; | |
165 DWORD len = sizeof(buff); | |
166 PSECURITY_DESCRIPTOR sd = reinterpret_cast<PSECURITY_DESCRIPTOR>(buff); | |
167 if (!::GetFileSecurityW(exe.value().c_str(), DACL_SECURITY_INFORMATION, | |
168 sd, len, &len)) { | |
169 return false; | |
170 } | |
171 wchar_t* sddl = 0; | |
172 if (!::ConvertSecurityDescriptorToStringSecurityDescriptorW(sd, | |
173 SDDL_REVISION_1, DACL_SECURITY_INFORMATION, &sddl, NULL)) | |
174 return false; | |
175 string16 new_sddl(sddl); | |
176 ::LocalFree(sddl); | |
177 sd = NULL; | |
178 // See MSDN for the security descriptor definition language (SDDL) syntax, | |
179 // in our case we add "A;" generic read 'GR' and generic execute 'GX' for | |
180 // the nt\authenticated_users 'AU' group, that becomes: | |
181 const wchar_t kAllowACE[] = L"(A;;GRGX;;;AU)"; | |
182 // We should check that there are no special ACES for the group we | |
183 // are interested, which is nt\authenticated_users. | |
184 if (string16::npos != new_sddl.find(L";AU)")) | |
185 return false; | |
186 // Specific ACEs (not inherited) need to go to the front. It is ok if we | |
187 // are the very first one. | |
188 size_t pos_insert = new_sddl.find(L"("); | |
189 if (string16::npos == pos_insert) | |
190 return false; | |
191 // All good, time to change the dacl. | |
192 new_sddl.insert(pos_insert, kAllowACE); | |
193 if (!::ConvertStringSecurityDescriptorToSecurityDescriptorW(new_sddl.c_str(), | |
194 SDDL_REVISION_1, &sd, NULL)) | |
195 return false; | |
196 bool rv = ::SetFileSecurityW(exe.value().c_str(), DACL_SECURITY_INFORMATION, | |
197 sd) == TRUE; | |
198 ::LocalFree(sd); | |
199 return rv; | |
200 } | |
201 | |
202 // This function launches setup as the currently logged-in interactive | |
203 // user that is the user whose logon session is attached to winsta0\default. | |
204 // It assumes that currently we are running as SYSTEM in a non-interactive | |
205 // windowstation. | |
206 // The function fails if there is no interactive session active, basically | |
207 // the computer is on but nobody has logged in locally. | |
208 // Remote Desktop sessions do not count as interactive sessions; running this | |
209 // method as a user logged in via remote desktop will do nothing. | |
210 bool LaunchSetupAsConsoleUser(const base::FilePath& setup_path, | |
211 const installer::Product& product, | |
212 const std::string& flag) { | |
213 CommandLine cmd_line(setup_path); | |
214 cmd_line.AppendSwitch(flag); | |
215 | |
216 // Pass along product-specific options. | |
217 product.AppendProductFlags(&cmd_line); | |
218 | |
219 // Convey to the invoked setup.exe that it's operating on a system-level | |
220 // installation. | |
221 cmd_line.AppendSwitch(installer::switches::kSystemLevel); | |
222 | |
223 // Propagate --verbose-logging to the invoked setup.exe. | |
224 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
225 installer::switches::kVerboseLogging)) { | |
226 cmd_line.AppendSwitch(installer::switches::kVerboseLogging); | |
227 } | |
228 | |
229 // Get the Google Update results key, and pass it on the command line to | |
230 // the child process. | |
231 int key = GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey(); | |
232 cmd_line.AppendSwitchASCII(installer::switches::kToastResultsKey, | |
233 base::IntToString(key)); | |
234 | |
235 if (base::win::GetVersion() > base::win::VERSION_XP) { | |
236 // Make sure that in Vista and Above we have the proper DACLs so | |
237 // the interactive user can launch it. | |
238 if (!FixDACLsForExecute(setup_path)) | |
239 NOTREACHED(); | |
240 } | |
241 | |
242 DWORD console_id = ::WTSGetActiveConsoleSessionId(); | |
243 if (console_id == 0xFFFFFFFF) { | |
244 PLOG(ERROR) << __FUNCTION__ << " failed to get active session id"; | |
245 return false; | |
246 } | |
247 HANDLE user_token; | |
248 if (!::WTSQueryUserToken(console_id, &user_token)) { | |
249 PLOG(ERROR) << __FUNCTION__ << " failed to get user token for console_id " | |
250 << console_id; | |
251 return false; | |
252 } | |
253 // Note: Handle inheritance must be true in order for the child process to be | |
254 // able to use the duplicated handle above (Google Update results). | |
255 base::LaunchOptions options; | |
256 options.as_user = user_token; | |
257 options.inherit_handles = true; | |
258 options.empty_desktop_name = true; | |
259 VLOG(1) << __FUNCTION__ << " launching " << cmd_line.GetCommandLineString(); | |
260 bool launched = base::LaunchProcess(cmd_line, options, NULL); | |
261 ::CloseHandle(user_token); | |
262 VLOG(1) << __FUNCTION__ << " result: " << launched; | |
263 return launched; | |
264 } | |
265 | |
266 // A helper function that writes to HKLM if the handle was passed through the | |
267 // command line, but HKCU otherwise. |experiment_group| is the value to write | |
268 // and |last_write| is used when writing to HKLM to determine whether to close | |
269 // the handle when done. | |
270 void SetClient(const string16& experiment_group, bool last_write) { | |
271 static int reg_key_handle = -1; | |
272 if (reg_key_handle == -1) { | |
273 // If a specific Toast Results key handle (presumably to our HKLM key) was | |
274 // passed in to the command line (such as for system level installs), we use | |
275 // it. Otherwise, we write to the key under HKCU. | |
276 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); | |
277 if (cmd_line.HasSwitch(installer::switches::kToastResultsKey)) { | |
278 // Get the handle to the key under HKLM. | |
279 base::StringToInt(cmd_line.GetSwitchValueASCII( | |
280 installer::switches::kToastResultsKey).c_str(), | |
281 ®_key_handle); | |
282 } else { | |
283 reg_key_handle = 0; | |
284 } | |
285 } | |
286 | |
287 if (reg_key_handle) { | |
288 // Use it to write the experiment results. | |
289 GoogleUpdateSettings::WriteGoogleUpdateSystemClientKey( | |
290 reg_key_handle, google_update::kRegClientField, experiment_group); | |
291 if (last_write) | |
292 CloseHandle((HANDLE) reg_key_handle); | |
293 } else { | |
294 // Write to HKCU. | |
295 GoogleUpdateSettings::SetClient(experiment_group); | |
296 } | |
297 } | |
298 | |
299 } // namespace | |
300 | |
301 UserExperiment::UserExperiment() {} | |
302 | |
303 // static | |
304 bool UserExperiment::CreateExperimentDetails( | |
305 UserExperiment::ExperimentDetails* experiment, | |
306 int flavor) { | |
307 struct FlavorDetails { | |
308 int heading_id; | |
309 int flags; | |
310 }; | |
311 // Maximum number of experiment flavors we support. | |
312 static const int kMax = 4; | |
313 // This struct determines which experiment flavors we show for each locale and | |
314 // brand. | |
315 // | |
316 // Plugin infobar experiment: | |
317 // The experiment in 2011 used PIxx codes. | |
318 // | |
319 // Inactive user toast experiment: | |
320 // The experiment in Dec 2009 used TGxx and THxx. | |
321 // The experiment in Feb 2010 used TKxx and TLxx. | |
322 // The experiment in Apr 2010 used TMxx and TNxx. | |
323 // The experiment in Oct 2010 used TVxx TWxx TXxx TYxx. | |
324 // The experiment in Feb 2011 used SJxx SKxx SLxx SMxx. | |
325 // The experiment in Mar 2012 used ZAxx ZBxx ZCxx. | |
326 // The experiment in Jan 2013 uses DAxx. | |
327 using namespace attrition_experiments; | |
328 | |
329 static const struct UserExperimentSpecs { | |
330 const wchar_t* locale; // Locale to show this experiment for (* for all). | |
331 const wchar_t* brands; // Brand codes show this experiment for (* for all). | |
332 int control_group; // Size of the control group, in percentages. | |
333 const wchar_t* prefix; // The two letter experiment code. The second letter | |
334 // will be incremented with the flavor. | |
335 FlavorDetails flavors[kMax]; | |
336 } kExperiments[] = { | |
337 // The first match from top to bottom is used so this list should be ordered | |
338 // most-specific rule first. | |
339 { L"*", L"GGRV", // All locales, GGRV is enterprise. | |
340 0, // 0 percent control group. | |
341 L"EA", // Experiment is EAxx, EBxx, etc. | |
342 // No flavors means no experiment. | |
343 { { 0, 0 }, | |
344 { 0, 0 }, | |
345 { 0, 0 }, | |
346 { 0, 0 } | |
347 } | |
348 }, | |
349 { L"*", L"*", // All locales, all brands. | |
350 5, // 5 percent control group. | |
351 L"DA", // Experiment is DAxx. | |
352 // One single flavor. | |
353 { { IDS_TRY_TOAST_HEADING3, kMakeDefault }, | |
354 { 0, 0 }, | |
355 { 0, 0 }, | |
356 { 0, 0 } | |
357 } | |
358 } | |
359 }; | |
360 | |
361 string16 locale; | |
362 GoogleUpdateSettings::GetLanguage(&locale); | |
363 if (locale.empty() || (locale == ASCIIToWide("en"))) | |
364 locale = ASCIIToWide("en-US"); | |
365 | |
366 string16 brand; | |
367 if (!GoogleUpdateSettings::GetBrand(&brand)) | |
368 brand = ASCIIToWide(""); // Could still be viable for catch-all rules. | |
369 | |
370 for (int i = 0; i < arraysize(kExperiments); ++i) { | |
371 if (kExperiments[i].locale != locale && | |
372 kExperiments[i].locale != ASCIIToWide("*")) | |
373 continue; | |
374 | |
375 std::vector<string16> brand_codes; | |
376 base::SplitString(kExperiments[i].brands, L',', &brand_codes); | |
377 if (brand_codes.empty()) | |
378 return false; | |
379 for (std::vector<string16>::iterator it = brand_codes.begin(); | |
380 it != brand_codes.end(); ++it) { | |
381 if (*it != brand && *it != L"*") | |
382 continue; | |
383 // We have found our match. | |
384 const UserExperimentSpecs& match = kExperiments[i]; | |
385 // Find out how many flavors we have. Zero means no experiment. | |
386 int num_flavors = 0; | |
387 while (match.flavors[num_flavors].heading_id) { ++num_flavors; } | |
388 if (!num_flavors) | |
389 return false; | |
390 | |
391 if (flavor < 0) | |
392 flavor = base::RandInt(0, num_flavors - 1); | |
393 experiment->flavor = flavor; | |
394 experiment->heading = match.flavors[flavor].heading_id; | |
395 experiment->control_group = match.control_group; | |
396 const wchar_t prefix[] = { match.prefix[0], match.prefix[1] + flavor, 0 }; | |
397 experiment->prefix = prefix; | |
398 experiment->flags = match.flavors[flavor].flags; | |
399 return true; | |
400 } | |
401 } | |
402 | |
403 return false; | |
404 } | |
405 | |
406 // Currently we only have one experiment: the inactive user toast. Which only | |
407 // applies for users doing upgrades. | |
408 | |
409 // static | |
410 // There are three scenarios when this function is called: | |
411 // 1- Is a per-user-install and it updated: perform the experiment | |
412 // 2- Is a system-install and it updated : relaunch as the interactive user | |
413 // 3- It has been re-launched from the #2 case. In this case we enter | |
414 // this function with |system_install| true and a REENTRY_SYS_UPDATE status. | |
415 void UserExperiment::LaunchUserExperiment(const base::FilePath& setup_path, | |
416 installer::InstallStatus status, | |
417 const Version& version, | |
418 const installer::Product& product, | |
419 bool system_level) { | |
420 VLOG(1) << "LaunchUserExperiment status: " << status << " product: " | |
421 << product.distribution()->GetAppShortCutName() | |
422 << " system_level: " << system_level; | |
423 | |
424 if (system_level) { | |
425 if (installer::NEW_VERSION_UPDATED == status) { | |
426 // We need to relaunch as the interactive user. | |
427 LaunchSetupAsConsoleUser(setup_path, product, | |
428 installer::switches::kSystemLevelToast); | |
429 return; | |
430 } | |
431 } else { | |
432 if ((installer::NEW_VERSION_UPDATED != status) && | |
433 (installer::REENTRY_SYS_UPDATE != status)) { | |
434 // We are not updating or in re-launch. Exit. | |
435 return; | |
436 } | |
437 } | |
438 | |
439 // The |flavor| value ends up being processed by TryChromeDialogView to show | |
440 // different experiments. | |
441 ExperimentDetails experiment; | |
442 if (!CreateExperimentDetails(&experiment, -1)) { | |
443 VLOG(1) << "Failed to get experiment details."; | |
444 return; | |
445 } | |
446 int flavor = experiment.flavor; | |
447 string16 base_group = experiment.prefix; | |
448 | |
449 string16 brand; | |
450 if (GoogleUpdateSettings::GetBrand(&brand) && (brand == L"CHXX")) { | |
451 // Testing only: the user automatically qualifies for the experiment. | |
452 VLOG(1) << "Experiment qualification bypass"; | |
453 } else { | |
454 // Check that the user was not already drafted in this experiment. | |
455 string16 client; | |
456 GoogleUpdateSettings::GetClient(&client); | |
457 if (client.size() > 2) { | |
458 if (base_group == client.substr(0, 2)) { | |
459 VLOG(1) << "User already participated in this experiment"; | |
460 return; | |
461 } | |
462 } | |
463 // Check browser usage inactivity by the age of the last-write time of the | |
464 // most recently-used chrome user data directory. | |
465 std::vector<base::FilePath> user_data_dirs; | |
466 product.GetUserDataPaths(&user_data_dirs); | |
467 int dir_age_hours = -1; | |
468 for (size_t i = 0; i < user_data_dirs.size(); ++i) { | |
469 int this_age = GetDirectoryWriteAgeInHours( | |
470 user_data_dirs[i].value().c_str()); | |
471 if (this_age >= 0 && (dir_age_hours < 0 || this_age < dir_age_hours)) | |
472 dir_age_hours = this_age; | |
473 } | |
474 | |
475 const bool experiment_enabled = false; | |
476 const int kThirtyDays = 30 * 24; | |
477 | |
478 if (!experiment_enabled) { | |
479 VLOG(1) << "Toast experiment is disabled."; | |
480 return; | |
481 } else if (dir_age_hours < 0) { | |
482 // This means that we failed to find the user data dir. The most likely | |
483 // cause is that this user has not ever used chrome at all which can | |
484 // happen in a system-level install. | |
485 SetClient(base_group + kToastUDDirFailure, true); | |
486 return; | |
487 } else if (dir_age_hours < kThirtyDays) { | |
488 // An active user, so it does not qualify. | |
489 VLOG(1) << "Chrome used in last " << dir_age_hours << " hours"; | |
490 SetClient(base_group + kToastActiveGroup, true); | |
491 return; | |
492 } | |
493 // Check to see if this user belongs to the control group. | |
494 double control_group = 1.0 * (100 - experiment.control_group) / 100; | |
495 if (base::RandDouble() > control_group) { | |
496 SetClient(base_group + kToastExpControlGroup, true); | |
497 VLOG(1) << "User is control group"; | |
498 return; | |
499 } | |
500 } | |
501 | |
502 VLOG(1) << "User drafted for toast experiment " << flavor; | |
503 SetClient(base_group + kToastExpBaseGroup, false); | |
504 // User level: The experiment needs to be performed in a different process | |
505 // because google_update expects the upgrade process to be quick and nimble. | |
506 // System level: We have already been relaunched, so we don't need to be | |
507 // quick, but we relaunch to follow the exact same codepath. | |
508 CommandLine cmd_line(setup_path); | |
509 cmd_line.AppendSwitchASCII(installer::switches::kInactiveUserToast, | |
510 base::IntToString(flavor)); | |
511 cmd_line.AppendSwitchASCII(installer::switches::kExperimentGroup, | |
512 WideToASCII(base_group)); | |
513 LaunchSetup(&cmd_line, product, system_level); | |
514 } | |
515 | |
516 // static | |
517 // User qualifies for the experiment. To test, use --try-chrome-again=|flavor| | |
518 // as a parameter to chrome.exe. | |
519 void UserExperiment::InactiveUserToastExperiment( | |
520 BrowserDistribution* dist, | |
521 int flavor, | |
522 const string16& experiment_group, | |
523 const installer::Product& installation, | |
524 const base::FilePath& application_path) { | |
525 // Add the 'welcome back' url for chrome to show. | |
526 CommandLine options(CommandLine::NO_PROGRAM); | |
527 options.AppendSwitchNative(::switches::kTryChromeAgain, | |
528 base::IntToString16(flavor)); | |
529 // Prepend the url with a space. | |
530 string16 url(GetWelcomeBackUrl()); | |
531 options.AppendArg("--"); | |
532 options.AppendArgNative(url); | |
533 // The command line should now have the url added as: | |
534 // "chrome.exe -- <url>" | |
535 DCHECK_NE(string16::npos, | |
536 options.GetCommandLineString().find(L" -- " + url)); | |
537 | |
538 // Launch chrome now. It will show the toast UI. | |
539 int32 exit_code = 0; | |
540 if (!installation.LaunchChromeAndWait(application_path, options, &exit_code)) | |
541 return; | |
542 | |
543 // The chrome process has exited, figure out what happened. | |
544 const wchar_t* outcome = NULL; | |
545 switch (exit_code) { | |
546 case content::RESULT_CODE_NORMAL_EXIT: | |
547 outcome = kToastExpTriesOkGroup; | |
548 break; | |
549 case chrome::RESULT_CODE_NORMAL_EXIT_CANCEL: | |
550 outcome = kToastExpCancelGroup; | |
551 break; | |
552 case chrome::RESULT_CODE_NORMAL_EXIT_EXP2: | |
553 outcome = kToastExpUninstallGroup; | |
554 break; | |
555 default: | |
556 outcome = kToastExpTriesErrorGroup; | |
557 }; | |
558 // Write to the |client| key for the last time. | |
559 SetClient(experiment_group + outcome, true); | |
560 | |
561 if (outcome != kToastExpUninstallGroup) | |
562 return; | |
563 // The user wants to uninstall. This is a best effort operation. Note that | |
564 // we waited for chrome to exit so the uninstall would not detect chrome | |
565 // running. | |
566 bool system_level_toast = CommandLine::ForCurrentProcess()->HasSwitch( | |
567 installer::switches::kSystemLevelToast); | |
568 | |
569 CommandLine cmd(InstallUtil::GetChromeUninstallCmd(system_level_toast, | |
570 dist->GetType())); | |
571 base::LaunchProcess(cmd, base::LaunchOptions(), NULL); | |
572 } | |
573 | |
574 } // namespace installer | |
OLD | NEW |