| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // static | 269 // static |
| 270 bool StartupBrowserCreator::InSynchronousProfileLaunch() { | 270 bool StartupBrowserCreator::InSynchronousProfileLaunch() { |
| 271 return in_synchronous_profile_launch_; | 271 return in_synchronous_profile_launch_; |
| 272 } | 272 } |
| 273 | 273 |
| 274 bool StartupBrowserCreator::LaunchBrowser( | 274 bool StartupBrowserCreator::LaunchBrowser( |
| 275 const base::CommandLine& command_line, | 275 const base::CommandLine& command_line, |
| 276 Profile* profile, | 276 Profile* profile, |
| 277 const base::FilePath& cur_dir, | 277 const base::FilePath& cur_dir, |
| 278 chrome::startup::IsProcessStartup process_startup, | 278 chrome::startup::IsProcessStartup process_startup, |
| 279 chrome::startup::IsFirstRun is_first_run, | 279 chrome::startup::IsFirstRun is_first_run) { |
| 280 int* return_code) { | |
| 281 in_synchronous_profile_launch_ = | 280 in_synchronous_profile_launch_ = |
| 282 process_startup == chrome::startup::IS_PROCESS_STARTUP; | 281 process_startup == chrome::startup::IS_PROCESS_STARTUP; |
| 283 DCHECK(profile); | 282 DCHECK(profile); |
| 284 | 283 |
| 285 // Continue with the incognito profile from here on if Incognito mode | 284 // Continue with the incognito profile from here on if Incognito mode |
| 286 // is forced. | 285 // is forced. |
| 287 if (IncognitoModePrefs::ShouldLaunchIncognito(command_line, | 286 if (IncognitoModePrefs::ShouldLaunchIncognito(command_line, |
| 288 profile->GetPrefs())) { | 287 profile->GetPrefs())) { |
| 289 profile = profile->GetOffTheRecordProfile(); | 288 profile = profile->GetOffTheRecordProfile(); |
| 290 } else if (command_line.HasSwitch(switches::kIncognito)) { | 289 } else if (command_line.HasSwitch(switches::kIncognito)) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 313 if (ash::Shell::HasInstance()) | 312 if (ash::Shell::HasInstance()) |
| 314 host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; | 313 host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; |
| 315 #endif | 314 #endif |
| 316 | 315 |
| 317 const bool launched = lwp.Launch(profile, urls_to_launch, | 316 const bool launched = lwp.Launch(profile, urls_to_launch, |
| 318 in_synchronous_profile_launch_, | 317 in_synchronous_profile_launch_, |
| 319 host_desktop_type); | 318 host_desktop_type); |
| 320 in_synchronous_profile_launch_ = false; | 319 in_synchronous_profile_launch_ = false; |
| 321 if (!launched) { | 320 if (!launched) { |
| 322 LOG(ERROR) << "launch error"; | 321 LOG(ERROR) << "launch error"; |
| 323 if (return_code) | |
| 324 *return_code = chrome::RESULT_CODE_INVALID_CMDLINE_URL; | |
| 325 return false; | 322 return false; |
| 326 } | 323 } |
| 327 } else { | 324 } else { |
| 328 in_synchronous_profile_launch_ = false; | 325 in_synchronous_profile_launch_ = false; |
| 329 } | 326 } |
| 330 | 327 |
| 331 profile_launch_observer.Get().AddLaunched(profile); | 328 profile_launch_observer.Get().AddLaunched(profile); |
| 332 | 329 |
| 333 #if defined(OS_CHROMEOS) | 330 #if defined(OS_CHROMEOS) |
| 334 chromeos::ProfileHelper::Get()->ProfileStartup(profile, process_startup); | 331 chromeos::ProfileHelper::Get()->ProfileStartup(profile, process_startup); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 return urls; | 475 return urls; |
| 479 } | 476 } |
| 480 | 477 |
| 481 // static | 478 // static |
| 482 bool StartupBrowserCreator::ProcessCmdLineImpl( | 479 bool StartupBrowserCreator::ProcessCmdLineImpl( |
| 483 const base::CommandLine& command_line, | 480 const base::CommandLine& command_line, |
| 484 const base::FilePath& cur_dir, | 481 const base::FilePath& cur_dir, |
| 485 bool process_startup, | 482 bool process_startup, |
| 486 Profile* last_used_profile, | 483 Profile* last_used_profile, |
| 487 const Profiles& last_opened_profiles, | 484 const Profiles& last_opened_profiles, |
| 488 int* return_code, | |
| 489 StartupBrowserCreator* browser_creator) { | 485 StartupBrowserCreator* browser_creator) { |
| 490 VLOG(2) << "ProcessCmdLineImpl : BEGIN"; | 486 VLOG(2) << "ProcessCmdLineImpl : BEGIN"; |
| 491 DCHECK(last_used_profile); | 487 DCHECK(last_used_profile); |
| 492 if (process_startup) { | 488 if (process_startup) { |
| 493 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) | 489 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) |
| 494 content::NavigationController::DisablePromptOnRepost(); | 490 content::NavigationController::DisablePromptOnRepost(); |
| 495 } | 491 } |
| 496 | 492 |
| 497 bool silent_launch = false; | 493 bool silent_launch = false; |
| 498 | 494 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 } | 708 } |
| 713 } | 709 } |
| 714 | 710 |
| 715 VLOG(2) << "ProcessCmdLineImpl: PLACE 7.A"; | 711 VLOG(2) << "ProcessCmdLineImpl: PLACE 7.A"; |
| 716 Profile* profile_to_open = last_used_profile->IsGuestSession() ? | 712 Profile* profile_to_open = last_used_profile->IsGuestSession() ? |
| 717 last_used_profile->GetOffTheRecordProfile() : last_used_profile; | 713 last_used_profile->GetOffTheRecordProfile() : last_used_profile; |
| 718 | 714 |
| 719 VLOG(2) << "ProcessCmdLineImpl: PLACE 8.A"; | 715 VLOG(2) << "ProcessCmdLineImpl: PLACE 8.A"; |
| 720 if (!browser_creator->LaunchBrowser(command_line, profile_to_open, | 716 if (!browser_creator->LaunchBrowser(command_line, profile_to_open, |
| 721 cur_dir, is_process_startup, | 717 cur_dir, is_process_startup, |
| 722 is_first_run, return_code)) { | 718 is_first_run)) { |
| 723 return false; | 719 return false; |
| 724 } | 720 } |
| 725 } else { | 721 } else { |
| 726 VLOG(2) << "ProcessCmdLineImpl: PLACE 6.B"; | 722 VLOG(2) << "ProcessCmdLineImpl: PLACE 6.B"; |
| 727 // Guest profiles should not be reopened on startup. This can happen if | 723 // Guest profiles should not be reopened on startup. This can happen if |
| 728 // the last used profile was a Guest, but other profiles were also open | 724 // the last used profile was a Guest, but other profiles were also open |
| 729 // when Chrome was closed. In this case, pick a different open profile | 725 // when Chrome was closed. In this case, pick a different open profile |
| 730 // to be the active one, since the Guest profile is never added to the list | 726 // to be the active one, since the Guest profile is never added to the list |
| 731 // of open profiles. | 727 // of open profiles. |
| 732 if (switches::IsNewAvatarMenu() && last_used_profile->IsGuestSession()) { | 728 if (switches::IsNewAvatarMenu() && last_used_profile->IsGuestSession()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 754 // open pages. | 750 // open pages. |
| 755 SessionStartupPref startup_pref = | 751 SessionStartupPref startup_pref = |
| 756 GetSessionStartupPref(command_line, *it); | 752 GetSessionStartupPref(command_line, *it); |
| 757 if (*it != last_used_profile && | 753 if (*it != last_used_profile && |
| 758 startup_pref.type == SessionStartupPref::DEFAULT && | 754 startup_pref.type == SessionStartupPref::DEFAULT && |
| 759 !HasPendingUncleanExit(*it)) | 755 !HasPendingUncleanExit(*it)) |
| 760 continue; | 756 continue; |
| 761 | 757 |
| 762 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? | 758 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? |
| 763 command_line : command_line_without_urls, *it, cur_dir, | 759 command_line : command_line_without_urls, *it, cur_dir, |
| 764 is_process_startup, is_first_run, return_code)) | 760 is_process_startup, is_first_run)) |
| 765 return false; | 761 return false; |
| 766 // We've launched at least one browser. | 762 // We've launched at least one browser. |
| 767 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; | 763 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; |
| 768 } | 764 } |
| 769 VLOG(2) << "ProcessCmdLineImpl: PLACE 8.B"; | 765 VLOG(2) << "ProcessCmdLineImpl: PLACE 8.B"; |
| 770 // This must be done after all profiles have been launched so the observer | 766 // This must be done after all profiles have been launched so the observer |
| 771 // knows about all profiles to wait for before activating this one. | 767 // knows about all profiles to wait for before activating this one. |
| 772 profile_launch_observer.Get().set_profile_to_activate(last_used_profile); | 768 profile_launch_observer.Get().set_profile_to_activate(last_used_profile); |
| 773 } | 769 } |
| 774 VLOG(2) << "ProcessCmdLineImpl: END"; | 770 VLOG(2) << "ProcessCmdLineImpl: END"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 | 804 |
| 809 return true; | 805 return true; |
| 810 } | 806 } |
| 811 | 807 |
| 812 // static | 808 // static |
| 813 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( | 809 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( |
| 814 const base::CommandLine& command_line, | 810 const base::CommandLine& command_line, |
| 815 const base::FilePath& cur_dir, | 811 const base::FilePath& cur_dir, |
| 816 Profile* profile, | 812 Profile* profile, |
| 817 Profile::CreateStatus status) { | 813 Profile::CreateStatus status) { |
| 818 if (status == Profile::CREATE_STATUS_INITIALIZED) | 814 if (status != Profile::CREATE_STATUS_INITIALIZED) |
| 819 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, | 815 return; |
| 820 NULL); | 816 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL); |
| 821 } | 817 } |
| 822 | 818 |
| 823 // static | 819 // static |
| 824 void StartupBrowserCreator::ProcessCommandLineAlreadyRunning( | 820 void StartupBrowserCreator::ProcessCommandLineAlreadyRunning( |
| 825 const base::CommandLine& command_line, | 821 const base::CommandLine& command_line, |
| 826 const base::FilePath& cur_dir, | 822 const base::FilePath& cur_dir, |
| 827 const base::FilePath& profile_path) { | 823 const base::FilePath& profile_path) { |
| 828 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 824 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 829 Profile* profile = profile_manager->GetProfileByPath(profile_path); | 825 Profile* profile = profile_manager->GetProfileByPath(profile_path); |
| 830 | 826 |
| 831 // The profile isn't loaded yet and so needs to be loaded asynchronously. | 827 // The profile isn't loaded yet and so needs to be loaded asynchronously. |
| 832 if (!profile) { | 828 if (!profile) { |
| 833 profile_manager->CreateProfileAsync(profile_path, | 829 profile_manager->CreateProfileAsync(profile_path, |
| 834 base::Bind(&StartupBrowserCreator::ProcessCommandLineOnProfileCreated, | 830 base::Bind(&StartupBrowserCreator::ProcessCommandLineOnProfileCreated, |
| 835 command_line, cur_dir), base::string16(), base::string16(), | 831 command_line, cur_dir), base::string16(), base::string16(), |
| 836 std::string()); | 832 std::string()); |
| 837 return; | 833 return; |
| 838 } | 834 } |
| 839 | 835 |
| 840 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, | 836 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL); |
| 841 NULL); | |
| 842 } | 837 } |
| 843 | 838 |
| 844 // static | 839 // static |
| 845 bool StartupBrowserCreator::ActivatedProfile() { | 840 bool StartupBrowserCreator::ActivatedProfile() { |
| 846 return profile_launch_observer.Get().activated_profile(); | 841 return profile_launch_observer.Get().activated_profile(); |
| 847 } | 842 } |
| 848 | 843 |
| 849 bool HasPendingUncleanExit(Profile* profile) { | 844 bool HasPendingUncleanExit(Profile* profile) { |
| 850 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED && | 845 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED && |
| 851 !profile_launch_observer.Get().HasBeenLaunched(profile); | 846 !profile_launch_observer.Get().HasBeenLaunched(profile); |
| 852 } | 847 } |
| 853 | 848 |
| 854 base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, | 849 base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, |
| 855 const base::CommandLine& command_line) { | 850 const base::CommandLine& command_line) { |
| 856 if (command_line.HasSwitch(switches::kProfileDirectory)) { | 851 if (command_line.HasSwitch(switches::kProfileDirectory)) { |
| 857 return user_data_dir.Append( | 852 return user_data_dir.Append( |
| 858 command_line.GetSwitchValuePath(switches::kProfileDirectory)); | 853 command_line.GetSwitchValuePath(switches::kProfileDirectory)); |
| 859 } | 854 } |
| 860 | 855 |
| 861 // If we are showing the app list then chrome isn't shown so load the app | 856 // If we are showing the app list then chrome isn't shown so load the app |
| 862 // list's profile rather than chrome's. | 857 // list's profile rather than chrome's. |
| 863 if (command_line.HasSwitch(switches::kShowAppList)) { | 858 if (command_line.HasSwitch(switches::kShowAppList)) { |
| 864 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> | 859 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> |
| 865 GetProfilePath(user_data_dir); | 860 GetProfilePath(user_data_dir); |
| 866 } | 861 } |
| 867 | 862 |
| 868 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 863 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| 869 user_data_dir); | 864 user_data_dir); |
| 870 } | 865 } |
| OLD | NEW |