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

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

Issue 12674028: Report text output and exit code for command-line operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forgotten review responses. Created 7 years, 8 months 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 | Annotate | Revision Log
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 "base/bind.h" 10 #include "base/bind.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/browser/automation/automation_provider_list.h" 29 #include "chrome/browser/automation/automation_provider_list.h"
30 #include "chrome/browser/automation/testing_automation_provider.h" 30 #include "chrome/browser/automation/testing_automation_provider.h"
31 #include "chrome/browser/browser_process.h" 31 #include "chrome/browser/browser_process.h"
32 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 32 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
33 #include "chrome/browser/extensions/startup_helper.h" 33 #include "chrome/browser/extensions/startup_helper.h"
34 #include "chrome/browser/extensions/unpacked_installer.h" 34 #include "chrome/browser/extensions/unpacked_installer.h"
35 #include "chrome/browser/first_run/first_run.h" 35 #include "chrome/browser/first_run/first_run.h"
36 #include "chrome/browser/google/google_util.h" 36 #include "chrome/browser/google/google_util.h"
37 #include "chrome/browser/net/url_fixer_upper.h" 37 #include "chrome/browser/net/url_fixer_upper.h"
38 #include "chrome/browser/notifications/desktop_notification_service.h" 38 #include "chrome/browser/notifications/desktop_notification_service.h"
39 #include "chrome/browser/operation_output.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"
41 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 42 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
42 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 43 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
43 #include "chrome/browser/printing/print_dialog_cloud.h" 44 #include "chrome/browser/printing/print_dialog_cloud.h"
44 #include "chrome/browser/profiles/profile.h" 45 #include "chrome/browser/profiles/profile.h"
45 #include "chrome/browser/profiles/profile_manager.h" 46 #include "chrome/browser/profiles/profile_manager.h"
46 #include "chrome/browser/search_engines/template_url.h" 47 #include "chrome/browser/search_engines/template_url.h"
47 #include "chrome/browser/search_engines/template_url_service.h" 48 #include "chrome/browser/search_engines/template_url_service.h"
48 #include "chrome/browser/search_engines/template_url_service_factory.h" 49 #include "chrome/browser/search_engines/template_url_service_factory.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // static 234 // static
234 bool StartupBrowserCreator::was_restarted_read_ = false; 235 bool StartupBrowserCreator::was_restarted_read_ = false;
235 236
236 // static 237 // static
237 bool StartupBrowserCreator::in_synchronous_profile_launch_ = false; 238 bool StartupBrowserCreator::in_synchronous_profile_launch_ = false;
238 239
239 void StartupBrowserCreator::AddFirstRunTab(const GURL& url) { 240 void StartupBrowserCreator::AddFirstRunTab(const GURL& url) {
240 first_run_tabs_.push_back(url); 241 first_run_tabs_.push_back(url);
241 } 242 }
242 243
244 bool StartupBrowserCreator::Start(
245 const CommandLine& cmd_line,
246 const base::FilePath& cur_dir,
247 Profile* last_used_profile,
248 const Profiles& last_opened_profiles,
249 scoped_ptr<OperationOutput> operation_output) {
250 return ProcessCmdLineImpl(cmd_line, cur_dir, true, last_used_profile,
251 last_opened_profiles, this,
252 operation_output.Pass());
253 }
254
243 // static 255 // static
244 bool StartupBrowserCreator::InSynchronousProfileLaunch() { 256 bool StartupBrowserCreator::InSynchronousProfileLaunch() {
245 return in_synchronous_profile_launch_; 257 return in_synchronous_profile_launch_;
246 } 258 }
247 259
248 bool StartupBrowserCreator::LaunchBrowser( 260 bool StartupBrowserCreator::LaunchBrowser(
249 const CommandLine& command_line, 261 const CommandLine& command_line,
250 Profile* profile, 262 Profile* profile,
251 const base::FilePath& cur_dir, 263 const base::FilePath& cur_dir,
252 chrome::startup::IsProcessStartup process_startup, 264 chrome::startup::IsProcessStartup process_startup,
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 return urls; 435 return urls;
424 } 436 }
425 437
426 // static 438 // static
427 bool StartupBrowserCreator::ProcessCmdLineImpl( 439 bool StartupBrowserCreator::ProcessCmdLineImpl(
428 const CommandLine& command_line, 440 const CommandLine& command_line,
429 const base::FilePath& cur_dir, 441 const base::FilePath& cur_dir,
430 bool process_startup, 442 bool process_startup,
431 Profile* last_used_profile, 443 Profile* last_used_profile,
432 const Profiles& last_opened_profiles, 444 const Profiles& last_opened_profiles,
433 int* return_code, 445 StartupBrowserCreator* browser_creator,
434 StartupBrowserCreator* browser_creator) { 446 scoped_ptr<OperationOutput> operation_output) {
435 DCHECK(last_used_profile); 447 DCHECK(last_used_profile);
436 if (process_startup) { 448 if (process_startup) {
437 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 449 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
438 content::NavigationController::DisablePromptOnRepost(); 450 content::NavigationController::DisablePromptOnRepost();
439 } 451 }
440 452
453 // TODO(erikwright): Remove before committing.
454 if (command_line.HasSwitch("greetings")) {
455 if (operation_output) {
456 std::string hello_world("hello world!");
457 operation_output->Write(hello_world.c_str(), hello_world.length());
458 OperationOutput::Complete(operation_output.Pass(), 42);
459 }
460
461 return false;
462 }
463
441 bool silent_launch = false; 464 bool silent_launch = false;
442 465
443 #if defined(ENABLE_AUTOMATION) 466 #if defined(ENABLE_AUTOMATION)
444 // Look for the testing channel ID ONLY during process startup 467 // Look for the testing channel ID ONLY during process startup
445 if (process_startup && 468 if (process_startup &&
446 command_line.HasSwitch(switches::kTestingChannelID)) { 469 command_line.HasSwitch(switches::kTestingChannelID)) {
447 std::string testing_channel_id = command_line.GetSwitchValueASCII( 470 std::string testing_channel_id = command_line.GetSwitchValueASCII(
448 switches::kTestingChannelID); 471 switches::kTestingChannelID);
449 // TODO(sanjeevr) Check if we need to make this a singleton for 472 // TODO(sanjeevr) Check if we need to make this a singleton for
450 // compatibility with the old testing code 473 // compatibility with the old testing code
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 643 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
621 // |last_opened_profiles| will be empty in the following circumstances: 644 // |last_opened_profiles| will be empty in the following circumstances:
622 // - This is the first launch. |last_used_profile| is the initial profile. 645 // - This is the first launch. |last_used_profile| is the initial profile.
623 // - The user exited the browser by closing all windows for all 646 // - The user exited the browser by closing all windows for all
624 // profiles. |last_used_profile| is the profile which owned the last open 647 // profiles. |last_used_profile| is the profile which owned the last open
625 // window. 648 // window.
626 // - Only incognito windows were open when the browser exited. 649 // - Only incognito windows were open when the browser exited.
627 // |last_used_profile| is the last used incognito profile. Restoring it will 650 // |last_used_profile| is the last used incognito profile. Restoring it will
628 // create a browser window for the corresponding original profile. 651 // create a browser window for the corresponding original profile.
629 if (last_opened_profiles.empty()) { 652 if (last_opened_profiles.empty()) {
653 int return_code = 0;
630 if (!browser_creator->LaunchBrowser(command_line, last_used_profile, 654 if (!browser_creator->LaunchBrowser(command_line, last_used_profile,
631 cur_dir, is_process_startup, 655 cur_dir, is_process_startup,
632 is_first_run, return_code)) { 656 is_first_run, &return_code)) {
657 if (operation_output)
658 OperationOutput::Complete(operation_output.Pass(), return_code);
633 return false; 659 return false;
634 } 660 }
635 } else { 661 } else {
636 // Launch the last used profile with the full command line, and the other 662 // Launch the last used profile with the full command line, and the other
637 // opened profiles without the URLs to launch. 663 // opened profiles without the URLs to launch.
638 CommandLine command_line_without_urls(command_line.GetProgram()); 664 CommandLine command_line_without_urls(command_line.GetProgram());
639 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); 665 const CommandLine::SwitchMap& switches = command_line.GetSwitches();
640 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); 666 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin();
641 switch_it != switches.end(); ++switch_it) { 667 switch_it != switches.end(); ++switch_it) {
642 command_line_without_urls.AppendSwitchNative(switch_it->first, 668 command_line_without_urls.AppendSwitchNative(switch_it->first,
643 switch_it->second); 669 switch_it->second);
644 } 670 }
645 // Launch the profiles in the order they became active. 671 // Launch the profiles in the order they became active.
646 for (Profiles::const_iterator it = last_opened_profiles.begin(); 672 for (Profiles::const_iterator it = last_opened_profiles.begin();
647 it != last_opened_profiles.end(); ++it) { 673 it != last_opened_profiles.end(); ++it) {
648 // Don't launch additional profiles which would only open a new tab 674 // Don't launch additional profiles which would only open a new tab
649 // page. When restarting after an update, all profiles will reopen last 675 // page. When restarting after an update, all profiles will reopen last
650 // open pages. 676 // open pages.
651 SessionStartupPref startup_pref = 677 SessionStartupPref startup_pref =
652 GetSessionStartupPref(command_line, *it); 678 GetSessionStartupPref(command_line, *it);
653 if (*it != last_used_profile && 679 if (*it != last_used_profile &&
654 startup_pref.type == SessionStartupPref::DEFAULT && 680 startup_pref.type == SessionStartupPref::DEFAULT &&
655 !HasPendingUncleanExit(*it)) 681 !HasPendingUncleanExit(*it))
656 continue; 682 continue;
683 int return_code = 0;
657 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? 684 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ?
658 command_line : command_line_without_urls, *it, cur_dir, 685 command_line : command_line_without_urls, *it, cur_dir,
659 is_process_startup, is_first_run, return_code)) 686 is_process_startup, is_first_run, &return_code)) {
687 if (operation_output)
688 OperationOutput::Complete(operation_output.Pass(), return_code);
660 return false; 689 return false;
690 }
661 // We've launched at least one browser. 691 // We've launched at least one browser.
662 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; 692 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP;
663 } 693 }
664 // This must be done after all profiles have been launched so the observer 694 // This must be done after all profiles have been launched so the observer
665 // knows about all profiles to wait for before activating this one. 695 // knows about all profiles to wait for before activating this one.
666 profile_launch_observer.Get().set_profile_to_activate(last_used_profile); 696 profile_launch_observer.Get().set_profile_to_activate(last_used_profile);
667 } 697 }
698 if (operation_output) {
699 OperationOutput::Complete(operation_output.Pass(),
700 content::RESULT_CODE_NORMAL_EXIT);
701 }
668 return true; 702 return true;
669 } 703 }
670 704
671 template <class AutomationProviderClass> 705 template <class AutomationProviderClass>
672 bool StartupBrowserCreator::CreateAutomationProvider( 706 bool StartupBrowserCreator::CreateAutomationProvider(
673 const std::string& channel_id, 707 const std::string& channel_id,
674 Profile* profile, 708 Profile* profile,
675 size_t expected_tabs) { 709 size_t expected_tabs) {
676 #if defined(ENABLE_AUTOMATION) 710 #if defined(ENABLE_AUTOMATION)
677 scoped_refptr<AutomationProviderClass> automation = 711 scoped_refptr<AutomationProviderClass> automation =
678 new AutomationProviderClass(profile); 712 new AutomationProviderClass(profile);
679 if (!automation->InitializeChannel(channel_id)) 713 if (!automation->InitializeChannel(channel_id))
680 return false; 714 return false;
681 automation->SetExpectedTabCount(expected_tabs); 715 automation->SetExpectedTabCount(expected_tabs);
682 716
683 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); 717 AutomationProviderList* list = g_browser_process->GetAutomationProviderList();
684 DCHECK(list); 718 DCHECK(list);
685 list->AddProvider(automation); 719 list->AddProvider(automation);
686 #endif // defined(ENABLE_AUTOMATION) 720 #endif // defined(ENABLE_AUTOMATION)
687 721
688 return true; 722 return true;
689 } 723 }
690 724
691 // static 725 // static
692 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( 726 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated(
693 const CommandLine& command_line, 727 const CommandLine& command_line,
694 const base::FilePath& cur_dir, 728 const base::FilePath& cur_dir,
729 scoped_ptr<OperationOutput> operation_output,
695 Profile* profile, 730 Profile* profile,
696 Profile::CreateStatus status) { 731 Profile::CreateStatus status) {
697 if (status == Profile::CREATE_STATUS_INITIALIZED) 732 if (status == Profile::CREATE_STATUS_INITIALIZED) {
698 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, 733 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL,
699 NULL); 734 operation_output.Pass());
735 } else {
736 // Signal failure on operation_output?
737 }
700 } 738 }
701 739
702 // static 740 // static
703 void StartupBrowserCreator::ProcessCommandLineAlreadyRunning( 741 void StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
704 const CommandLine& command_line, 742 const CommandLine& command_line,
705 const base::FilePath& cur_dir, 743 const base::FilePath& cur_dir,
706 const base::FilePath& profile_path) { 744 const base::FilePath& profile_path,
745 scoped_ptr<OperationOutput> operation_output) {
707 ProfileManager* profile_manager = g_browser_process->profile_manager(); 746 ProfileManager* profile_manager = g_browser_process->profile_manager();
708 Profile* profile = profile_manager->GetProfileByPath(profile_path); 747 Profile* profile = profile_manager->GetProfileByPath(profile_path);
709 748
710 // The profile isn't loaded yet and so needs to be loaded asynchronously. 749 // The profile isn't loaded yet and so needs to be loaded asynchronously.
711 if (!profile) { 750 if (!profile) {
712 profile_manager->CreateProfileAsync(profile_path, 751 profile_manager->CreateProfileAsync(
713 base::Bind(&StartupBrowserCreator::ProcessCommandLineOnProfileCreated, 752 profile_path,
714 command_line, cur_dir), string16(), string16(), false); 753 base::Bind(
754 &StartupBrowserCreator::ProcessCommandLineOnProfileCreated,
755 command_line, cur_dir, base::Passed(operation_output.Pass())),
756 string16(), string16(), false);
715 return; 757 return;
716 } 758 }
717 759
718 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, 760 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL,
719 NULL); 761 operation_output.Pass());
720 } 762 }
721 763
722 // static 764 // static
723 bool StartupBrowserCreator::ActivatedProfile() { 765 bool StartupBrowserCreator::ActivatedProfile() {
724 return profile_launch_observer.Get().activated_profile(); 766 return profile_launch_observer.Get().activated_profile();
725 } 767 }
726 768
727 bool HasPendingUncleanExit(Profile* profile) { 769 bool HasPendingUncleanExit(Profile* profile) {
728 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED && 770 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED &&
729 !profile_launch_observer.Get().HasBeenLaunched(profile); 771 !profile_launch_observer.Get().HasBeenLaunched(profile);
730 } 772 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator.h ('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