Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 |
| 5 // This file defines specific implementation of BrowserDistribution class for | 5 #include "chrome/installer/util/user_experiment.h" |
| 6 // Google Chrome. | 6 |
| 7 | |
| 8 #include "chrome/installer/util/google_chrome_distribution.h" | |
| 9 | |
| 10 #include <windows.h> | |
| 11 #include <msi.h> | |
| 12 #include <sddl.h> | 7 #include <sddl.h> |
| 13 #include <wtsapi32.h> | 8 #include <wtsapi32.h> |
| 14 #include <vector> | 9 #include <vector> |
| 15 | 10 |
| 16 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 17 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 18 #include "base/json/json_file_value_serializer.h" | |
| 19 #include "base/memory/scoped_ptr.h" | |
| 20 #include "base/path_service.h" | |
| 21 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 22 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 23 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 24 #include "base/stringprintf.h" | |
| 25 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 26 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 27 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 28 #include "base/win/registry.h" | 19 #include "base/win/scoped_handle.h" |
| 29 #include "base/win/windows_version.h" | 20 #include "base/win/windows_version.h" |
| 30 #include "chrome/common/attrition_experiments.h" | 21 #include "chrome/common/attrition_experiments.h" |
| 31 #include "chrome/common/chrome_result_codes.h" | 22 #include "chrome/common/chrome_result_codes.h" |
| 32 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/net/test_server_locations.h" | |
| 34 #include "chrome/common/pref_names.h" | |
| 35 #include "chrome/installer/util/channel_info.h" | |
| 36 #include "chrome/installer/util/google_update_constants.h" | 24 #include "chrome/installer/util/google_update_constants.h" |
| 37 #include "chrome/installer/util/google_update_settings.h" | 25 #include "chrome/installer/util/google_update_settings.h" |
| 38 #include "chrome/installer/util/helper.h" | |
| 39 #include "chrome/installer/util/install_util.h" | 26 #include "chrome/installer/util/install_util.h" |
| 40 #include "chrome/installer/util/l10n_string_util.h" | |
| 41 #include "chrome/installer/util/product.h" | 27 #include "chrome/installer/util/product.h" |
| 42 #include "chrome/installer/util/util_constants.h" | |
| 43 #include "chrome/installer/util/wmi.h" | |
| 44 #include "content/public/common/result_codes.h" | 28 #include "content/public/common/result_codes.h" |
| 45 | 29 |
| 46 #include "installer_util_strings.h" // NOLINT | |
| 47 | |
| 48 #pragma comment(lib, "wtsapi32.lib") | 30 #pragma comment(lib, "wtsapi32.lib") |
| 49 | 31 |
| 32 namespace installer { | |
| 33 | |
| 50 namespace { | 34 namespace { |
| 51 | 35 |
| 52 const wchar_t kChromeGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | |
| 53 const wchar_t kBrowserAppId[] = L"Chrome"; | |
| 54 const wchar_t kCommandExecuteImplUuid[] = | |
| 55 L"{5C65F4B0-3651-4514-B207-D10CB699B14B}"; | |
| 56 | |
| 57 // The following strings are the possible outcomes of the toast experiment | 36 // The following strings are the possible outcomes of the toast experiment |
| 58 // as recorded in the |client| field. | 37 // as recorded in the |client| field. |
| 59 const wchar_t kToastExpControlGroup[] = L"01"; | 38 const wchar_t kToastExpControlGroup[] = L"01"; |
| 60 const wchar_t kToastExpCancelGroup[] = L"02"; | 39 const wchar_t kToastExpCancelGroup[] = L"02"; |
| 61 const wchar_t kToastExpUninstallGroup[] = L"04"; | 40 const wchar_t kToastExpUninstallGroup[] = L"04"; |
| 62 const wchar_t kToastExpTriesOkGroup[] = L"18"; | 41 const wchar_t kToastExpTriesOkGroup[] = L"18"; |
| 63 const wchar_t kToastExpTriesErrorGroup[] = L"28"; | 42 const wchar_t kToastExpTriesErrorGroup[] = L"28"; |
| 64 const wchar_t kToastActiveGroup[] = L"40"; | 43 const wchar_t kToastActiveGroup[] = L"40"; |
| 65 const wchar_t kToastUDDirFailure[] = L"40"; | 44 const wchar_t kToastUDDirFailure[] = L"40"; |
| 66 const wchar_t kToastExpBaseGroup[] = L"80"; | 45 const wchar_t kToastExpBaseGroup[] = L"80"; |
| 67 | 46 |
| 68 // Substitute the locale parameter in uninstall URL with whatever | 47 // Substitute the locale parameter in uninstall URL with whatever |
| 69 // Google Update tells us is the locale. In case we fail to find | 48 // Google Update tells us is the locale. In case we fail to find |
| 70 // the locale, we use US English. | 49 // the locale, we use US English. |
| 71 string16 LocalizeUrl(const wchar_t* url) { | 50 string16 LocalizeUrl(const wchar_t* url) { |
| 72 string16 language; | 51 string16 language; |
| 73 if (!GoogleUpdateSettings::GetLanguage(&language)) | 52 if (!GoogleUpdateSettings::GetLanguage(&language)) |
| 74 language = L"en-US"; // Default to US English. | 53 language = L"en-US"; // Default to US English. |
| 75 return ReplaceStringPlaceholders(url, language.c_str(), NULL); | 54 return ReplaceStringPlaceholders(url, language.c_str(), NULL); |
| 76 } | 55 } |
| 77 | 56 |
| 78 string16 GetUninstallSurveyUrl() { | |
| 79 const wchar_t kSurveyUrl[] = L"http://www.google.com/support/chrome/bin/" | |
| 80 L"request.py?hl=$1&contact_type=uninstall"; | |
| 81 return LocalizeUrl(kSurveyUrl); | |
| 82 } | |
| 83 | |
| 84 string16 GetWelcomeBackUrl() { | 57 string16 GetWelcomeBackUrl() { |
| 85 const wchar_t kWelcomeUrl[] = L"http://www.google.com/chrome/intl/$1/" | 58 const wchar_t kWelcomeUrl[] = L"http://www.google.com/chrome/intl/$1/" |
| 86 L"welcomeback-new.html"; | 59 L"welcomeback-new.html"; |
| 87 return LocalizeUrl(kWelcomeUrl); | 60 return LocalizeUrl(kWelcomeUrl); |
| 88 } | 61 } |
| 89 | 62 |
| 90 // Converts FILETIME to hours. FILETIME times are absolute times in | 63 // Converts FILETIME to hours. FILETIME times are absolute times in |
| 91 // 100 nanosecond units. For example 5:30 pm of June 15, 2009 is 3580464. | 64 // 100 nanosecond units. For example 5:30 pm of June 15, 2009 is 3580464. |
| 92 int FileTimeToHours(const FILETIME& time) { | 65 int FileTimeToHours(const FILETIME& time) { |
| 93 const ULONGLONG k100sNanoSecsToHours = 10000000LL * 60 * 60; | 66 const ULONGLONG k100sNanoSecsToHours = 10000000LL * 60 * 60; |
| 94 ULARGE_INTEGER uli = {time.dwLowDateTime, time.dwHighDateTime}; | 67 ULARGE_INTEGER uli = {time.dwLowDateTime, time.dwHighDateTime}; |
| 95 return static_cast<int>(uli.QuadPart / k100sNanoSecsToHours); | 68 return static_cast<int>(uli.QuadPart / k100sNanoSecsToHours); |
| 96 } | 69 } |
| 97 | 70 |
| 98 // Returns the directory last write time in hours since January 1, 1601. | 71 // Returns the directory last write time in hours since January 1, 1601. |
| 99 // Returns -1 if there was an error retrieving the directory time. | 72 // Returns -1 if there was an error retrieving the directory time. |
| 100 int GetDirectoryWriteTimeInHours(const wchar_t* path) { | 73 int GetDirectoryWriteTimeInHours(const wchar_t* path) { |
| 101 // To open a directory you need to pass FILE_FLAG_BACKUP_SEMANTICS. | 74 // To open a directory you need to pass FILE_FLAG_BACKUP_SEMANTICS. |
| 102 DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; | 75 DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; |
| 103 HANDLE file = ::CreateFileW(path, 0, share, NULL, OPEN_EXISTING, | 76 base::win::ScopedHandle file(::CreateFileW(path, 0, share, NULL, |
| 104 FILE_FLAG_BACKUP_SEMANTICS, NULL); | 77 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL)); |
| 105 if (INVALID_HANDLE_VALUE == file) | 78 if (!file.IsValid()) |
| 106 return -1; | 79 return -1; |
| 80 | |
| 107 FILETIME time; | 81 FILETIME time; |
| 108 if (!::GetFileTime(file, NULL, NULL, &time)) { | 82 return ::GetFileTime(file, NULL, NULL, &time) ? FileTimeToHours(time) : -1; |
| 109 ::CloseHandle(file); | |
| 110 return -1; | |
| 111 } | |
| 112 | |
| 113 ::CloseHandle(file); | |
| 114 return FileTimeToHours(time); | |
| 115 } | 83 } |
| 116 | 84 |
| 117 // Returns the directory last-write time age in hours, relative to current | 85 // Returns the directory last-write time age in hours, relative to current |
| 118 // time, so if it returns 14 it means that the directory was last written 14 | 86 // time, so if it returns 14 it means that the directory was last written 14 |
| 119 // hours ago. Returns -1 if there was an error retrieving the directory. | 87 // hours ago. Returns -1 if there was an error retrieving the directory. |
| 120 int GetDirectoryWriteAgeInHours(const wchar_t* path) { | 88 int GetDirectoryWriteAgeInHours(const wchar_t* path) { |
| 121 int dir_time = GetDirectoryWriteTimeInHours(path); | 89 int dir_time = GetDirectoryWriteTimeInHours(path); |
| 122 if (dir_time < 0) | 90 if (dir_time < 0) |
| 123 return dir_time; | 91 return dir_time; |
| 124 FILETIME time; | 92 FILETIME time; |
| 125 GetSystemTimeAsFileTime(&time); | 93 GetSystemTimeAsFileTime(&time); |
| 126 int now_time = FileTimeToHours(time); | 94 int now_time = FileTimeToHours(time); |
| 127 if (dir_time >= now_time) | 95 if (dir_time >= now_time) |
| 128 return 0; | 96 return 0; |
| 129 return (now_time - dir_time); | 97 return (now_time - dir_time); |
| 130 } | 98 } |
| 131 | 99 |
| 132 // Launches setup.exe (located at |setup_path|) with |cmd_line|. | 100 // Launches setup.exe (located at |setup_path|) with |cmd_line|. |
| 133 // If system_level_toast is true, appends --system-level-toast. | 101 // If system_level_toast is true, appends --system-level-toast. |
| 134 // If handle to experiment result key was given at startup, re-add it. | 102 // If handle to experiment result key was given at startup, re-add it. |
| 135 // Does not wait for the process to terminate. | 103 // Does not wait for the process to terminate. |
| 136 // |cmd_line| may be modified as a result of this call. | 104 // |cmd_line| may be modified as a result of this call. |
| 137 bool LaunchSetup(CommandLine* cmd_line, | 105 bool LaunchSetup(CommandLine* cmd_line, |
| 138 const installer::Product& product, | |
| 139 bool system_level_toast) { | 106 bool system_level_toast) { |
|
grt (UTC plus 2)
2013/03/12 14:32:18
nit: move this to the previous line.
huangs
2013/03/12 18:03:07
Done.
huangs
2013/03/12 18:03:07
Done.
| |
| 140 const CommandLine& current_cmd_line = *CommandLine::ForCurrentProcess(); | 107 const CommandLine& current_cmd_line = *CommandLine::ForCurrentProcess(); |
| 141 | 108 |
| 142 // Propagate --verbose-logging to the invoked setup.exe. | 109 // Propagate --verbose-logging to the invoked setup.exe. |
| 143 if (current_cmd_line.HasSwitch(installer::switches::kVerboseLogging)) | 110 if (current_cmd_line.HasSwitch(installer::switches::kVerboseLogging)) |
|
grt (UTC plus 2)
2013/03/12 14:32:18
remove "installer::" everywhere possible since thi
huangs
2013/03/12 18:03:07
Done, with line wraps.
| |
| 144 cmd_line->AppendSwitch(installer::switches::kVerboseLogging); | 111 cmd_line->AppendSwitch(installer::switches::kVerboseLogging); |
| 145 | 112 |
| 146 // Pass along product-specific options. | |
| 147 product.AppendProductFlags(cmd_line); | |
| 148 | |
| 149 // Re-add the system level toast flag. | 113 // Re-add the system level toast flag. |
| 150 if (system_level_toast) { | 114 if (system_level_toast) { |
| 151 cmd_line->AppendSwitch(installer::switches::kSystemLevel); | 115 cmd_line->AppendSwitch(installer::switches::kSystemLevel); |
| 152 cmd_line->AppendSwitch(installer::switches::kSystemLevelToast); | 116 cmd_line->AppendSwitch(installer::switches::kSystemLevelToast); |
| 153 | 117 |
| 154 // Re-add the toast result key. We need to do this because Setup running as | 118 // Re-add the toast result key. We need to do this because Setup running as |
| 155 // system passes the key to Setup running as user, but that child process | 119 // system passes the key to Setup running as user, but that child process |
| 156 // does not perform the actual toasting, it launches another Setup (as user) | 120 // does not perform the actual toasting, it launches another Setup (as user) |
| 157 // to do so. That is the process that needs the key. | 121 // to do so. That is the process that needs the key. |
| 158 std::string key(installer::switches::kToastResultsKey); | 122 std::string key(installer::switches::kToastResultsKey); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 } | 185 } |
| 222 | 186 |
| 223 // This function launches setup as the currently logged-in interactive | 187 // This function launches setup as the currently logged-in interactive |
| 224 // user that is the user whose logon session is attached to winsta0\default. | 188 // user that is the user whose logon session is attached to winsta0\default. |
| 225 // It assumes that currently we are running as SYSTEM in a non-interactive | 189 // It assumes that currently we are running as SYSTEM in a non-interactive |
| 226 // windowstation. | 190 // windowstation. |
| 227 // The function fails if there is no interactive session active, basically | 191 // The function fails if there is no interactive session active, basically |
| 228 // the computer is on but nobody has logged in locally. | 192 // the computer is on but nobody has logged in locally. |
| 229 // Remote Desktop sessions do not count as interactive sessions; running this | 193 // Remote Desktop sessions do not count as interactive sessions; running this |
| 230 // method as a user logged in via remote desktop will do nothing. | 194 // method as a user logged in via remote desktop will do nothing. |
| 231 bool LaunchSetupAsConsoleUser(const base::FilePath& setup_path, | 195 bool LaunchSetupAsConsoleUser(CommandLine* cmd_line) { |
| 232 const installer::Product& product, | |
| 233 const std::string& flag) { | |
| 234 CommandLine cmd_line(setup_path); | |
| 235 cmd_line.AppendSwitch(flag); | |
| 236 | |
| 237 // Pass along product-specific options. | |
| 238 product.AppendProductFlags(&cmd_line); | |
| 239 | |
| 240 // Convey to the invoked setup.exe that it's operating on a system-level | 196 // Convey to the invoked setup.exe that it's operating on a system-level |
| 241 // installation. | 197 // installation. |
| 242 cmd_line.AppendSwitch(installer::switches::kSystemLevel); | 198 cmd_line->AppendSwitch(installer::switches::kSystemLevel); |
| 243 | 199 |
| 244 // Propagate --verbose-logging to the invoked setup.exe. | 200 // Propagate --verbose-logging to the invoked setup.exe. |
| 245 if (CommandLine::ForCurrentProcess()->HasSwitch( | 201 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 246 installer::switches::kVerboseLogging)) { | 202 installer::switches::kVerboseLogging)) { |
| 247 cmd_line.AppendSwitch(installer::switches::kVerboseLogging); | 203 cmd_line->AppendSwitch(installer::switches::kVerboseLogging); |
| 248 } | 204 } |
| 249 | 205 |
| 250 // Get the Google Update results key, and pass it on the command line to | 206 // Get the Google Update results key, and pass it on the command line to |
| 251 // the child process. | 207 // the child process. |
| 252 int key = GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey(); | 208 int key = GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey(); |
| 253 cmd_line.AppendSwitchASCII(installer::switches::kToastResultsKey, | 209 cmd_line->AppendSwitchASCII(installer::switches::kToastResultsKey, |
| 254 base::IntToString(key)); | 210 base::IntToString(key)); |
| 255 | 211 |
| 256 if (base::win::GetVersion() > base::win::VERSION_XP) { | 212 if (base::win::GetVersion() > base::win::VERSION_XP) { |
| 257 // Make sure that in Vista and Above we have the proper DACLs so | 213 // Make sure that in Vista and Above we have the proper DACLs so |
| 258 // the interactive user can launch it. | 214 // the interactive user can launch it. |
| 259 if (!FixDACLsForExecute(setup_path)) | 215 if (!FixDACLsForExecute(cmd_line->GetProgram())) |
| 260 NOTREACHED(); | 216 NOTREACHED(); |
| 261 } | 217 } |
| 262 | 218 |
| 263 DWORD console_id = ::WTSGetActiveConsoleSessionId(); | 219 DWORD console_id = ::WTSGetActiveConsoleSessionId(); |
| 264 if (console_id == 0xFFFFFFFF) { | 220 if (console_id == 0xFFFFFFFF) { |
| 265 PLOG(ERROR) << __FUNCTION__ << " failed to get active session id"; | 221 PLOG(ERROR) << __FUNCTION__ << " failed to get active session id"; |
| 266 return false; | 222 return false; |
| 267 } | 223 } |
| 268 HANDLE user_token; | 224 HANDLE user_token; |
| 269 if (!::WTSQueryUserToken(console_id, &user_token)) { | 225 if (!::WTSQueryUserToken(console_id, &user_token)) { |
| 270 PLOG(ERROR) << __FUNCTION__ << " failed to get user token for console_id " | 226 PLOG(ERROR) << __FUNCTION__ << " failed to get user token for console_id " |
| 271 << console_id; | 227 << console_id; |
| 272 return false; | 228 return false; |
| 273 } | 229 } |
| 274 // Note: Handle inheritance must be true in order for the child process to be | 230 // Note: Handle inheritance must be true in order for the child process to be |
| 275 // able to use the duplicated handle above (Google Update results). | 231 // able to use the duplicated handle above (Google Update results). |
| 276 base::LaunchOptions options; | 232 base::LaunchOptions options; |
| 277 options.as_user = user_token; | 233 options.as_user = user_token; |
| 278 options.inherit_handles = true; | 234 options.inherit_handles = true; |
| 279 options.empty_desktop_name = true; | 235 options.empty_desktop_name = true; |
| 280 VLOG(1) << __FUNCTION__ << " launching " << cmd_line.GetCommandLineString(); | 236 VLOG(1) << __FUNCTION__ << " launching " << cmd_line->GetCommandLineString(); |
| 281 bool launched = base::LaunchProcess(cmd_line, options, NULL); | 237 bool launched = base::LaunchProcess(*cmd_line, options, NULL); |
| 282 ::CloseHandle(user_token); | 238 ::CloseHandle(user_token); |
| 283 VLOG(1) << __FUNCTION__ << " result: " << launched; | 239 VLOG(1) << __FUNCTION__ << " result: " << launched; |
| 284 return launched; | 240 return launched; |
| 285 } | 241 } |
| 286 | 242 |
| 287 } // namespace | |
| 288 | |
| 289 GoogleChromeDistribution::GoogleChromeDistribution() | |
| 290 : BrowserDistribution(CHROME_BROWSER), | |
| 291 product_guid_(kChromeGuid) { | |
| 292 } | |
| 293 | |
| 294 bool GoogleChromeDistribution::BuildUninstallMetricsString( | |
| 295 const DictionaryValue* uninstall_metrics_dict, string16* metrics) { | |
| 296 DCHECK(NULL != metrics); | |
| 297 bool has_values = false; | |
| 298 | |
| 299 for (DictionaryValue::Iterator iter(*uninstall_metrics_dict); !iter.IsAtEnd(); | |
| 300 iter.Advance()) { | |
| 301 has_values = true; | |
| 302 metrics->append(L"&"); | |
| 303 metrics->append(UTF8ToWide(iter.key())); | |
| 304 metrics->append(L"="); | |
| 305 | |
| 306 std::string value; | |
| 307 iter.value().GetAsString(&value); | |
| 308 metrics->append(UTF8ToWide(value)); | |
| 309 } | |
| 310 | |
| 311 return has_values; | |
| 312 } | |
| 313 | |
| 314 bool GoogleChromeDistribution::ExtractUninstallMetricsFromFile( | |
| 315 const base::FilePath& file_path, | |
| 316 string16* uninstall_metrics_string) { | |
| 317 JSONFileValueSerializer json_serializer(file_path); | |
| 318 | |
| 319 std::string json_error_string; | |
| 320 scoped_ptr<Value> root(json_serializer.Deserialize(NULL, NULL)); | |
| 321 if (!root.get()) | |
| 322 return false; | |
| 323 | |
| 324 // Preferences should always have a dictionary root. | |
| 325 if (!root->IsType(Value::TYPE_DICTIONARY)) | |
| 326 return false; | |
| 327 | |
| 328 return ExtractUninstallMetrics(*static_cast<DictionaryValue*>(root.get()), | |
| 329 uninstall_metrics_string); | |
| 330 } | |
| 331 | |
| 332 bool GoogleChromeDistribution::ExtractUninstallMetrics( | |
| 333 const DictionaryValue& root, | |
| 334 string16* uninstall_metrics_string) { | |
| 335 // Make sure that the user wants us reporting metrics. If not, don't | |
| 336 // add our uninstall metrics. | |
| 337 bool metrics_reporting_enabled = false; | |
| 338 if (!root.GetBoolean(prefs::kMetricsReportingEnabled, | |
| 339 &metrics_reporting_enabled) || | |
| 340 !metrics_reporting_enabled) { | |
| 341 return false; | |
| 342 } | |
| 343 | |
| 344 const DictionaryValue* uninstall_metrics_dict = NULL; | |
| 345 if (!root.HasKey(installer::kUninstallMetricsName) || | |
| 346 !root.GetDictionary(installer::kUninstallMetricsName, | |
| 347 &uninstall_metrics_dict)) { | |
| 348 return false; | |
| 349 } | |
| 350 | |
| 351 if (!BuildUninstallMetricsString(uninstall_metrics_dict, | |
| 352 uninstall_metrics_string)) { | |
| 353 return false; | |
| 354 } | |
| 355 | |
| 356 return true; | |
| 357 } | |
| 358 | |
| 359 void GoogleChromeDistribution::DoPostUninstallOperations( | |
| 360 const Version& version, | |
| 361 const base::FilePath& local_data_path, | |
| 362 const string16& distribution_data) { | |
| 363 // Send the Chrome version and OS version as params to the form. | |
| 364 // It would be nice to send the locale, too, but I don't see an | |
| 365 // easy way to get that in the existing code. It's something we | |
| 366 // can add later, if needed. | |
| 367 // We depend on installed_version.GetString() not having spaces or other | |
| 368 // characters that need escaping: 0.2.13.4. Should that change, we will | |
| 369 // need to escape the string before using it in a URL. | |
| 370 const string16 kVersionParam = L"crversion"; | |
| 371 const string16 kOSParam = L"os"; | |
| 372 base::win::OSInfo::VersionNumber version_number = | |
| 373 base::win::OSInfo::GetInstance()->version_number(); | |
| 374 string16 os_version = base::StringPrintf(L"%d.%d.%d", | |
| 375 version_number.major, version_number.minor, version_number.build); | |
| 376 | |
| 377 base::FilePath iexplore; | |
| 378 if (!PathService::Get(base::DIR_PROGRAM_FILES, &iexplore)) | |
| 379 return; | |
| 380 | |
| 381 iexplore = iexplore.AppendASCII("Internet Explorer"); | |
| 382 iexplore = iexplore.AppendASCII("iexplore.exe"); | |
| 383 | |
| 384 string16 command = iexplore.value() + L" " + GetUninstallSurveyUrl() + | |
| 385 L"&" + kVersionParam + L"=" + UTF8ToWide(version.GetString()) + L"&" + | |
| 386 kOSParam + L"=" + os_version; | |
| 387 | |
| 388 string16 uninstall_metrics; | |
| 389 if (ExtractUninstallMetricsFromFile(local_data_path, &uninstall_metrics)) { | |
| 390 // The user has opted into anonymous usage data collection, so append | |
| 391 // metrics and distribution data. | |
| 392 command += uninstall_metrics; | |
| 393 if (!distribution_data.empty()) { | |
| 394 command += L"&"; | |
| 395 command += distribution_data; | |
| 396 } | |
| 397 } | |
| 398 | |
| 399 int pid = 0; | |
| 400 // The reason we use WMI to launch the process is because the uninstall | |
| 401 // process runs inside a Job object controlled by the shell. As long as there | |
| 402 // are processes running, the shell will not close the uninstall applet. WMI | |
| 403 // allows us to escape from the Job object so the applet will close. | |
| 404 installer::WMIProcess::Launch(command, &pid); | |
| 405 } | |
| 406 | |
| 407 string16 GoogleChromeDistribution::GetActiveSetupGuid() { | |
| 408 return product_guid(); | |
| 409 } | |
| 410 | |
| 411 string16 GoogleChromeDistribution::GetAppGuid() { | |
| 412 return product_guid(); | |
| 413 } | |
| 414 | |
| 415 string16 GoogleChromeDistribution::GetBaseAppName() { | |
| 416 // I'd really like to return L ## PRODUCT_FULLNAME_STRING; but that's no good | |
| 417 // since it'd be "Chromium" in a non-Chrome build, which isn't at all what I | |
| 418 // want. Sigh. | |
| 419 return L"Google Chrome"; | |
| 420 } | |
| 421 | |
| 422 string16 GoogleChromeDistribution::GetAppShortCutName() { | |
| 423 const string16& app_shortcut_name = | |
| 424 installer::GetLocalizedString(IDS_PRODUCT_NAME_BASE); | |
| 425 return app_shortcut_name; | |
| 426 } | |
| 427 | |
| 428 string16 GoogleChromeDistribution::GetAlternateApplicationName() { | |
| 429 const string16& alt_product_name = | |
| 430 installer::GetLocalizedString(IDS_OEM_MAIN_SHORTCUT_NAME_BASE); | |
| 431 return alt_product_name; | |
| 432 } | |
| 433 | |
| 434 string16 GoogleChromeDistribution::GetBaseAppId() { | |
| 435 return kBrowserAppId; | |
| 436 } | |
| 437 | |
| 438 string16 GoogleChromeDistribution::GetInstallSubDir() { | |
| 439 string16 sub_dir(installer::kGoogleChromeInstallSubDir1); | |
| 440 sub_dir.append(L"\\"); | |
| 441 sub_dir.append(installer::kGoogleChromeInstallSubDir2); | |
| 442 return sub_dir; | |
| 443 } | |
| 444 | |
| 445 string16 GoogleChromeDistribution::GetPublisherName() { | |
| 446 const string16& publisher_name = | |
| 447 installer::GetLocalizedString(IDS_ABOUT_VERSION_COMPANY_NAME_BASE); | |
| 448 return publisher_name; | |
| 449 } | |
| 450 | |
| 451 string16 GoogleChromeDistribution::GetAppDescription() { | |
| 452 const string16& app_description = | |
| 453 installer::GetLocalizedString(IDS_SHORTCUT_TOOLTIP_BASE); | |
| 454 return app_description; | |
| 455 } | |
| 456 | |
| 457 std::string GoogleChromeDistribution::GetSafeBrowsingName() { | |
| 458 return "googlechrome"; | |
| 459 } | |
| 460 | |
| 461 string16 GoogleChromeDistribution::GetStateKey() { | |
| 462 string16 key(google_update::kRegPathClientState); | |
| 463 key.append(L"\\"); | |
| 464 key.append(product_guid()); | |
| 465 return key; | |
| 466 } | |
| 467 | |
| 468 string16 GoogleChromeDistribution::GetStateMediumKey() { | |
| 469 string16 key(google_update::kRegPathClientStateMedium); | |
| 470 key.append(L"\\"); | |
| 471 key.append(product_guid()); | |
| 472 return key; | |
| 473 } | |
| 474 | |
| 475 string16 GoogleChromeDistribution::GetStatsServerURL() { | |
| 476 return L"https://clients4.google.com/firefox/metrics/collect"; | |
| 477 } | |
| 478 | |
| 479 std::string GoogleChromeDistribution::GetNetworkStatsServer() const { | |
| 480 return chrome_common_net::kEchoTestServerLocation; | |
| 481 } | |
| 482 | |
| 483 std::string GoogleChromeDistribution::GetHttpPipeliningTestServer() const { | |
| 484 return chrome_common_net::kPipelineTestServerBaseUrl; | |
| 485 } | |
| 486 | |
| 487 string16 GoogleChromeDistribution::GetDistributionData(HKEY root_key) { | |
| 488 string16 sub_key(google_update::kRegPathClientState); | |
| 489 sub_key.append(L"\\"); | |
| 490 sub_key.append(product_guid()); | |
| 491 | |
| 492 base::win::RegKey client_state_key(root_key, sub_key.c_str(), KEY_READ); | |
| 493 string16 result; | |
| 494 string16 brand_value; | |
| 495 if (client_state_key.ReadValue(google_update::kRegRLZBrandField, | |
| 496 &brand_value) == ERROR_SUCCESS) { | |
| 497 result = google_update::kRegRLZBrandField; | |
| 498 result.append(L"="); | |
| 499 result.append(brand_value); | |
| 500 result.append(L"&"); | |
| 501 } | |
| 502 | |
| 503 string16 client_value; | |
| 504 if (client_state_key.ReadValue(google_update::kRegClientField, | |
| 505 &client_value) == ERROR_SUCCESS) { | |
| 506 result.append(google_update::kRegClientField); | |
| 507 result.append(L"="); | |
| 508 result.append(client_value); | |
| 509 result.append(L"&"); | |
| 510 } | |
| 511 | |
| 512 string16 ap_value; | |
| 513 // If we fail to read the ap key, send up "&ap=" anyway to indicate | |
| 514 // that this was probably a stable channel release. | |
| 515 client_state_key.ReadValue(google_update::kRegApField, &ap_value); | |
| 516 result.append(google_update::kRegApField); | |
| 517 result.append(L"="); | |
| 518 result.append(ap_value); | |
| 519 | |
| 520 return result; | |
| 521 } | |
| 522 | |
| 523 string16 GoogleChromeDistribution::GetUninstallLinkName() { | |
| 524 const string16& link_name = | |
| 525 installer::GetLocalizedString(IDS_UNINSTALL_CHROME_BASE); | |
| 526 return link_name; | |
| 527 } | |
| 528 | |
| 529 string16 GoogleChromeDistribution::GetUninstallRegPath() { | |
| 530 return L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" | |
| 531 L"Google Chrome"; | |
| 532 } | |
| 533 | |
| 534 string16 GoogleChromeDistribution::GetVersionKey() { | |
| 535 string16 key(google_update::kRegPathClients); | |
| 536 key.append(L"\\"); | |
| 537 key.append(product_guid()); | |
| 538 return key; | |
| 539 } | |
| 540 | |
| 541 string16 GoogleChromeDistribution::GetIconFilename() { | |
| 542 return installer::kChromeExe; | |
| 543 } | |
| 544 | |
| 545 bool GoogleChromeDistribution::GetCommandExecuteImplClsid( | |
| 546 string16* handler_class_uuid) { | |
| 547 if (handler_class_uuid) | |
| 548 *handler_class_uuid = kCommandExecuteImplUuid; | |
| 549 return true; | |
| 550 } | |
| 551 | |
| 552 bool GoogleChromeDistribution::AppHostIsSupported() { | |
| 553 return true; | |
| 554 } | |
| 555 | |
| 556 // This method checks if we need to change "ap" key in Google Update to try | |
| 557 // full installer as fall back method in case incremental installer fails. | |
| 558 // - If incremental installer fails we append a magic string ("-full"), if | |
| 559 // it is not present already, so that Google Update server next time will send | |
| 560 // full installer to update Chrome on the local machine | |
| 561 // - If we are currently running full installer, we remove this magic | |
| 562 // string (if it is present) regardless of whether installer failed or not. | |
| 563 // There is no fall-back for full installer :) | |
| 564 void GoogleChromeDistribution::UpdateInstallStatus(bool system_install, | |
| 565 installer::ArchiveType archive_type, | |
| 566 installer::InstallStatus install_status) { | |
| 567 GoogleUpdateSettings::UpdateInstallStatus(system_install, | |
| 568 archive_type, InstallUtil::GetInstallReturnCode(install_status), | |
| 569 product_guid()); | |
| 570 } | |
| 571 | |
| 572 // A helper function that writes to HKLM if the handle was passed through the | 243 // A helper function that writes to HKLM if the handle was passed through the |
| 573 // command line, but HKCU otherwise. |experiment_group| is the value to write | 244 // command line, but HKCU otherwise. |experiment_group| is the value to write |
| 574 // and |last_write| is used when writing to HKLM to determine whether to close | 245 // and |last_write| is used when writing to HKLM to determine whether to close |
| 575 // the handle when done. | 246 // the handle when done. |
| 576 void SetClient(const string16& experiment_group, bool last_write) { | 247 void SetClient(const string16& experiment_group, bool last_write) { |
| 577 static int reg_key_handle = -1; | 248 static int reg_key_handle = -1; |
| 578 if (reg_key_handle == -1) { | 249 if (reg_key_handle == -1) { |
| 579 // If a specific Toast Results key handle (presumably to our HKLM key) was | 250 // If a specific Toast Results key handle (presumably to our HKLM key) was |
| 580 // passed in to the command line (such as for system level installs), we use | 251 // passed in to the command line (such as for system level installs), we use |
| 581 // it. Otherwise, we write to the key under HKCU. | 252 // it. Otherwise, we write to the key under HKCU. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 595 GoogleUpdateSettings::WriteGoogleUpdateSystemClientKey( | 266 GoogleUpdateSettings::WriteGoogleUpdateSystemClientKey( |
| 596 reg_key_handle, google_update::kRegClientField, experiment_group); | 267 reg_key_handle, google_update::kRegClientField, experiment_group); |
| 597 if (last_write) | 268 if (last_write) |
| 598 CloseHandle((HANDLE) reg_key_handle); | 269 CloseHandle((HANDLE) reg_key_handle); |
| 599 } else { | 270 } else { |
| 600 // Write to HKCU. | 271 // Write to HKCU. |
| 601 GoogleUpdateSettings::SetClient(experiment_group); | 272 GoogleUpdateSettings::SetClient(experiment_group); |
| 602 } | 273 } |
| 603 } | 274 } |
| 604 | 275 |
| 605 bool GoogleChromeDistribution::GetExperimentDetails( | 276 } // namespace |
| 606 UserExperiment* experiment, int flavor) { | 277 |
| 278 bool CreateExperimentDetails( | |
| 279 int flavor, | |
|
grt (UTC plus 2)
2013/03/12 14:32:18
nit: un-wrap this and the next line.
huangs
2013/03/12 18:03:07
Done.
| |
| 280 ExperimentDetails* experiment) { | |
| 607 struct FlavorDetails { | 281 struct FlavorDetails { |
| 608 int heading_id; | 282 int heading_id; |
| 609 int flags; | 283 int flags; |
| 610 }; | 284 }; |
| 611 // Maximum number of experiment flavors we support. | 285 // Maximum number of experiment flavors we support. |
| 612 static const int kMax = 4; | 286 static const int kMax = 4; |
| 613 // This struct determines which experiment flavors we show for each locale and | 287 // This struct determines which experiment flavors we show for each locale and |
| 614 // brand. | 288 // brand. |
| 615 // | 289 // |
| 616 // Plugin infobar experiment: | 290 // Plugin infobar experiment: |
| 617 // The experiment in 2011 used PIxx codes. | 291 // The experiment in 2011 used PIxx codes. |
| 618 // | 292 // |
| 619 // Inactive user toast experiment: | 293 // Inactive user toast experiment: |
| 620 // The experiment in Dec 2009 used TGxx and THxx. | 294 // The experiment in Dec 2009 used TGxx and THxx. |
| 621 // The experiment in Feb 2010 used TKxx and TLxx. | 295 // The experiment in Feb 2010 used TKxx and TLxx. |
| 622 // The experiment in Apr 2010 used TMxx and TNxx. | 296 // The experiment in Apr 2010 used TMxx and TNxx. |
| 623 // The experiment in Oct 2010 used TVxx TWxx TXxx TYxx. | 297 // The experiment in Oct 2010 used TVxx TWxx TXxx TYxx. |
| 624 // The experiment in Feb 2011 used SJxx SKxx SLxx SMxx. | 298 // The experiment in Feb 2011 used SJxx SKxx SLxx SMxx. |
| 625 // The experiment in Mar 2012 used ZAxx ZBxx ZCxx. | 299 // The experiment in Mar 2012 used ZAxx ZBxx ZCxx. |
| 626 // The experiment in Jan 2013 uses DAxx. | 300 // The experiment in Jan 2013 uses DAxx. |
| 627 using namespace attrition_experiments; | 301 using namespace attrition_experiments; |
| 628 | 302 |
| 629 static const struct UserExperimentDetails { | 303 static const struct UserExperimentSpecs { |
| 630 const wchar_t* locale; // Locale to show this experiment for (* for all). | 304 const wchar_t* locale; // Locale to show this experiment for (* for all). |
| 631 const wchar_t* brands; // Brand codes show this experiment for (* for all). | 305 const wchar_t* brands; // Brand codes show this experiment for (* for all). |
| 632 int control_group; // Size of the control group, in percentages. | 306 int control_group; // Size of the control group, in percentages. |
| 633 const wchar_t* prefix; // The two letter experiment code. The second letter | 307 const wchar_t* prefix; // The two letter experiment code. The second letter |
| 634 // will be incremented with the flavor. | 308 // will be incremented with the flavor. |
| 635 FlavorDetails flavors[kMax]; | 309 FlavorDetails flavors[kMax]; |
| 636 } kExperiments[] = { | 310 } kExperiments[] = { |
| 637 // The first match from top to bottom is used so this list should be ordered | 311 // The first match from top to bottom is used so this list should be ordered |
| 638 // most-specific rule first. | 312 // most-specific rule first. |
| 639 { L"*", L"GGRV", // All locales, GGRV is enterprise. | 313 { L"*", L"GGRV", // All locales, GGRV is enterprise. |
| 640 0, // 0 percent control group. | 314 0, // 0 percent control group. |
| 641 L"EA", // Experiment is EAxx, EBxx, etc. | 315 L"EA", // Experiment is EAxx, EBxx, etc. |
| 642 // No flavors means no experiment. | 316 // No flavors means no experiment. |
| 643 { { 0, 0 }, | 317 { { 0, 0 }, |
| 644 { 0, 0 }, | 318 { 0, 0 }, |
| 645 { 0, 0 }, | 319 { 0, 0 }, |
| 646 { 0, 0 } | 320 { 0, 0 } |
| 647 } | 321 } |
| 648 }, | 322 }, |
| 649 { L"*", L"*", // All locales, all brands. | 323 { L"*", L"*", // All locales, all brands. |
| 650 5, // 5 percent control group. | 324 5, // 5 percent control group. |
| 651 L"DA", // Experiment is DAxx. | 325 L"DA", // Experiment is DAxx. |
| 652 // One single flavor. | 326 // One single flavor. |
| 653 { { IDS_TRY_TOAST_HEADING3, kMakeDefault }, | 327 { { IDS_TRY_TOAST_HEADING3, kToastUiMakeDefault }, |
| 654 { 0, 0 }, | 328 { 0, 0 }, |
| 655 { 0, 0 }, | 329 { 0, 0 }, |
| 656 { 0, 0 } | 330 { 0, 0 } |
| 657 } | 331 } |
| 658 } | 332 } |
| 659 }; | 333 }; |
| 660 | 334 |
| 661 string16 locale; | 335 string16 locale; |
| 662 GoogleUpdateSettings::GetLanguage(&locale); | 336 GoogleUpdateSettings::GetLanguage(&locale); |
| 663 if (locale.empty() || (locale == ASCIIToWide("en"))) | 337 if (locale.empty() || (locale == ASCIIToWide("en"))) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 674 | 348 |
| 675 std::vector<string16> brand_codes; | 349 std::vector<string16> brand_codes; |
| 676 base::SplitString(kExperiments[i].brands, L',', &brand_codes); | 350 base::SplitString(kExperiments[i].brands, L',', &brand_codes); |
| 677 if (brand_codes.empty()) | 351 if (brand_codes.empty()) |
| 678 return false; | 352 return false; |
| 679 for (std::vector<string16>::iterator it = brand_codes.begin(); | 353 for (std::vector<string16>::iterator it = brand_codes.begin(); |
| 680 it != brand_codes.end(); ++it) { | 354 it != brand_codes.end(); ++it) { |
| 681 if (*it != brand && *it != L"*") | 355 if (*it != brand && *it != L"*") |
| 682 continue; | 356 continue; |
| 683 // We have found our match. | 357 // We have found our match. |
| 684 const UserExperimentDetails& match = kExperiments[i]; | 358 const UserExperimentSpecs& match = kExperiments[i]; |
| 685 // Find out how many flavors we have. Zero means no experiment. | 359 // Find out how many flavors we have. Zero means no experiment. |
| 686 int num_flavors = 0; | 360 int num_flavors = 0; |
| 687 while (match.flavors[num_flavors].heading_id) { ++num_flavors; } | 361 while (match.flavors[num_flavors].heading_id) { ++num_flavors; } |
| 688 if (!num_flavors) | 362 if (!num_flavors) |
| 689 return false; | 363 return false; |
| 690 | 364 |
| 691 if (flavor < 0) | 365 if (flavor < 0) |
| 692 flavor = base::RandInt(0, num_flavors - 1); | 366 flavor = base::RandInt(0, num_flavors - 1); |
| 693 experiment->flavor = flavor; | 367 experiment->flavor = flavor; |
| 694 experiment->heading = match.flavors[flavor].heading_id; | 368 experiment->heading = match.flavors[flavor].heading_id; |
| 695 experiment->control_group = match.control_group; | 369 experiment->control_group = match.control_group; |
| 696 const wchar_t prefix[] = { match.prefix[0], match.prefix[1] + flavor, 0 }; | 370 const wchar_t prefix[] = { match.prefix[0], match.prefix[1] + flavor, 0 }; |
| 697 experiment->prefix = prefix; | 371 experiment->prefix = prefix; |
| 698 experiment->flags = match.flavors[flavor].flags; | 372 experiment->flags = match.flavors[flavor].flags; |
| 699 return true; | 373 return true; |
| 700 } | 374 } |
| 701 } | 375 } |
| 702 | 376 |
| 703 return false; | 377 return false; |
| 704 } | 378 } |
| 705 | 379 |
| 706 // Currently we only have one experiment: the inactive user toast. Which only | 380 // Currently we only have one experiment: the inactive user toast. Which only |
| 707 // applies for users doing upgrades. | 381 // applies for users doing upgrades. |
| 708 | 382 |
| 709 // | |
| 710 // There are three scenarios when this function is called: | 383 // There are three scenarios when this function is called: |
| 711 // 1- Is a per-user-install and it updated: perform the experiment | 384 // 1- Is a per-user-install and it updated: perform the experiment |
| 712 // 2- Is a system-install and it updated : relaunch as the interactive user | 385 // 2- Is a system-install and it updated : relaunch as the interactive user |
| 713 // 3- It has been re-launched from the #2 case. In this case we enter | 386 // 3- It has been re-launched from the #2 case. In this case we enter |
| 714 // this function with |system_install| true and a REENTRY_SYS_UPDATE status. | 387 // this function with |system_install| true and a REENTRY_SYS_UPDATE status. |
| 715 void GoogleChromeDistribution::LaunchUserExperiment( | 388 void LaunchUserExperiment(const CommandLine& base_cmd_line, |
|
grt (UTC plus 2)
2013/03/12 14:32:18
This function seems specific to the browser now. I
huangs
2013/03/12 18:03:07
Done. Since BD is no longer required, also removi
| |
| 716 const base::FilePath& setup_path, installer::InstallStatus status, | 389 BrowserDistribution* dist, |
| 717 const Version& version, const installer::Product& product, | 390 installer::InstallStatus status, |
| 718 bool system_level) { | 391 bool system_level) { |
| 719 VLOG(1) << "LaunchUserExperiment status: " << status << " product: " | 392 VLOG(1) << "LaunchUserExperiment status: " << status << " product: " |
|
grt (UTC plus 2)
2013/03/12 14:32:18
I think it makes sense to move this logging into p
huangs
2013/03/12 18:03:07
Done.
| |
| 720 << product.distribution()->GetAppShortCutName() | 393 << dist->GetAppShortCutName() |
| 721 << " system_level: " << system_level; | 394 << " system_level: " << system_level; |
| 722 | 395 |
| 723 if (system_level) { | 396 if (system_level) { |
| 724 if (installer::NEW_VERSION_UPDATED == status) { | 397 if (installer::NEW_VERSION_UPDATED == status) { |
| 398 CommandLine cmd_line(base_cmd_line); | |
| 399 cmd_line.AppendSwitch(installer::switches::kSystemLevelToast); | |
| 725 // We need to relaunch as the interactive user. | 400 // We need to relaunch as the interactive user. |
| 726 LaunchSetupAsConsoleUser(setup_path, product, | 401 LaunchSetupAsConsoleUser(&cmd_line); |
| 727 installer::switches::kSystemLevelToast); | |
| 728 return; | 402 return; |
| 729 } | 403 } |
| 730 } else { | 404 } else { |
| 731 if ((installer::NEW_VERSION_UPDATED != status) && | 405 if ((installer::NEW_VERSION_UPDATED != status) && |
| 732 (installer::REENTRY_SYS_UPDATE != status)) { | 406 (installer::REENTRY_SYS_UPDATE != status)) { |
| 733 // We are not updating or in re-launch. Exit. | 407 // We are not updating or in re-launch. Exit. |
| 734 return; | 408 return; |
| 735 } | 409 } |
| 736 } | 410 } |
| 737 | 411 |
| 738 // The |flavor| value ends up being processed by TryChromeDialogView to show | 412 // The |flavor| value ends up being processed by TryChromeDialogView to show |
| 739 // different experiments. | 413 // different experiments. |
| 740 UserExperiment experiment; | 414 ExperimentDetails experiment; |
| 741 if (!GetExperimentDetails(&experiment, -1)) { | 415 if (!CreateExperimentDetails(-1, &experiment)) { |
| 742 VLOG(1) << "Failed to get experiment details."; | 416 VLOG(1) << "Failed to get experiment details."; |
| 743 return; | 417 return; |
| 744 } | 418 } |
| 745 int flavor = experiment.flavor; | 419 int flavor = experiment.flavor; |
| 746 string16 base_group = experiment.prefix; | 420 string16 base_group = experiment.prefix; |
| 747 | 421 |
| 748 string16 brand; | 422 string16 brand; |
| 749 if (GoogleUpdateSettings::GetBrand(&brand) && (brand == L"CHXX")) { | 423 if (GoogleUpdateSettings::GetBrand(&brand) && (brand == L"CHXX")) { |
| 750 // Testing only: the user automatically qualifies for the experiment. | 424 // Testing only: the user automatically qualifies for the experiment. |
| 751 VLOG(1) << "Experiment qualification bypass"; | 425 VLOG(1) << "Experiment qualification bypass"; |
| 752 } else { | 426 } else { |
| 753 // Check that the user was not already drafted in this experiment. | 427 // Check that the user was not already drafted in this experiment. |
| 754 string16 client; | 428 string16 client; |
| 755 GoogleUpdateSettings::GetClient(&client); | 429 GoogleUpdateSettings::GetClient(&client); |
| 756 if (client.size() > 2) { | 430 if (client.size() > 2) { |
| 757 if (base_group == client.substr(0, 2)) { | 431 if (base_group == client.substr(0, 2)) { |
| 758 VLOG(1) << "User already participated in this experiment"; | 432 VLOG(1) << "User already participated in this experiment"; |
| 759 return; | 433 return; |
| 760 } | 434 } |
| 761 } | 435 } |
| 762 // Check browser usage inactivity by the age of the last-write time of the | 436 // Check browser usage inactivity by the age of the last-write time of the |
| 763 // most recently-used chrome user data directory. | 437 // most recently-used chrome user data directory. |
| 764 std::vector<base::FilePath> user_data_dirs; | 438 std::vector<base::FilePath> user_data_dirs; |
| 765 product.GetUserDataPaths(&user_data_dirs); | 439 dist->GetUserDataPaths(&user_data_dirs); |
|
grt (UTC plus 2)
2013/03/12 14:32:18
Please call GetChromeUserDataPaths from helper.h d
huangs
2013/03/12 18:03:07
Done.
| |
| 766 int dir_age_hours = -1; | 440 int dir_age_hours = -1; |
| 767 for (size_t i = 0; i < user_data_dirs.size(); ++i) { | 441 for (size_t i = 0; i < user_data_dirs.size(); ++i) { |
| 768 int this_age = GetDirectoryWriteAgeInHours( | 442 int this_age = GetDirectoryWriteAgeInHours( |
| 769 user_data_dirs[i].value().c_str()); | 443 user_data_dirs[i].value().c_str()); |
| 770 if (this_age >= 0 && (dir_age_hours < 0 || this_age < dir_age_hours)) | 444 if (this_age >= 0 && (dir_age_hours < 0 || this_age < dir_age_hours)) |
| 771 dir_age_hours = this_age; | 445 dir_age_hours = this_age; |
| 772 } | 446 } |
| 773 | 447 |
| 774 const bool experiment_enabled = false; | 448 const bool experiment_enabled = false; |
| 775 const int kThirtyDays = 30 * 24; | 449 const int kThirtyDays = 30 * 24; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 797 return; | 471 return; |
| 798 } | 472 } |
| 799 } | 473 } |
| 800 | 474 |
| 801 VLOG(1) << "User drafted for toast experiment " << flavor; | 475 VLOG(1) << "User drafted for toast experiment " << flavor; |
| 802 SetClient(base_group + kToastExpBaseGroup, false); | 476 SetClient(base_group + kToastExpBaseGroup, false); |
| 803 // User level: The experiment needs to be performed in a different process | 477 // User level: The experiment needs to be performed in a different process |
| 804 // because google_update expects the upgrade process to be quick and nimble. | 478 // because google_update expects the upgrade process to be quick and nimble. |
| 805 // System level: We have already been relaunched, so we don't need to be | 479 // System level: We have already been relaunched, so we don't need to be |
| 806 // quick, but we relaunch to follow the exact same codepath. | 480 // quick, but we relaunch to follow the exact same codepath. |
| 807 CommandLine cmd_line(setup_path); | 481 CommandLine cmd_line(base_cmd_line); |
| 808 cmd_line.AppendSwitchASCII(installer::switches::kInactiveUserToast, | 482 cmd_line.AppendSwitchASCII(installer::switches::kInactiveUserToast, |
| 809 base::IntToString(flavor)); | 483 base::IntToString(flavor)); |
| 810 cmd_line.AppendSwitchASCII(installer::switches::kExperimentGroup, | 484 cmd_line.AppendSwitchASCII(installer::switches::kExperimentGroup, |
| 811 WideToASCII(base_group)); | 485 WideToASCII(base_group)); |
| 812 LaunchSetup(&cmd_line, product, system_level); | 486 LaunchSetup(&cmd_line, system_level); |
| 813 } | 487 } |
| 814 | 488 |
| 815 // User qualifies for the experiment. To test, use --try-chrome-again=|flavor| | 489 // User qualifies for the experiment. To test, use --try-chrome-again=|flavor| |
| 816 // as a parameter to chrome.exe. | 490 // as a parameter to chrome.exe. |
| 817 void GoogleChromeDistribution::InactiveUserToastExperiment(int flavor, | 491 void InactiveUserToastExperiment(BrowserDistribution* dist, |
| 818 const string16& experiment_group, | 492 int flavor, |
| 819 const installer::Product& installation, | 493 const string16& experiment_group, |
| 820 const base::FilePath& application_path) { | 494 const installer::Product& installation, |
| 495 const base::FilePath& application_path) { | |
| 821 // Add the 'welcome back' url for chrome to show. | 496 // Add the 'welcome back' url for chrome to show. |
| 822 CommandLine options(CommandLine::NO_PROGRAM); | 497 CommandLine options(CommandLine::NO_PROGRAM); |
| 823 options.AppendSwitchNative(switches::kTryChromeAgain, | 498 options.AppendSwitchNative(::switches::kTryChromeAgain, |
| 824 base::IntToString16(flavor)); | 499 base::IntToString16(flavor)); |
| 825 // Prepend the url with a space. | 500 // Prepend the url with a space. |
| 826 string16 url(GetWelcomeBackUrl()); | 501 string16 url(GetWelcomeBackUrl()); |
| 827 options.AppendArg("--"); | 502 options.AppendArg("--"); |
| 828 options.AppendArgNative(url); | 503 options.AppendArgNative(url); |
| 829 // The command line should now have the url added as: | 504 // The command line should now have the url added as: |
| 830 // "chrome.exe -- <url>" | 505 // "chrome.exe -- <url>" |
| 831 DCHECK_NE(string16::npos, | 506 DCHECK_NE(string16::npos, |
| 832 options.GetCommandLineString().find(L" -- " + url)); | 507 options.GetCommandLineString().find(L" -- " + url)); |
| 833 | 508 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 856 | 531 |
| 857 if (outcome != kToastExpUninstallGroup) | 532 if (outcome != kToastExpUninstallGroup) |
| 858 return; | 533 return; |
| 859 // The user wants to uninstall. This is a best effort operation. Note that | 534 // The user wants to uninstall. This is a best effort operation. Note that |
| 860 // we waited for chrome to exit so the uninstall would not detect chrome | 535 // we waited for chrome to exit so the uninstall would not detect chrome |
| 861 // running. | 536 // running. |
| 862 bool system_level_toast = CommandLine::ForCurrentProcess()->HasSwitch( | 537 bool system_level_toast = CommandLine::ForCurrentProcess()->HasSwitch( |
| 863 installer::switches::kSystemLevelToast); | 538 installer::switches::kSystemLevelToast); |
| 864 | 539 |
| 865 CommandLine cmd(InstallUtil::GetChromeUninstallCmd(system_level_toast, | 540 CommandLine cmd(InstallUtil::GetChromeUninstallCmd(system_level_toast, |
| 866 GetType())); | 541 dist->GetType())); |
|
grt (UTC plus 2)
2013/03/12 14:32:18
use installation.distribution()->GetType() here an
grt (UTC plus 2)
2013/03/12 19:36:18
ping
huangs
2013/03/14 17:20:44
Sorry, missed a spot. Done.
| |
| 867 base::LaunchProcess(cmd, base::LaunchOptions(), NULL); | 542 base::LaunchProcess(cmd, base::LaunchOptions(), NULL); |
| 868 } | 543 } |
| 869 | 544 |
| 870 bool GoogleChromeDistribution::ShouldSetExperimentLabels() { | 545 } // namespace installer |
| 871 return true; | |
| 872 } | |
| OLD | NEW |