Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator.cc

Issue 816403003: Make callers of CommandLine use it via the base:: namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 void StartupBrowserCreator::AddFirstRunTab(const GURL& url) { 265 void StartupBrowserCreator::AddFirstRunTab(const GURL& url) {
266 first_run_tabs_.push_back(url); 266 first_run_tabs_.push_back(url);
267 } 267 }
268 268
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 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) { 280 int* return_code) {
281
282 in_synchronous_profile_launch_ = 281 in_synchronous_profile_launch_ =
283 process_startup == chrome::startup::IS_PROCESS_STARTUP; 282 process_startup == chrome::startup::IS_PROCESS_STARTUP;
284 DCHECK(profile); 283 DCHECK(profile);
285 284
286 // Continue with the incognito profile from here on if Incognito mode 285 // Continue with the incognito profile from here on if Incognito mode
287 // is forced. 286 // is forced.
288 if (IncognitoModePrefs::ShouldLaunchIncognito(command_line, 287 if (IncognitoModePrefs::ShouldLaunchIncognito(command_line,
289 profile->GetPrefs())) { 288 profile->GetPrefs())) {
290 profile = profile->GetOffTheRecordProfile(); 289 profile = profile->GetOffTheRecordProfile();
291 } else if (command_line.HasSwitch(switches::kIncognito)) { 290 } else if (command_line.HasSwitch(switches::kIncognito)) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 PrefService* pref_service = g_browser_process->local_state(); 345 PrefService* pref_service = g_browser_process->local_state();
347 was_restarted = pref_service->GetBoolean(prefs::kWasRestarted); 346 was_restarted = pref_service->GetBoolean(prefs::kWasRestarted);
348 pref_service->SetBoolean(prefs::kWasRestarted, false); 347 pref_service->SetBoolean(prefs::kWasRestarted, false);
349 was_restarted_read_ = true; 348 was_restarted_read_ = true;
350 } 349 }
351 return was_restarted; 350 return was_restarted;
352 } 351 }
353 352
354 // static 353 // static
355 SessionStartupPref StartupBrowserCreator::GetSessionStartupPref( 354 SessionStartupPref StartupBrowserCreator::GetSessionStartupPref(
356 const CommandLine& command_line, 355 const base::CommandLine& command_line,
357 Profile* profile) { 356 Profile* profile) {
358 DCHECK(profile); 357 DCHECK(profile);
359 PrefService* prefs = profile->GetPrefs(); 358 PrefService* prefs = profile->GetPrefs();
360 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); 359 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs);
361 360
362 // IsChromeFirstRun() looks for a sentinel file to determine whether the user 361 // IsChromeFirstRun() looks for a sentinel file to determine whether the user
363 // is starting Chrome for the first time. On Chrome OS, the sentinel is stored 362 // is starting Chrome for the first time. On Chrome OS, the sentinel is stored
364 // in a location shared by all users and the check is meaningless. Query the 363 // in a location shared by all users and the check is meaningless. Query the
365 // UserManager instead to determine whether the user is new. 364 // UserManager instead to determine whether the user is new.
366 #if defined(OS_CHROMEOS) 365 #if defined(OS_CHROMEOS)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 return pref; 415 return pref;
417 } 416 }
418 417
419 // static 418 // static
420 void StartupBrowserCreator::ClearLaunchedProfilesForTesting() { 419 void StartupBrowserCreator::ClearLaunchedProfilesForTesting() {
421 profile_launch_observer.Get().Clear(); 420 profile_launch_observer.Get().Clear();
422 } 421 }
423 422
424 // static 423 // static
425 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( 424 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine(
426 const CommandLine& command_line, 425 const base::CommandLine& command_line,
427 const base::FilePath& cur_dir, 426 const base::FilePath& cur_dir,
428 Profile* profile) { 427 Profile* profile) {
429 std::vector<GURL> urls; 428 std::vector<GURL> urls;
430 429
431 const CommandLine::StringVector& params = command_line.GetArgs(); 430 const base::CommandLine::StringVector& params = command_line.GetArgs();
432 for (size_t i = 0; i < params.size(); ++i) { 431 for (size_t i = 0; i < params.size(); ++i) {
433 base::FilePath param = base::FilePath(params[i]); 432 base::FilePath param = base::FilePath(params[i]);
434 // Handle Vista way of searching - "? <search-term>" 433 // Handle Vista way of searching - "? <search-term>"
435 if ((param.value().size() > 2) && (param.value()[0] == '?') && 434 if ((param.value().size() > 2) && (param.value()[0] == '?') &&
436 (param.value()[1] == ' ')) { 435 (param.value()[1] == ' ')) {
437 GURL url(GetDefaultSearchURLForSearchTerms( 436 GURL url(GetDefaultSearchURLForSearchTerms(
438 TemplateURLServiceFactory::GetForProfile(profile), 437 TemplateURLServiceFactory::GetForProfile(profile),
439 param.LossyDisplayName().substr(2))); 438 param.LossyDisplayName().substr(2)));
440 if (url.is_valid()) { 439 if (url.is_valid()) {
441 urls.push_back(url); 440 urls.push_back(url);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 (url.spec().compare(url::kAboutBlankURL) == 0)) { 473 (url.spec().compare(url::kAboutBlankURL) == 0)) {
475 urls.push_back(url); 474 urls.push_back(url);
476 } 475 }
477 } 476 }
478 } 477 }
479 return urls; 478 return urls;
480 } 479 }
481 480
482 // static 481 // static
483 bool StartupBrowserCreator::ProcessCmdLineImpl( 482 bool StartupBrowserCreator::ProcessCmdLineImpl(
484 const CommandLine& command_line, 483 const base::CommandLine& command_line,
485 const base::FilePath& cur_dir, 484 const base::FilePath& cur_dir,
486 bool process_startup, 485 bool process_startup,
487 Profile* last_used_profile, 486 Profile* last_used_profile,
488 const Profiles& last_opened_profiles, 487 const Profiles& last_opened_profiles,
489 int* return_code, 488 int* return_code,
490 StartupBrowserCreator* browser_creator) { 489 StartupBrowserCreator* browser_creator) {
491 VLOG(2) << "ProcessCmdLineImpl : BEGIN"; 490 VLOG(2) << "ProcessCmdLineImpl : BEGIN";
492 DCHECK(last_used_profile); 491 DCHECK(last_used_profile);
493 if (process_startup) { 492 if (process_startup) {
494 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 493 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 // background page of apps. Tracked at http://crbug.com/175381 623 // background page of apps. Tracked at http://crbug.com/175381
625 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) 624 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0)
626 return true; 625 return true;
627 } 626 }
628 627
629 VLOG(2) << "ProcessCmdLineImpl: PLACE 4.B"; 628 VLOG(2) << "ProcessCmdLineImpl: PLACE 4.B";
630 // Check for --load-and-launch-app. 629 // Check for --load-and-launch-app.
631 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && 630 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) &&
632 !IncognitoModePrefs::ShouldLaunchIncognito( 631 !IncognitoModePrefs::ShouldLaunchIncognito(
633 command_line, last_used_profile->GetPrefs())) { 632 command_line, last_used_profile->GetPrefs())) {
634 CommandLine::StringType path = command_line.GetSwitchValueNative( 633 base::CommandLine::StringType path =
635 apps::kLoadAndLaunchApp); 634 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp);
636 635
637 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( 636 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch(
638 base::FilePath(path), command_line, cur_dir)) { 637 base::FilePath(path), command_line, cur_dir)) {
639 return false; 638 return false;
640 } 639 }
641 640
642 // Return early here since we don't want to open a browser window. 641 // Return early here since we don't want to open a browser window.
643 // The exception is when there are no browser windows, since we don't want 642 // The exception is when there are no browser windows, since we don't want
644 // chrome to shut down. 643 // chrome to shut down.
645 // TODO(jackhou): Do this properly once keep-alive is handled by the 644 // TODO(jackhou): Do this properly once keep-alive is handled by the
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 // when Chrome was closed. In this case, pick a different open profile 726 // when Chrome was closed. In this case, pick a different open profile
728 // to be the active one, since the Guest profile is never added to the list 727 // to be the active one, since the Guest profile is never added to the list
729 // of open profiles. 728 // of open profiles.
730 if (switches::IsNewAvatarMenu() && last_used_profile->IsGuestSession()) { 729 if (switches::IsNewAvatarMenu() && last_used_profile->IsGuestSession()) {
731 DCHECK(!last_opened_profiles[0]->IsGuestSession()); 730 DCHECK(!last_opened_profiles[0]->IsGuestSession());
732 last_used_profile = last_opened_profiles[0]; 731 last_used_profile = last_opened_profiles[0];
733 } 732 }
734 733
735 // Launch the last used profile with the full command line, and the other 734 // Launch the last used profile with the full command line, and the other
736 // opened profiles without the URLs to launch. 735 // opened profiles without the URLs to launch.
737 CommandLine command_line_without_urls(command_line.GetProgram()); 736 base::CommandLine command_line_without_urls(command_line.GetProgram());
738 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); 737 const base::CommandLine::SwitchMap& switches = command_line.GetSwitches();
739 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); 738 for (base::CommandLine::SwitchMap::const_iterator switch_it =
739 switches.begin();
740 switch_it != switches.end(); ++switch_it) { 740 switch_it != switches.end(); ++switch_it) {
741 command_line_without_urls.AppendSwitchNative(switch_it->first, 741 command_line_without_urls.AppendSwitchNative(switch_it->first,
742 switch_it->second); 742 switch_it->second);
743 } 743 }
744 VLOG(2) << "ProcessCmdLineImpl: PLACE 7.B"; 744 VLOG(2) << "ProcessCmdLineImpl: PLACE 7.B";
745 // Launch the profiles in the order they became active. 745 // Launch the profiles in the order they became active.
746 for (Profiles::const_iterator it = last_opened_profiles.begin(); 746 for (Profiles::const_iterator it = last_opened_profiles.begin();
747 it != last_opened_profiles.end(); ++it) { 747 it != last_opened_profiles.end(); ++it) {
748 DCHECK(!(*it)->IsGuestSession()); 748 DCHECK(!(*it)->IsGuestSession());
749 // Don't launch additional profiles which would only open a new tab 749 // Don't launch additional profiles which would only open a new tab
(...skipping 16 matching lines...) Expand all
766 VLOG(2) << "ProcessCmdLineImpl: PLACE 8.B"; 766 VLOG(2) << "ProcessCmdLineImpl: PLACE 8.B";
767 // This must be done after all profiles have been launched so the observer 767 // This must be done after all profiles have been launched so the observer
768 // knows about all profiles to wait for before activating this one. 768 // knows about all profiles to wait for before activating this one.
769 profile_launch_observer.Get().set_profile_to_activate(last_used_profile); 769 profile_launch_observer.Get().set_profile_to_activate(last_used_profile);
770 } 770 }
771 VLOG(2) << "ProcessCmdLineImpl: END"; 771 VLOG(2) << "ProcessCmdLineImpl: END";
772 return true; 772 return true;
773 } 773 }
774 774
775 // static 775 // static
776 bool StartupBrowserCreator::ProcessLoadApps(const CommandLine& command_line, 776 bool StartupBrowserCreator::ProcessLoadApps(
777 const base::FilePath& cur_dir, 777 const base::CommandLine& command_line,
778 Profile* profile) { 778 const base::FilePath& cur_dir,
779 CommandLine::StringType path_list = 779 Profile* profile) {
780 base::CommandLine::StringType path_list =
780 command_line.GetSwitchValueNative(extensions::switches::kLoadApps); 781 command_line.GetSwitchValueNative(extensions::switches::kLoadApps);
781 782
782 base::StringTokenizerT<CommandLine::StringType, 783 base::StringTokenizerT<base::CommandLine::StringType,
783 CommandLine::StringType::const_iterator> 784 base::CommandLine::StringType::const_iterator>
784 tokenizer(path_list, FILE_PATH_LITERAL(",")); 785 tokenizer(path_list, FILE_PATH_LITERAL(","));
785 786
786 if (!tokenizer.GetNext()) 787 if (!tokenizer.GetNext())
787 return false; 788 return false;
788 789
789 base::FilePath app_absolute_dir = 790 base::FilePath app_absolute_dir =
790 base::MakeAbsoluteFilePath(base::FilePath(tokenizer.token())); 791 base::MakeAbsoluteFilePath(base::FilePath(tokenizer.token()));
791 if (!apps::AppLoadService::Get(profile)->LoadAndLaunch( 792 if (!apps::AppLoadService::Get(profile)->LoadAndLaunch(
792 app_absolute_dir, command_line, cur_dir)) { 793 app_absolute_dir, command_line, cur_dir)) {
793 return false; 794 return false;
794 } 795 }
795 796
796 while (tokenizer.GetNext()) { 797 while (tokenizer.GetNext()) {
797 app_absolute_dir = 798 app_absolute_dir =
798 base::MakeAbsoluteFilePath(base::FilePath(tokenizer.token())); 799 base::MakeAbsoluteFilePath(base::FilePath(tokenizer.token()));
799 800
800 if (!apps::AppLoadService::Get(profile)->Load(app_absolute_dir)) { 801 if (!apps::AppLoadService::Get(profile)->Load(app_absolute_dir)) {
801 return false; 802 return false;
802 } 803 }
803 } 804 }
804 805
805 return true; 806 return true;
806 } 807 }
807 808
808 // static 809 // static
809 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( 810 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated(
810 const CommandLine& command_line, 811 const base::CommandLine& command_line,
811 const base::FilePath& cur_dir, 812 const base::FilePath& cur_dir,
812 Profile* profile, 813 Profile* profile,
813 Profile::CreateStatus status) { 814 Profile::CreateStatus status) {
814 if (status == Profile::CREATE_STATUS_INITIALIZED) 815 if (status == Profile::CREATE_STATUS_INITIALIZED)
815 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, 816 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL,
816 NULL); 817 NULL);
817 } 818 }
818 819
819 // static 820 // static
820 void StartupBrowserCreator::ProcessCommandLineAlreadyRunning( 821 void StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
821 const CommandLine& command_line, 822 const base::CommandLine& command_line,
822 const base::FilePath& cur_dir, 823 const base::FilePath& cur_dir,
823 const base::FilePath& profile_path) { 824 const base::FilePath& profile_path) {
824 ProfileManager* profile_manager = g_browser_process->profile_manager(); 825 ProfileManager* profile_manager = g_browser_process->profile_manager();
825 Profile* profile = profile_manager->GetProfileByPath(profile_path); 826 Profile* profile = profile_manager->GetProfileByPath(profile_path);
826 827
827 // The profile isn't loaded yet and so needs to be loaded asynchronously. 828 // The profile isn't loaded yet and so needs to be loaded asynchronously.
828 if (!profile) { 829 if (!profile) {
829 profile_manager->CreateProfileAsync(profile_path, 830 profile_manager->CreateProfileAsync(profile_path,
830 base::Bind(&StartupBrowserCreator::ProcessCommandLineOnProfileCreated, 831 base::Bind(&StartupBrowserCreator::ProcessCommandLineOnProfileCreated,
831 command_line, cur_dir), base::string16(), base::string16(), 832 command_line, cur_dir), base::string16(), base::string16(),
832 std::string()); 833 std::string());
833 return; 834 return;
834 } 835 }
835 836
836 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, 837 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL,
837 NULL); 838 NULL);
838 } 839 }
839 840
840 // static 841 // static
841 bool StartupBrowserCreator::ActivatedProfile() { 842 bool StartupBrowserCreator::ActivatedProfile() {
842 return profile_launch_observer.Get().activated_profile(); 843 return profile_launch_observer.Get().activated_profile();
843 } 844 }
844 845
845 bool HasPendingUncleanExit(Profile* profile) { 846 bool HasPendingUncleanExit(Profile* profile) {
846 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED && 847 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED &&
847 !profile_launch_observer.Get().HasBeenLaunched(profile); 848 !profile_launch_observer.Get().HasBeenLaunched(profile);
848 } 849 }
849 850
850 base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, 851 base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir,
851 const CommandLine& command_line) { 852 const base::CommandLine& command_line) {
852 if (command_line.HasSwitch(switches::kProfileDirectory)) { 853 if (command_line.HasSwitch(switches::kProfileDirectory)) {
853 return user_data_dir.Append( 854 return user_data_dir.Append(
854 command_line.GetSwitchValuePath(switches::kProfileDirectory)); 855 command_line.GetSwitchValuePath(switches::kProfileDirectory));
855 } 856 }
856 857
857 // If we are showing the app list then chrome isn't shown so load the app 858 // If we are showing the app list then chrome isn't shown so load the app
858 // list's profile rather than chrome's. 859 // list's profile rather than chrome's.
859 if (command_line.HasSwitch(switches::kShowAppList)) { 860 if (command_line.HasSwitch(switches::kShowAppList)) {
860 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> 861 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->
861 GetProfilePath(user_data_dir); 862 GetProfilePath(user_data_dir);
862 } 863 }
863 864
864 return g_browser_process->profile_manager()->GetLastUsedProfileDir( 865 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
865 user_data_dir); 866 user_data_dir);
866 } 867 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/bad_flags_prompt.cc ('k') | chrome/browser/ui/startup/startup_browser_creator_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698