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( | |
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()) { | |
392 // If search engines aren't explicitly imported, don't import. | |
393 if (!(out_prefs->do_import_items & importer::SEARCH_ENGINES)) { | |
394 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; | |
395 } | |
396 // If home page isn't explicitly imported, don't import. | |
397 if (!(out_prefs->do_import_items & importer::HOME_PAGE)) { | |
398 out_prefs->dont_import_items |= importer::HOME_PAGE; | |
399 } | |
400 // If history isn't explicitly forbidden, do import. | |
401 if (!(out_prefs->dont_import_items & importer::HISTORY)) { | |
402 out_prefs->do_import_items |= importer::HISTORY; | |
403 } | |
404 } | |
405 | |
406 if (out_prefs->do_import_items || !import_bookmarks_path.empty()) { | |
407 // There is something to import from the default browser. This launches | |
408 // the importer process and blocks until done or until it fails. | |
409 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); | |
410 importer_list->DetectSourceProfilesHack(); | |
411 if (!ImportSettingsWin( | |
412 NULL, importer_list->GetSourceProfileAt(0).importer_type, | |
413 out_prefs->do_import_items, base::FilePath::FromWStringHack(UTF8ToWide( | |
414 import_bookmarks_path)), true)) { | |
415 LOG(WARNING) << "silent import failed"; | |
416 } | |
417 } | |
418 } | |
419 | |
420 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) { | 365 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) { |
421 if (IsEULANotAccepted(install_prefs)) { | 366 if (IsEULANotAccepted(install_prefs)) { |
422 // Show the post-installation EULA. This is done by setup.exe and the | 367 // 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 | 368 // result determines if we continue or not. We wait here until the user |
424 // dismisses the dialog. | 369 // dismisses the dialog. |
425 | 370 |
426 // The actual eula text is in a resource in chrome. We extract it to | 371 // 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. | 372 // a text file so setup.exe can use it as an inner frame. |
428 base::FilePath inner_html; | 373 base::FilePath inner_html; |
429 if (WriteEULAtoTempFile(&inner_html)) { | 374 if (WriteEULAtoTempFile(&inner_html)) { |
(...skipping 26 matching lines...) Expand all Loading... |
456 int ImportNow(Profile* profile, const CommandLine& cmdline) { | 401 int ImportNow(Profile* profile, const CommandLine& cmdline) { |
457 int return_code = internal::ImportBookmarkFromFileIfNeeded(profile, cmdline); | 402 int return_code = internal::ImportBookmarkFromFileIfNeeded(profile, cmdline); |
458 #if !defined(USE_AURA) | 403 #if !defined(USE_AURA) |
459 if (cmdline.HasSwitch(switches::kImport)) { | 404 if (cmdline.HasSwitch(switches::kImport)) { |
460 return_code = ImportFromBrowser(profile, cmdline); | 405 return_code = ImportFromBrowser(profile, cmdline); |
461 } | 406 } |
462 #endif | 407 #endif |
463 return return_code; | 408 return return_code; |
464 } | 409 } |
465 | 410 |
| 411 // On Windows this is the complete import (i.e., AutoImport() is skipped). |
| 412 // TODO(gab): Merge this into AutoImport() as part of http://crbug.com/22142 |
| 413 void LaunchInitialImport(MasterPrefs* out_prefs) { |
| 414 if (!internal::IsOrganicFirstRun()) { |
| 415 // If search engines aren't explicitly imported, don't import. |
| 416 if (!(out_prefs->do_import_items & importer::SEARCH_ENGINES)) { |
| 417 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; |
| 418 } |
| 419 // If home page isn't explicitly imported, don't import. |
| 420 if (!(out_prefs->do_import_items & importer::HOME_PAGE)) { |
| 421 out_prefs->dont_import_items |= importer::HOME_PAGE; |
| 422 } |
| 423 // If history isn't explicitly forbidden, do import. |
| 424 if (!(out_prefs->dont_import_items & importer::HISTORY)) { |
| 425 out_prefs->do_import_items |= importer::HISTORY; |
| 426 } |
| 427 } |
| 428 |
| 429 if (out_prefs->do_import_items || !out_prefs->import_bookmarks_path.empty()) { |
| 430 // There is something to import from the default browser. This launches |
| 431 // the importer process and blocks until done or until it fails. |
| 432 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); |
| 433 importer_list->DetectSourceProfilesHack(); |
| 434 internal::g_profile_import_exited_successfully = ImportSettingsWin( |
| 435 importer_list->GetSourceProfileAt(0).importer_type, |
| 436 out_prefs->do_import_items, |
| 437 base::FilePath::FromWStringHack(UTF8ToWide( |
| 438 out_prefs->import_bookmarks_path)), |
| 439 true); |
| 440 if (!internal::g_profile_import_exited_successfully) |
| 441 LOG(WARNING) << "silent import failed"; |
| 442 } |
| 443 internal::g_did_perform_profile_import = true; |
| 444 } |
| 445 |
466 base::FilePath MasterPrefsPath() { | 446 base::FilePath MasterPrefsPath() { |
467 // The standard location of the master prefs is next to the chrome binary. | 447 // The standard location of the master prefs is next to the chrome binary. |
468 base::FilePath master_prefs; | 448 base::FilePath master_prefs; |
469 if (!PathService::Get(base::DIR_EXE, &master_prefs)) | 449 if (!PathService::Get(base::DIR_EXE, &master_prefs)) |
470 return base::FilePath(); | 450 return base::FilePath(); |
471 return master_prefs.AppendASCII(installer::kDefaultMasterPrefs); | 451 return master_prefs.AppendASCII(installer::kDefaultMasterPrefs); |
472 } | 452 } |
473 | 453 |
474 } // namespace first_run | 454 } // namespace first_run |
OLD | NEW |