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

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: Line endings. Created 7 years, 9 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // static 233 // static
233 bool StartupBrowserCreator::was_restarted_read_ = false; 234 bool StartupBrowserCreator::was_restarted_read_ = false;
234 235
235 // static 236 // static
236 bool StartupBrowserCreator::in_synchronous_profile_launch_ = false; 237 bool StartupBrowserCreator::in_synchronous_profile_launch_ = false;
237 238
238 void StartupBrowserCreator::AddFirstRunTab(const GURL& url) { 239 void StartupBrowserCreator::AddFirstRunTab(const GURL& url) {
239 first_run_tabs_.push_back(url); 240 first_run_tabs_.push_back(url);
240 } 241 }
241 242
243 bool StartupBrowserCreator::Start(
244 const CommandLine& cmd_line,
245 const base::FilePath& cur_dir,
246 Profile* last_used_profile,
247 const Profiles& last_opened_profiles,
248 scoped_ptr<OperationOutput> operation_output) {
249 return ProcessCmdLineImpl(cmd_line, cur_dir, true, last_used_profile,
250 last_opened_profiles, this,
251 operation_output.Pass());
252 }
253
242 // static 254 // static
243 bool StartupBrowserCreator::InSynchronousProfileLaunch() { 255 bool StartupBrowserCreator::InSynchronousProfileLaunch() {
244 return in_synchronous_profile_launch_; 256 return in_synchronous_profile_launch_;
245 } 257 }
246 258
247 bool StartupBrowserCreator::LaunchBrowser( 259 bool StartupBrowserCreator::LaunchBrowser(
248 const CommandLine& command_line, 260 const CommandLine& command_line,
249 Profile* profile, 261 Profile* profile,
250 const base::FilePath& cur_dir, 262 const base::FilePath& cur_dir,
251 chrome::startup::IsProcessStartup process_startup, 263 chrome::startup::IsProcessStartup process_startup,
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 return urls; 434 return urls;
423 } 435 }
424 436
425 // static 437 // static
426 bool StartupBrowserCreator::ProcessCmdLineImpl( 438 bool StartupBrowserCreator::ProcessCmdLineImpl(
427 const CommandLine& command_line, 439 const CommandLine& command_line,
428 const base::FilePath& cur_dir, 440 const base::FilePath& cur_dir,
429 bool process_startup, 441 bool process_startup,
430 Profile* last_used_profile, 442 Profile* last_used_profile,
431 const Profiles& last_opened_profiles, 443 const Profiles& last_opened_profiles,
432 int* return_code, 444 StartupBrowserCreator* browser_creator,
433 StartupBrowserCreator* browser_creator) { 445 scoped_ptr<OperationOutput> operation_output) {
434 DCHECK(last_used_profile); 446 DCHECK(last_used_profile);
435 if (process_startup) { 447 if (process_startup) {
436 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 448 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
437 content::NavigationController::DisablePromptOnRepost(); 449 content::NavigationController::DisablePromptOnRepost();
438 } 450 }
439 451
452 if (command_line.HasSwitch("greetings")) {
453 if (operation_output) {
454 std::string hello_world("hello world!");
455 operation_output->Write(hello_world.c_str(), hello_world.length());
456 OperationOutput::Complete(operation_output.Pass(), 42);
457 }
robertshield 2013/03/28 14:31:48 Is the greetings flag still useful?
458
459 return false;
460 }
461
440 bool silent_launch = false; 462 bool silent_launch = false;
441 463
442 #if defined(ENABLE_AUTOMATION) 464 #if defined(ENABLE_AUTOMATION)
443 // Look for the testing channel ID ONLY during process startup 465 // Look for the testing channel ID ONLY during process startup
444 if (process_startup && 466 if (process_startup &&
445 command_line.HasSwitch(switches::kTestingChannelID)) { 467 command_line.HasSwitch(switches::kTestingChannelID)) {
446 std::string testing_channel_id = command_line.GetSwitchValueASCII( 468 std::string testing_channel_id = command_line.GetSwitchValueASCII(
447 switches::kTestingChannelID); 469 switches::kTestingChannelID);
448 // TODO(sanjeevr) Check if we need to make this a singleton for 470 // TODO(sanjeevr) Check if we need to make this a singleton for
449 // compatibility with the old testing code 471 // compatibility with the old testing code
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 623 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
602 // |last_opened_profiles| will be empty in the following circumstances: 624 // |last_opened_profiles| will be empty in the following circumstances:
603 // - This is the first launch. |last_used_profile| is the initial profile. 625 // - This is the first launch. |last_used_profile| is the initial profile.
604 // - The user exited the browser by closing all windows for all 626 // - The user exited the browser by closing all windows for all
605 // profiles. |last_used_profile| is the profile which owned the last open 627 // profiles. |last_used_profile| is the profile which owned the last open
606 // window. 628 // window.
607 // - Only incognito windows were open when the browser exited. 629 // - Only incognito windows were open when the browser exited.
608 // |last_used_profile| is the last used incognito profile. Restoring it will 630 // |last_used_profile| is the last used incognito profile. Restoring it will
609 // create a browser window for the corresponding original profile. 631 // create a browser window for the corresponding original profile.
610 if (last_opened_profiles.empty()) { 632 if (last_opened_profiles.empty()) {
633 int return_code = 0;
611 if (!browser_creator->LaunchBrowser(command_line, last_used_profile, 634 if (!browser_creator->LaunchBrowser(command_line, last_used_profile,
612 cur_dir, is_process_startup, 635 cur_dir, is_process_startup,
613 is_first_run, return_code)) { 636 is_first_run, &return_code)) {
637 if (operation_output)
638 OperationOutput::Complete(operation_output.Pass(), return_code);
614 return false; 639 return false;
615 } 640 }
616 } else { 641 } else {
617 // Launch the last used profile with the full command line, and the other 642 // Launch the last used profile with the full command line, and the other
618 // opened profiles without the URLs to launch. 643 // opened profiles without the URLs to launch.
619 CommandLine command_line_without_urls(command_line.GetProgram()); 644 CommandLine command_line_without_urls(command_line.GetProgram());
620 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); 645 const CommandLine::SwitchMap& switches = command_line.GetSwitches();
621 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); 646 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin();
622 switch_it != switches.end(); ++switch_it) { 647 switch_it != switches.end(); ++switch_it) {
623 command_line_without_urls.AppendSwitchNative(switch_it->first, 648 command_line_without_urls.AppendSwitchNative(switch_it->first,
624 switch_it->second); 649 switch_it->second);
625 } 650 }
626 // Launch the profiles in the order they became active. 651 // Launch the profiles in the order they became active.
627 for (Profiles::const_iterator it = last_opened_profiles.begin(); 652 for (Profiles::const_iterator it = last_opened_profiles.begin();
628 it != last_opened_profiles.end(); ++it) { 653 it != last_opened_profiles.end(); ++it) {
629 // Don't launch additional profiles which would only open a new tab 654 // Don't launch additional profiles which would only open a new tab
630 // page. When restarting after an update, all profiles will reopen last 655 // page. When restarting after an update, all profiles will reopen last
631 // open pages. 656 // open pages.
632 SessionStartupPref startup_pref = 657 SessionStartupPref startup_pref =
633 GetSessionStartupPref(command_line, *it); 658 GetSessionStartupPref(command_line, *it);
634 if (*it != last_used_profile && 659 if (*it != last_used_profile &&
635 startup_pref.type == SessionStartupPref::DEFAULT && 660 startup_pref.type == SessionStartupPref::DEFAULT &&
636 !HasPendingUncleanExit(*it)) 661 !HasPendingUncleanExit(*it))
637 continue; 662 continue;
663 int return_code = 0;
638 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? 664 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ?
639 command_line : command_line_without_urls, *it, cur_dir, 665 command_line : command_line_without_urls, *it, cur_dir,
640 is_process_startup, is_first_run, return_code)) 666 is_process_startup, is_first_run, &return_code)) {
667 if (operation_output)
668 OperationOutput::Complete(operation_output.Pass(), return_code);
641 return false; 669 return false;
670 }
642 // We've launched at least one browser. 671 // We've launched at least one browser.
643 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; 672 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP;
644 } 673 }
645 // This must be done after all profiles have been launched so the observer 674 // This must be done after all profiles have been launched so the observer
646 // knows about all profiles to wait for before activating this one. 675 // knows about all profiles to wait for before activating this one.
647 profile_launch_observer.Get().set_profile_to_activate(last_used_profile); 676 profile_launch_observer.Get().set_profile_to_activate(last_used_profile);
648 } 677 }
678 if (operation_output) {
679 OperationOutput::Complete(operation_output.Pass(),
680 content::RESULT_CODE_NORMAL_EXIT);
681 }
649 return true; 682 return true;
650 } 683 }
651 684
652 template <class AutomationProviderClass> 685 template <class AutomationProviderClass>
653 bool StartupBrowserCreator::CreateAutomationProvider( 686 bool StartupBrowserCreator::CreateAutomationProvider(
654 const std::string& channel_id, 687 const std::string& channel_id,
655 Profile* profile, 688 Profile* profile,
656 size_t expected_tabs) { 689 size_t expected_tabs) {
657 #if defined(ENABLE_AUTOMATION) 690 #if defined(ENABLE_AUTOMATION)
658 scoped_refptr<AutomationProviderClass> automation = 691 scoped_refptr<AutomationProviderClass> automation =
659 new AutomationProviderClass(profile); 692 new AutomationProviderClass(profile);
660 if (!automation->InitializeChannel(channel_id)) 693 if (!automation->InitializeChannel(channel_id))
661 return false; 694 return false;
662 automation->SetExpectedTabCount(expected_tabs); 695 automation->SetExpectedTabCount(expected_tabs);
663 696
664 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); 697 AutomationProviderList* list = g_browser_process->GetAutomationProviderList();
665 DCHECK(list); 698 DCHECK(list);
666 list->AddProvider(automation); 699 list->AddProvider(automation);
667 #endif // defined(ENABLE_AUTOMATION) 700 #endif // defined(ENABLE_AUTOMATION)
668 701
669 return true; 702 return true;
670 } 703 }
671 704
672 // static 705 // static
673 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( 706 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated(
674 const CommandLine& command_line, 707 const CommandLine& command_line,
675 const base::FilePath& cur_dir, 708 const base::FilePath& cur_dir,
709 scoped_ptr<OperationOutput> operation_output,
676 Profile* profile, 710 Profile* profile,
677 Profile::CreateStatus status) { 711 Profile::CreateStatus status) {
678 if (status == Profile::CREATE_STATUS_INITIALIZED) 712 if (status == Profile::CREATE_STATUS_INITIALIZED) {
679 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, 713 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL,
680 NULL); 714 operation_output.Pass());
715 } else {
716 // Signal failure on operation_output?
717 }
681 } 718 }
682 719
683 // static 720 // static
684 void StartupBrowserCreator::ProcessCommandLineAlreadyRunning( 721 void StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
685 const CommandLine& command_line, 722 const CommandLine& command_line,
686 const base::FilePath& cur_dir, 723 const base::FilePath& cur_dir,
687 const base::FilePath& profile_path) { 724 const base::FilePath& profile_path,
725 scoped_ptr<OperationOutput> operation_output) {
688 ProfileManager* profile_manager = g_browser_process->profile_manager(); 726 ProfileManager* profile_manager = g_browser_process->profile_manager();
689 Profile* profile = profile_manager->GetProfileByPath(profile_path); 727 Profile* profile = profile_manager->GetProfileByPath(profile_path);
690 728
691 // The profile isn't loaded yet and so needs to be loaded asynchronously. 729 // The profile isn't loaded yet and so needs to be loaded asynchronously.
692 if (!profile) { 730 if (!profile) {
693 profile_manager->CreateProfileAsync(profile_path, 731 profile_manager->CreateProfileAsync(
694 base::Bind(&StartupBrowserCreator::ProcessCommandLineOnProfileCreated, 732 profile_path,
695 command_line, cur_dir), string16(), string16(), false); 733 base::Bind(
734 &StartupBrowserCreator::ProcessCommandLineOnProfileCreated,
735 command_line, cur_dir, base::Passed(operation_output.Pass())),
736 string16(), string16(), false);
696 return; 737 return;
697 } 738 }
698 739
699 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL, 740 ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL,
700 NULL); 741 operation_output.Pass());
701 } 742 }
702 743
703 // static 744 // static
704 bool StartupBrowserCreator::ActivatedProfile() { 745 bool StartupBrowserCreator::ActivatedProfile() {
705 return profile_launch_observer.Get().activated_profile(); 746 return profile_launch_observer.Get().activated_profile();
706 } 747 }
707 748
708 bool HasPendingUncleanExit(Profile* profile) { 749 bool HasPendingUncleanExit(Profile* profile) {
709 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED && 750 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED &&
710 !profile_launch_observer.Get().HasBeenLaunched(profile); 751 !profile_launch_observer.Get().HasBeenLaunched(profile);
711 } 752 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698