Chromium Code Reviews| 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/ui/startup/startup_browser_creator.h" | 5 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 6 | 6 |
| 7 #include <algorithm> // For max(). | 7 #include <algorithm> // For max(). |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "apps/app_load_service.h" | 10 #include "apps/app_load_service.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 23 #include "base/metrics/statistics_recorder.h" | 23 #include "base/metrics/statistics_recorder.h" |
| 24 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 25 #include "base/prefs/pref_service.h" | 25 #include "base/prefs/pref_service.h" |
| 26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/threading/thread_restrictions.h" | 29 #include "base/threading/thread_restrictions.h" |
| 30 #include "chrome/browser/app_mode/app_mode_utils.h" | 30 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 31 #include "chrome/browser/apps/install_chrome_app.h" | |
| 31 #include "chrome/browser/auto_launch_trial.h" | 32 #include "chrome/browser/auto_launch_trial.h" |
| 32 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 33 #include "chrome/browser/chrome_notification_types.h" | 34 #include "chrome/browser/chrome_notification_types.h" |
| 34 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 35 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 35 #include "chrome/browser/extensions/startup_helper.h" | 36 #include "chrome/browser/extensions/startup_helper.h" |
| 36 #include "chrome/browser/extensions/unpacked_installer.h" | 37 #include "chrome/browser/extensions/unpacked_installer.h" |
| 37 #include "chrome/browser/first_run/first_run.h" | 38 #include "chrome/browser/first_run/first_run.h" |
| 38 #include "chrome/browser/notifications/desktop_notification_service.h" | 39 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 39 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 40 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 40 #include "chrome/browser/prefs/session_startup_pref.h" | 41 #include "chrome/browser/prefs/session_startup_pref.h" |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 } | 501 } |
| 501 | 502 |
| 502 if (command_line.HasSwitch(switches::kInstallFromWebstore)) { | 503 if (command_line.HasSwitch(switches::kInstallFromWebstore)) { |
| 503 extensions::StartupHelper helper; | 504 extensions::StartupHelper helper; |
| 504 helper.InstallFromWebstore(command_line, last_used_profile); | 505 helper.InstallFromWebstore(command_line, last_used_profile); |
| 505 // Nothing more needs to be done, so return false to stop launching and | 506 // Nothing more needs to be done, so return false to stop launching and |
| 506 // quit. | 507 // quit. |
| 507 return false; | 508 return false; |
| 508 } | 509 } |
| 509 | 510 |
| 511 std::vector<GURL> extra_urls_to_launch; | |
|
tapted
2014/07/25 03:49:12
URLs are already added in StartupBrowserCreator::L
jackhou1
2014/07/28 02:58:15
I open up the webstore page because WebstoreStartu
| |
| 512 if (command_line.HasSwitch(switches::kInstallChromeApp)) { | |
| 513 extensions::StartupHelper helper; | |
| 514 helper.InstallChromeApp(command_line, last_used_profile); | |
| 515 extra_urls_to_launch.push_back(install_chrome_app::GetAppInstallUrl( | |
| 516 command_line.GetSwitchValueASCII(switches::kInstallChromeApp))); | |
| 517 } | |
| 518 | |
| 510 if (command_line.HasSwitch(switches::kValidateCrx)) { | 519 if (command_line.HasSwitch(switches::kValidateCrx)) { |
| 511 if (!process_startup) { | 520 if (!process_startup) { |
| 512 LOG(ERROR) << "chrome is already running; you must close all running " | 521 LOG(ERROR) << "chrome is already running; you must close all running " |
| 513 << "instances before running with the --" | 522 << "instances before running with the --" |
| 514 << switches::kValidateCrx << " flag"; | 523 << switches::kValidateCrx << " flag"; |
| 515 return false; | 524 return false; |
| 516 } | 525 } |
| 517 extensions::StartupHelper helper; | 526 extensions::StartupHelper helper; |
| 518 std::string message; | 527 std::string message; |
| 519 std::string error; | 528 std::string error; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 // background page of apps. Tracked at http://crbug.com/175381 | 611 // background page of apps. Tracked at http://crbug.com/175381 |
| 603 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) | 612 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) |
| 604 return true; | 613 return true; |
| 605 } | 614 } |
| 606 | 615 |
| 607 chrome::startup::IsProcessStartup is_process_startup = process_startup ? | 616 chrome::startup::IsProcessStartup is_process_startup = process_startup ? |
| 608 chrome::startup::IS_PROCESS_STARTUP : | 617 chrome::startup::IS_PROCESS_STARTUP : |
| 609 chrome::startup::IS_NOT_PROCESS_STARTUP; | 618 chrome::startup::IS_NOT_PROCESS_STARTUP; |
| 610 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? | 619 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? |
| 611 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 620 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 621 CommandLine command_line_with_extra_urls(command_line); | |
| 622 for (std::vector<GURL>::const_iterator it = extra_urls_to_launch.begin(); | |
| 623 it != extra_urls_to_launch.end(); | |
| 624 ++it) { | |
| 625 if (it->is_valid()) | |
| 626 command_line_with_extra_urls.AppendArg(it->spec()); | |
| 627 } | |
| 612 // |last_opened_profiles| will be empty in the following circumstances: | 628 // |last_opened_profiles| will be empty in the following circumstances: |
| 613 // - This is the first launch. |last_used_profile| is the initial profile. | 629 // - This is the first launch. |last_used_profile| is the initial profile. |
| 614 // - The user exited the browser by closing all windows for all | 630 // - The user exited the browser by closing all windows for all |
| 615 // profiles. |last_used_profile| is the profile which owned the last open | 631 // profiles. |last_used_profile| is the profile which owned the last open |
| 616 // window. | 632 // window. |
| 617 // - Only incognito windows were open when the browser exited. | 633 // - Only incognito windows were open when the browser exited. |
| 618 // |last_used_profile| is the last used incognito profile. Restoring it will | 634 // |last_used_profile| is the last used incognito profile. Restoring it will |
| 619 // create a browser window for the corresponding original profile. | 635 // create a browser window for the corresponding original profile. |
| 620 if (last_opened_profiles.empty()) { | 636 if (last_opened_profiles.empty()) { |
| 621 // If the last used profile is locked or was a guest, show the user manager. | 637 // If the last used profile is locked or was a guest, show the user manager. |
| 622 if (switches::IsNewProfileManagement()) { | 638 if (switches::IsNewProfileManagement()) { |
| 623 ProfileInfoCache& profile_info = | 639 ProfileInfoCache& profile_info = |
| 624 g_browser_process->profile_manager()->GetProfileInfoCache(); | 640 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 625 size_t profile_index = profile_info.GetIndexOfProfileWithPath( | 641 size_t profile_index = profile_info.GetIndexOfProfileWithPath( |
| 626 last_used_profile->GetPath()); | 642 last_used_profile->GetPath()); |
| 627 bool signin_required = profile_index != std::string::npos && | 643 bool signin_required = profile_index != std::string::npos && |
| 628 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); | 644 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); |
| 629 if (signin_required || last_used_profile->IsGuestSession()) { | 645 if (signin_required || last_used_profile->IsGuestSession()) { |
| 630 chrome::ShowUserManager(base::FilePath()); | 646 chrome::ShowUserManager(base::FilePath()); |
| 631 return true; | 647 return true; |
| 632 } | 648 } |
| 633 } | 649 } |
| 634 if (!browser_creator->LaunchBrowser(command_line, last_used_profile, | 650 if (!browser_creator->LaunchBrowser(command_line_with_extra_urls, |
| 651 last_used_profile, | |
| 635 cur_dir, is_process_startup, | 652 cur_dir, is_process_startup, |
| 636 is_first_run, return_code)) { | 653 is_first_run, return_code)) { |
| 637 return false; | 654 return false; |
| 638 } | 655 } |
| 639 } else { | 656 } else { |
| 640 // Launch the last used profile with the full command line, and the other | 657 // Launch the last used profile with the full command line, and the other |
| 641 // opened profiles without the URLs to launch. | 658 // opened profiles without the URLs to launch. |
| 642 CommandLine command_line_without_urls(command_line.GetProgram()); | 659 CommandLine command_line_without_urls(command_line.GetProgram()); |
| 643 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); | 660 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); |
| 644 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); | 661 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 658 startup_pref.type == SessionStartupPref::DEFAULT && | 675 startup_pref.type == SessionStartupPref::DEFAULT && |
| 659 !HasPendingUncleanExit(*it)) | 676 !HasPendingUncleanExit(*it)) |
| 660 continue; | 677 continue; |
| 661 | 678 |
| 662 // Don't re-open a browser window for the guest profile. | 679 // Don't re-open a browser window for the guest profile. |
| 663 if (switches::IsNewProfileManagement() && | 680 if (switches::IsNewProfileManagement() && |
| 664 (*it)->IsGuestSession()) | 681 (*it)->IsGuestSession()) |
| 665 continue; | 682 continue; |
| 666 | 683 |
| 667 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? | 684 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? |
| 668 command_line : command_line_without_urls, *it, cur_dir, | 685 command_line_with_extra_urls : command_line_without_urls, *it, |
| 669 is_process_startup, is_first_run, return_code)) | 686 cur_dir, is_process_startup, is_first_run, return_code)) |
| 670 return false; | 687 return false; |
| 671 // We've launched at least one browser. | 688 // We've launched at least one browser. |
| 672 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; | 689 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; |
| 673 } | 690 } |
| 674 // This must be done after all profiles have been launched so the observer | 691 // This must be done after all profiles have been launched so the observer |
| 675 // knows about all profiles to wait for before activating this one. | 692 // knows about all profiles to wait for before activating this one. |
| 676 | 693 |
| 677 // If the last used profile was the guest one, we didn't open it so | 694 // If the last used profile was the guest one, we didn't open it so |
| 678 // we don't need to activate it either. | 695 // we don't need to activate it either. |
| 679 if (!switches::IsNewProfileManagement() && | 696 if (!switches::IsNewProfileManagement() && |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 } | 752 } |
| 736 | 753 |
| 737 if (command_line.HasSwitch(switches::kProfileDirectory)) { | 754 if (command_line.HasSwitch(switches::kProfileDirectory)) { |
| 738 return user_data_dir.Append( | 755 return user_data_dir.Append( |
| 739 command_line.GetSwitchValuePath(switches::kProfileDirectory)); | 756 command_line.GetSwitchValuePath(switches::kProfileDirectory)); |
| 740 } | 757 } |
| 741 | 758 |
| 742 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 759 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| 743 user_data_dir); | 760 user_data_dir); |
| 744 } | 761 } |
| OLD | NEW |