| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 installer_util::GetDistroStringPreference(prefs.get(), | 393 installer_util::GetDistroStringPreference(prefs.get(), |
| 394 installer_util::master_preferences::kDistroImportBookmarksFromFilePref, | 394 installer_util::master_preferences::kDistroImportBookmarksFromFilePref, |
| 395 &import_bookmarks_path); | 395 &import_bookmarks_path); |
| 396 | 396 |
| 397 if (import_items || !import_bookmarks_path.empty()) { | 397 if (import_items || !import_bookmarks_path.empty()) { |
| 398 // There is something to import from the default browser. This launches | 398 // There is something to import from the default browser. This launches |
| 399 // the importer process and blocks until done or until it fails. | 399 // the importer process and blocks until done or until it fails. |
| 400 scoped_refptr<ImporterHost> importer_host = new ImporterHost(); | 400 scoped_refptr<ImporterHost> importer_host = new ImporterHost(); |
| 401 if (!FirstRun::ImportSettings(NULL, | 401 if (!FirstRun::ImportSettings(NULL, |
| 402 importer_host->GetSourceProfileInfoAt(0).browser_type, | 402 importer_host->GetSourceProfileInfoAt(0).browser_type, |
| 403 import_items, FilePath(import_bookmarks_path), NULL)) { | 403 import_items, FilePath(import_bookmarks_path), true, NULL)) { |
| 404 LOG(WARNING) << "silent import failed"; | 404 LOG(WARNING) << "silent import failed"; |
| 405 } | 405 } |
| 406 } | 406 } |
| 407 | 407 |
| 408 return false; | 408 return false; |
| 409 } | 409 } |
| 410 | 410 |
| 411 bool Upgrade::IsBrowserAlreadyRunning() { | 411 bool Upgrade::IsBrowserAlreadyRunning() { |
| 412 static HANDLE handle = NULL; | 412 static HANDLE handle = NULL; |
| 413 std::wstring exe; | 413 std::wstring exe; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 import_process_ = NULL; | 575 import_process_ = NULL; |
| 576 } | 576 } |
| 577 } | 577 } |
| 578 | 578 |
| 579 HWND owner_window_; | 579 HWND owner_window_; |
| 580 base::ProcessHandle import_process_; | 580 base::ProcessHandle import_process_; |
| 581 WorkerThreadTicker ticker_; | 581 WorkerThreadTicker ticker_; |
| 582 DISALLOW_COPY_AND_ASSIGN(HungImporterMonitor); | 582 DISALLOW_COPY_AND_ASSIGN(HungImporterMonitor); |
| 583 }; | 583 }; |
| 584 | 584 |
| 585 std::string EncodeImportParams(int browser_type, int options, HWND window) { | 585 std::string EncodeImportParams(int browser_type, int options, |
| 586 return StringPrintf("%d@%d@%d", browser_type, options, window); | 586 int skip_first_run_ui, HWND window) { |
| 587 return StringPrintf("%d@%d@%d@%d", browser_type, options, skip_first_run_ui, |
| 588 window); |
| 587 } | 589 } |
| 588 | 590 |
| 589 bool DecodeImportParams(const std::string& encoded, | 591 bool DecodeImportParams(const std::string& encoded, int* browser_type, |
| 590 int* browser_type, int* options, HWND* window) { | 592 int* options, int* skip_first_run_ui, HWND* window) { |
| 591 std::vector<std::string> parts; | 593 std::vector<std::string> parts; |
| 592 SplitString(encoded, '@', &parts); | 594 SplitString(encoded, '@', &parts); |
| 593 if (parts.size() != 3) | 595 if (parts.size() != 4) |
| 594 return false; | 596 return false; |
| 595 | 597 |
| 596 if (!base::StringToInt(parts[0], browser_type)) | 598 if (!base::StringToInt(parts[0], browser_type)) |
| 597 return false; | 599 return false; |
| 598 | 600 |
| 599 if (!base::StringToInt(parts[1], options)) | 601 if (!base::StringToInt(parts[1], options)) |
| 600 return false; | 602 return false; |
| 601 | 603 |
| 604 if (!base::StringToInt(parts[2], skip_first_run_ui)) |
| 605 return false; |
| 606 |
| 602 int64 window_int; | 607 int64 window_int; |
| 603 base::StringToInt64(parts[2], &window_int); | 608 base::StringToInt64(parts[3], &window_int); |
| 604 *window = reinterpret_cast<HWND>(window_int); | 609 *window = reinterpret_cast<HWND>(window_int); |
| 605 return true; | 610 return true; |
| 606 } | 611 } |
| 607 | 612 |
| 608 } // namespace | 613 } // namespace |
| 609 | 614 |
| 610 void FirstRun::AutoImport(Profile* profile, | 615 void FirstRun::AutoImport(Profile* profile, |
| 611 bool homepage_defined, | 616 bool homepage_defined, |
| 612 int import_items, | 617 int import_items, |
| 613 int dont_import_items, | 618 int dont_import_items, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 // Set the first run bubble to minimal. | 681 // Set the first run bubble to minimal. |
| 677 FirstRun::SetMinimalFirstRunBubblePref(); | 682 FirstRun::SetMinimalFirstRunBubblePref(); |
| 678 | 683 |
| 679 process_singleton->Unlock(); | 684 process_singleton->Unlock(); |
| 680 FirstRun::CreateSentinel(); | 685 FirstRun::CreateSentinel(); |
| 681 } | 686 } |
| 682 | 687 |
| 683 bool FirstRun::ImportSettings(Profile* profile, int browser_type, | 688 bool FirstRun::ImportSettings(Profile* profile, int browser_type, |
| 684 int items_to_import, | 689 int items_to_import, |
| 685 const FilePath& import_bookmarks_path, | 690 const FilePath& import_bookmarks_path, |
| 691 bool skip_first_run_ui, |
| 686 HWND parent_window) { | 692 HWND parent_window) { |
| 687 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); | 693 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); |
| 688 CommandLine import_cmd(cmdline.GetProgram()); | 694 CommandLine import_cmd(cmdline.GetProgram()); |
| 689 | 695 |
| 690 const char* kSwitchNames[] = { | 696 const char* kSwitchNames[] = { |
| 691 switches::kUserDataDir, | 697 switches::kUserDataDir, |
| 692 switches::kChromeFrame, | 698 switches::kChromeFrame, |
| 693 switches::kCountry, | 699 switches::kCountry, |
| 694 }; | 700 }; |
| 695 import_cmd.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames)); | 701 import_cmd.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames)); |
| 696 | 702 |
| 697 // Since ImportSettings is called before the local state is stored on disk | 703 // Since ImportSettings is called before the local state is stored on disk |
| 698 // we pass the language as an argument. GetApplicationLocale checks the | 704 // we pass the language as an argument. GetApplicationLocale checks the |
| 699 // current command line as fallback. | 705 // current command line as fallback. |
| 700 import_cmd.AppendSwitchASCII(switches::kLang, | 706 import_cmd.AppendSwitchASCII(switches::kLang, |
| 701 g_browser_process->GetApplicationLocale()); | 707 g_browser_process->GetApplicationLocale()); |
| 702 | 708 |
| 703 if (items_to_import) { | 709 if (items_to_import) { |
| 704 import_cmd.CommandLine::AppendSwitchASCII(switches::kImport, | 710 import_cmd.CommandLine::AppendSwitchASCII(switches::kImport, |
| 705 EncodeImportParams(browser_type, items_to_import, parent_window)); | 711 EncodeImportParams(browser_type, items_to_import, |
| 712 skip_first_run_ui ? 1 : 0, parent_window)); |
| 706 } | 713 } |
| 707 | 714 |
| 708 if (!import_bookmarks_path.empty()) { | 715 if (!import_bookmarks_path.empty()) { |
| 709 import_cmd.CommandLine::AppendSwitchPath( | 716 import_cmd.CommandLine::AppendSwitchPath( |
| 710 switches::kImportFromFile, import_bookmarks_path); | 717 switches::kImportFromFile, import_bookmarks_path); |
| 711 } | 718 } |
| 712 | 719 |
| 713 // Time to launch the process that is going to do the import. | 720 // Time to launch the process that is going to do the import. |
| 714 base::ProcessHandle import_process; | 721 base::ProcessHandle import_process; |
| 715 if (!base::LaunchApp(import_cmd, false, false, &import_process)) | 722 if (!base::LaunchApp(import_cmd, false, false, &import_process)) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 730 if (profile) | 737 if (profile) |
| 731 profile->GetPrefs()->ReloadPersistentPrefs(); | 738 profile->GetPrefs()->ReloadPersistentPrefs(); |
| 732 | 739 |
| 733 return (import_runner.exit_code() == ResultCodes::NORMAL_EXIT); | 740 return (import_runner.exit_code() == ResultCodes::NORMAL_EXIT); |
| 734 } | 741 } |
| 735 | 742 |
| 736 bool FirstRun::ImportSettings(Profile* profile, int browser_type, | 743 bool FirstRun::ImportSettings(Profile* profile, int browser_type, |
| 737 int items_to_import, | 744 int items_to_import, |
| 738 HWND parent_window) { | 745 HWND parent_window) { |
| 739 return ImportSettings(profile, browser_type, items_to_import, | 746 return ImportSettings(profile, browser_type, items_to_import, |
| 740 FilePath(), parent_window); | 747 FilePath(), false, parent_window); |
| 741 } | 748 } |
| 742 | 749 |
| 743 int FirstRun::ImportFromBrowser(Profile* profile, | 750 int FirstRun::ImportFromBrowser(Profile* profile, |
| 744 const CommandLine& cmdline) { | 751 const CommandLine& cmdline) { |
| 745 std::string import_info = cmdline.GetSwitchValueASCII(switches::kImport); | 752 std::string import_info = cmdline.GetSwitchValueASCII(switches::kImport); |
| 746 if (import_info.empty()) { | 753 if (import_info.empty()) { |
| 747 NOTREACHED(); | 754 NOTREACHED(); |
| 748 return false; | 755 return false; |
| 749 } | 756 } |
| 750 int browser_type = 0; | 757 int browser_type = 0; |
| 751 int items_to_import = 0; | 758 int items_to_import = 0; |
| 759 int skip_first_run_ui = 0; |
| 752 HWND parent_window = NULL; | 760 HWND parent_window = NULL; |
| 753 if (!DecodeImportParams(import_info, &browser_type, &items_to_import, | 761 if (!DecodeImportParams(import_info, &browser_type, &items_to_import, |
| 754 &parent_window)) { | 762 &skip_first_run_ui, &parent_window)) { |
| 755 NOTREACHED(); | 763 NOTREACHED(); |
| 756 return false; | 764 return false; |
| 757 } | 765 } |
| 758 scoped_refptr<ImporterHost> importer_host = new ImporterHost(); | 766 scoped_refptr<ImporterHost> importer_host = new ImporterHost(); |
| 759 FirstRunImportObserver observer; | 767 FirstRunImportObserver observer; |
| 760 | 768 |
| 761 // If there is no parent window, we run in headless mode which amounts | 769 // If |skip_first_run_ui|, we run in headless mode. This means that if |
| 762 // to having the windows hidden and if there is user action required the | 770 // there is user action required the import is automatically canceled. |
| 763 // import is automatically canceled. | 771 if (skip_first_run_ui > 0) |
| 764 if (!parent_window) | |
| 765 importer_host->set_headless(); | 772 importer_host->set_headless(); |
| 766 | 773 |
| 767 StartImportingWithUI( | 774 StartImportingWithUI( |
| 768 parent_window, | 775 parent_window, |
| 769 items_to_import, | 776 items_to_import, |
| 770 importer_host, | 777 importer_host, |
| 771 importer_host->GetSourceProfileInfoForBrowserType(browser_type), | 778 importer_host->GetSourceProfileInfoForBrowserType(browser_type), |
| 772 profile, | 779 profile, |
| 773 &observer, | 780 &observer, |
| 774 true); | 781 true); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 | 1064 |
| 1058 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { | 1065 Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { |
| 1059 if (version > 10000) { | 1066 if (version > 10000) { |
| 1060 // This is a test value. We want to make sure we exercise | 1067 // This is a test value. We want to make sure we exercise |
| 1061 // returning this early. See EarlyReturnTest test harness. | 1068 // returning this early. See EarlyReturnTest test harness. |
| 1062 return Upgrade::TD_NOT_NOW; | 1069 return Upgrade::TD_NOT_NOW; |
| 1063 } | 1070 } |
| 1064 TryChromeDialog td; | 1071 TryChromeDialog td; |
| 1065 return td.ShowModal(); | 1072 return td.ShowModal(); |
| 1066 } | 1073 } |
| OLD | NEW |