| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/first_run/first_run.h" | 5 #include "chrome/browser/first_run/first_run.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 | 10 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 267 |
| 268 importer::ShowImportProgressDialog(static_cast<uint16>(items_to_import), | 268 importer::ShowImportProgressDialog(static_cast<uint16>(items_to_import), |
| 269 importer_host, &importer_observer, | 269 importer_host, &importer_observer, |
| 270 importer_list->GetSourceProfileForImporterType(importer_type), profile, | 270 importer_list->GetSourceProfileForImporterType(importer_type), profile, |
| 271 true); | 271 true); |
| 272 importer_observer.RunLoop(); | 272 importer_observer.RunLoop(); |
| 273 return importer_observer.import_result(); | 273 return importer_observer.import_result(); |
| 274 } | 274 } |
| 275 #endif // !defined(USE_AURA) | 275 #endif // !defined(USE_AURA) |
| 276 | 276 |
| 277 bool ImportSettingsWin(Profile* profile, | 277 bool ImportSettingsWin(int importer_type, |
| 278 int importer_type, | |
| 279 int items_to_import, | 278 int items_to_import, |
| 280 const base::FilePath& import_bookmarks_path, | 279 const base::FilePath& import_bookmarks_path, |
| 281 bool skip_first_run_ui) { | 280 bool skip_first_run_ui) { |
| 282 if (!items_to_import && import_bookmarks_path.empty()) { | 281 if (!items_to_import && import_bookmarks_path.empty()) { |
| 283 return true; | 282 return true; |
| 284 } | 283 } |
| 285 | 284 |
| 286 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); | 285 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); |
| 287 base::FilePath chrome_exe(cmdline.GetProgram()); | 286 base::FilePath chrome_exe(cmdline.GetProgram()); |
| 288 // |chrome_exe| cannot be a relative path as chrome.exe already changed its | 287 // |chrome_exe| cannot be a relative path as chrome.exe already changed its |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 325 |
| 327 // Time to launch the process that is going to do the import. | 326 // Time to launch the process that is going to do the import. |
| 328 base::ProcessHandle import_process; | 327 base::ProcessHandle import_process; |
| 329 if (!base::LaunchProcess(import_cmd, base::LaunchOptions(), &import_process)) | 328 if (!base::LaunchProcess(import_cmd, base::LaunchOptions(), &import_process)) |
| 330 return false; | 329 return false; |
| 331 | 330 |
| 332 // We block inside the import_runner ctor, pumping messages until the | 331 // We block inside the import_runner ctor, pumping messages until the |
| 333 // importer process ends. | 332 // importer process ends. |
| 334 ImportProcessRunner import_runner(import_process); | 333 ImportProcessRunner import_runner(import_process); |
| 335 | 334 |
| 336 // Import process finished. Reload the prefs, because importer may set | |
| 337 // the pref value. | |
| 338 if (profile) | |
| 339 profile->GetPrefs()->ReloadPersistentPrefs(); | |
| 340 | |
| 341 return (import_runner.exit_code() == content::RESULT_CODE_NORMAL_EXIT); | 335 return (import_runner.exit_code() == content::RESULT_CODE_NORMAL_EXIT); |
| 342 } | 336 } |
| 343 | 337 |
| 344 } // namespace | 338 } // namespace |
| 345 | 339 |
| 346 namespace first_run { | 340 namespace first_run { |
| 347 namespace internal { | 341 namespace internal { |
| 348 | 342 |
| 349 void DoPostImportPlatformSpecificTasks() { | 343 void DoPostImportPlatformSpecificTasks() { |
| 350 // Trigger the Active Setup command for system-level Chromes to finish | 344 // Trigger the Active Setup command for system-level Chromes to finish |
| 351 // configuring this user's install (e.g. per-user shortcuts). | 345 // configuring this user's install (e.g. per-user shortcuts). |
| 352 // Delay the task slightly to give Chrome launch I/O priority while also | 346 // Delay the task slightly to give Chrome launch I/O priority while also |
| 353 // making sure shortcuts are created promptly to avoid annoying the user by | 347 // making sure shortcuts are created promptly to avoid annoying the user by |
| 354 // re-creating shortcuts he previously deleted. | 348 // re-creating shortcuts he previously deleted. |
| 355 static const int64 kTiggerActiveSetupDelaySeconds = 5; | 349 static const int64 kTiggerActiveSetupDelaySeconds = 5; |
| 356 base::FilePath chrome_exe; | 350 base::FilePath chrome_exe; |
| 357 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 351 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 358 NOTREACHED(); | 352 NOTREACHED(); |
| 359 } else if (!InstallUtil::IsPerUserInstall(chrome_exe.value().c_str())) { | 353 } else if (!InstallUtil::IsPerUserInstall(chrome_exe.value().c_str())) { |
| 360 content::BrowserThread::GetBlockingPool()->PostDelayedTask( | 354 content::BrowserThread::GetBlockingPool()->PostDelayedTask( |
| 361 FROM_HERE, | 355 FROM_HERE, |
| 362 base::Bind(&InstallUtil::TriggerActiveSetupCommand), | 356 base::Bind(&InstallUtil::TriggerActiveSetupCommand), |
| 363 base::TimeDelta::FromSeconds(kTiggerActiveSetupDelaySeconds)); | 357 base::TimeDelta::FromSeconds(kTiggerActiveSetupDelaySeconds)); |
| 364 } | 358 } |
| 365 } | 359 } |
| 366 | 360 |
| 367 bool ImportSettings(Profile* profile, | |
| 368 scoped_refptr<ImporterHost> importer_host, | |
| 369 scoped_refptr<ImporterList> importer_list, | |
| 370 int items_to_import) { | |
| 371 return ImportSettingsWin( | |
| 372 profile, | |
| 373 importer_list->GetSourceProfileAt(0).importer_type, | |
| 374 items_to_import, | |
| 375 base::FilePath(), | |
| 376 false); | |
| 377 } | |
| 378 | |
| 379 bool GetFirstRunSentinelFilePath(base::FilePath* path) { | 361 bool GetFirstRunSentinelFilePath(base::FilePath* path) { |
| 380 return GetSentinelFilePath(chrome::kFirstRunSentinel, path); | 362 return GetSentinelFilePath(chrome::kFirstRunSentinel, path); |
| 381 } | 363 } |
| 382 | 364 |
| 383 void SetImportPreferencesAndLaunchImport( | 365 void SetImportPreferencesAndLaunchImport(MasterPrefs* out_prefs) { |
| 384 MasterPrefs* out_prefs, | |
| 385 installer::MasterPreferences* install_prefs) { | |
| 386 std::string import_bookmarks_path; | |
| 387 install_prefs->GetString( | |
| 388 installer::master_preferences::kDistroImportBookmarksFromFilePref, | |
| 389 &import_bookmarks_path); | |
| 390 | |
| 391 if (!IsOrganicFirstRun()) { | 366 if (!IsOrganicFirstRun()) { |
| 392 // If search engines aren't explicitly imported, don't import. | 367 // If search engines aren't explicitly imported, don't import. |
| 393 if (!(out_prefs->do_import_items & importer::SEARCH_ENGINES)) { | 368 if (!(out_prefs->do_import_items & importer::SEARCH_ENGINES)) { |
| 394 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; | 369 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; |
| 395 } | 370 } |
| 396 // If home page isn't explicitly imported, don't import. | 371 // If home page isn't explicitly imported, don't import. |
| 397 if (!(out_prefs->do_import_items & importer::HOME_PAGE)) { | 372 if (!(out_prefs->do_import_items & importer::HOME_PAGE)) { |
| 398 out_prefs->dont_import_items |= importer::HOME_PAGE; | 373 out_prefs->dont_import_items |= importer::HOME_PAGE; |
| 399 } | 374 } |
| 400 // If history isn't explicitly forbidden, do import. | 375 // If history isn't explicitly forbidden, do import. |
| 401 if (!(out_prefs->dont_import_items & importer::HISTORY)) { | 376 if (!(out_prefs->dont_import_items & importer::HISTORY)) { |
| 402 out_prefs->do_import_items |= importer::HISTORY; | 377 out_prefs->do_import_items |= importer::HISTORY; |
| 403 } | 378 } |
| 404 } | 379 } |
| 405 | 380 |
| 406 if (out_prefs->do_import_items || !import_bookmarks_path.empty()) { | 381 if (out_prefs->do_import_items || !out_prefs->import_bookmarks_path.empty()) { |
| 407 // There is something to import from the default browser. This launches | 382 // There is something to import from the default browser. This launches |
| 408 // the importer process and blocks until done or until it fails. | 383 // the importer process and blocks until done or until it fails. |
| 409 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); | 384 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); |
| 410 importer_list->DetectSourceProfilesHack(); | 385 importer_list->DetectSourceProfilesHack(); |
| 411 if (!ImportSettingsWin( | 386 internal::g_profile_import_exited_successfully = ImportSettingsWin( |
| 412 NULL, importer_list->GetSourceProfileAt(0).importer_type, | 387 importer_list->GetSourceProfileAt(0).importer_type, |
| 413 out_prefs->do_import_items, base::FilePath::FromWStringHack(UTF8ToWide( | 388 out_prefs->do_import_items, |
| 414 import_bookmarks_path)), true)) { | 389 base::FilePath::FromWStringHack(UTF8ToWide( |
| 390 out_prefs->import_bookmarks_path)), |
| 391 true); |
| 392 if (!internal::g_profile_import_exited_successfully) |
| 415 LOG(WARNING) << "silent import failed"; | 393 LOG(WARNING) << "silent import failed"; |
| 416 } | |
| 417 } | 394 } |
| 395 internal::g_did_perform_profile_import = true; |
| 418 } | 396 } |
| 419 | 397 |
| 420 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) { | 398 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) { |
| 421 if (IsEULANotAccepted(install_prefs)) { | 399 if (IsEULANotAccepted(install_prefs)) { |
| 422 // Show the post-installation EULA. This is done by setup.exe and the | 400 // Show the post-installation EULA. This is done by setup.exe and the |
| 423 // result determines if we continue or not. We wait here until the user | 401 // result determines if we continue or not. We wait here until the user |
| 424 // dismisses the dialog. | 402 // dismisses the dialog. |
| 425 | 403 |
| 426 // The actual eula text is in a resource in chrome. We extract it to | 404 // The actual eula text is in a resource in chrome. We extract it to |
| 427 // a text file so setup.exe can use it as an inner frame. | 405 // a text file so setup.exe can use it as an inner frame. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 443 |
| 466 base::FilePath MasterPrefsPath() { | 444 base::FilePath MasterPrefsPath() { |
| 467 // The standard location of the master prefs is next to the chrome binary. | 445 // The standard location of the master prefs is next to the chrome binary. |
| 468 base::FilePath master_prefs; | 446 base::FilePath master_prefs; |
| 469 if (!PathService::Get(base::DIR_EXE, &master_prefs)) | 447 if (!PathService::Get(base::DIR_EXE, &master_prefs)) |
| 470 return base::FilePath(); | 448 return base::FilePath(); |
| 471 return master_prefs.AppendASCII(installer::kDefaultMasterPrefs); | 449 return master_prefs.AppendASCII(installer::kDefaultMasterPrefs); |
| 472 } | 450 } |
| 473 | 451 |
| 474 } // namespace first_run | 452 } // namespace first_run |
| OLD | NEW |