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

Side by Side Diff: chrome/browser/ui/browser_init.cc

Issue 9087009: Restore all profiles which were active when restoring the last open pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 8 years, 11 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/browser_init.h" 5 #include "chrome/browser/ui/browser_init.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 (url.spec().find(chrome::kChromeUISettingsURL) == 0) || 1525 (url.spec().find(chrome::kChromeUISettingsURL) == 0) ||
1526 #endif 1526 #endif
1527 (url.spec().compare(chrome::kAboutBlankURL) == 0)) { 1527 (url.spec().compare(chrome::kAboutBlankURL) == 0)) {
1528 urls.push_back(url); 1528 urls.push_back(url);
1529 } 1529 }
1530 } 1530 }
1531 } 1531 }
1532 return urls; 1532 return urls;
1533 } 1533 }
1534 1534
1535 bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line, 1535 bool BrowserInit::ProcessCmdLineImpl(
1536 const FilePath& cur_dir, 1536 const CommandLine& command_line,
1537 bool process_startup, 1537 const FilePath& cur_dir,
1538 Profile* profile, 1538 bool process_startup,
1539 int* return_code, 1539 Profile* last_active_profile,
1540 BrowserInit* browser_init) { 1540 const std::vector<Profile*>& other_profiles,
1541 DCHECK(profile); 1541 int* return_code,
1542 BrowserInit* browser_init) {
1543 DCHECK(last_active_profile);
1542 if (process_startup) { 1544 if (process_startup) {
1543 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 1545 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
1544 content::NavigationController::DisablePromptOnRepost(); 1546 content::NavigationController::DisablePromptOnRepost();
1545 1547
1546 RegisterComponentsForUpdate(command_line); 1548 RegisterComponentsForUpdate(command_line);
1547 1549
1548 // Look for the testing channel ID ONLY during process startup 1550 // Look for the testing channel ID ONLY during process startup
1549 if (command_line.HasSwitch(switches::kTestingChannelID)) { 1551 if (command_line.HasSwitch(switches::kTestingChannelID)) {
1550 std::string testing_channel_id = command_line.GetSwitchValueASCII( 1552 std::string testing_channel_id = command_line.GetSwitchValueASCII(
1551 switches::kTestingChannelID); 1553 switches::kTestingChannelID);
1552 // TODO(sanjeevr) Check if we need to make this a singleton for 1554 // TODO(sanjeevr) Check if we need to make this a singleton for
1553 // compatibility with the old testing code 1555 // compatibility with the old testing code
1554 // If there are any extra parameters, we expect each one to generate a 1556 // If there are any extra parameters, we expect each one to generate a
1555 // new tab; if there are none then we get one homepage tab. 1557 // new tab; if there are none then we get one homepage tab.
1556 int expected_tab_count = 1; 1558 int expected_tab_count = 1;
1557 if (command_line.HasSwitch(switches::kNoStartupWindow)) { 1559 if (command_line.HasSwitch(switches::kNoStartupWindow)) {
1558 expected_tab_count = 0; 1560 expected_tab_count = 0;
1559 #if defined(OS_CHROMEOS) 1561 #if defined(OS_CHROMEOS)
1560 // kLoginManager will cause Chrome to start up with the ChromeOS login 1562 // kLoginManager will cause Chrome to start up with the ChromeOS login
1561 // screen instead of a browser window, so it won't load any tabs. 1563 // screen instead of a browser window, so it won't load any tabs.
1562 } else if (command_line.HasSwitch(switches::kLoginManager)) { 1564 } else if (command_line.HasSwitch(switches::kLoginManager)) {
1563 expected_tab_count = 0; 1565 expected_tab_count = 0;
1564 #endif 1566 #endif
1565 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { 1567 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) {
1566 std::string restore_session_value( 1568 std::string restore_session_value(
1567 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); 1569 command_line.GetSwitchValueASCII(switches::kRestoreLastSession));
1568 base::StringToInt(restore_session_value, &expected_tab_count); 1570 base::StringToInt(restore_session_value, &expected_tab_count);
1569 } else { 1571 } else {
1570 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( 1572 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(
1571 command_line, cur_dir, profile); 1573 command_line, cur_dir, last_active_profile);
1572 expected_tab_count = 1574 expected_tab_count =
1573 std::max(1, static_cast<int>(urls_to_open.size())); 1575 std::max(1, static_cast<int>(urls_to_open.size()));
1574 } 1576 }
1575 if (!CreateAutomationProvider<TestingAutomationProvider>( 1577 if (!CreateAutomationProvider<TestingAutomationProvider>(
1576 testing_channel_id, 1578 testing_channel_id,
1577 profile, 1579 last_active_profile,
1578 static_cast<size_t>(expected_tab_count))) 1580 static_cast<size_t>(expected_tab_count)))
1579 return false; 1581 return false;
1580 } 1582 }
1581 } 1583 }
1582 1584
1583 bool silent_launch = false; 1585 bool silent_launch = false;
1584 1586
1585 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { 1587 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) {
1586 std::string automation_channel_id = command_line.GetSwitchValueASCII( 1588 std::string automation_channel_id = command_line.GetSwitchValueASCII(
1587 switches::kAutomationClientChannelID); 1589 switches::kAutomationClientChannelID);
1588 // If there are any extra parameters, we expect each one to generate a 1590 // If there are any extra parameters, we expect each one to generate a
1589 // new tab; if there are none then we have no tabs 1591 // new tab; if there are none then we have no tabs
1590 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( 1592 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(
1591 command_line, cur_dir, profile); 1593 command_line, cur_dir, last_active_profile);
1592 size_t expected_tabs = 1594 size_t expected_tabs =
1593 std::max(static_cast<int>(urls_to_open.size()), 0); 1595 std::max(static_cast<int>(urls_to_open.size()), 0);
1594 if (expected_tabs == 0) 1596 if (expected_tabs == 0)
1595 silent_launch = true; 1597 silent_launch = true;
1596 1598
1597 if (command_line.HasSwitch(switches::kChromeFrame)) { 1599 if (command_line.HasSwitch(switches::kChromeFrame)) {
1598 #if !defined(USE_AURA) 1600 #if !defined(USE_AURA)
1599 if (!CreateAutomationProvider<ChromeFrameAutomationProvider>( 1601 if (!CreateAutomationProvider<ChromeFrameAutomationProvider>(
1600 automation_channel_id, profile, expected_tabs)) 1602 automation_channel_id, last_active_profile, expected_tabs))
1601 return false; 1603 return false;
1602 #endif 1604 #endif
1603 } else { 1605 } else {
1604 if (!CreateAutomationProvider<AutomationProvider>( 1606 if (!CreateAutomationProvider<AutomationProvider>(
1605 automation_channel_id, profile, expected_tabs)) 1607 automation_channel_id, last_active_profile, expected_tabs))
1606 return false; 1608 return false;
1607 } 1609 }
1608 } 1610 }
1609 1611
1610 // If we have been invoked to display a desktop notification on behalf of 1612 // If we have been invoked to display a desktop notification on behalf of
1611 // the service process, we do not want to open any browser windows. 1613 // the service process, we do not want to open any browser windows.
1612 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { 1614 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) {
1613 silent_launch = true; 1615 silent_launch = true;
1614 CloudPrintProxyServiceFactory::GetForProfile(profile)-> 1616 CloudPrintProxyServiceFactory::GetForProfile(last_active_profile)->
1615 ShowTokenExpiredNotification(); 1617 ShowTokenExpiredNotification();
1616 } 1618 }
1617 1619
1618 // If we are just displaying a print dialog we shouldn't open browser 1620 // If we are just displaying a print dialog we shouldn't open browser
1619 // windows. 1621 // windows.
1620 if (command_line.HasSwitch(switches::kCloudPrintFile) && 1622 if (command_line.HasSwitch(switches::kCloudPrintFile) &&
1621 print_dialog_cloud::CreatePrintDialogFromCommandLine(command_line)) { 1623 print_dialog_cloud::CreatePrintDialogFromCommandLine(command_line)) {
1622 silent_launch = true; 1624 silent_launch = true;
1623 } 1625 }
1624 1626
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 } 1661 }
1660 #endif 1662 #endif
1661 1663
1662 // If we don't want to launch a new browser window or tab (in the case 1664 // If we don't want to launch a new browser window or tab (in the case
1663 // of an automation request), we are done here. 1665 // of an automation request), we are done here.
1664 if (!silent_launch) { 1666 if (!silent_launch) {
1665 IsProcessStartup is_process_startup = process_startup ? 1667 IsProcessStartup is_process_startup = process_startup ?
1666 IS_PROCESS_STARTUP : IS_NOT_PROCESS_STARTUP; 1668 IS_PROCESS_STARTUP : IS_NOT_PROCESS_STARTUP;
1667 IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? 1669 IsFirstRun is_first_run = first_run::IsChromeFirstRun() ?
1668 IS_FIRST_RUN : IS_NOT_FIRST_RUN; 1670 IS_FIRST_RUN : IS_NOT_FIRST_RUN;
1669 return browser_init->LaunchBrowser(command_line, profile, cur_dir, 1671 // Launch the last active profile with the full command line, and the other
1670 is_process_startup, is_first_run, return_code); 1672 // profiles without the URLs to launch.
1673 CommandLine command_line_without_urls(command_line.GetProgram());
1674 const CommandLine::SwitchMap& switches = command_line.GetSwitches();
1675 CommandLine::SwitchMap::const_iterator switch_it;
Peter Kasting 2012/01/10 02:20:12 Nit: Declare loop iterators/indexes inside the loo
marja 2012/01/10 14:12:03 Done.
1676 for (switch_it = switches.begin(); switch_it != switches.end();
1677 ++switch_it) {
1678 command_line_without_urls.AppendSwitchNative(switch_it->first,
1679 switch_it->second);
1680 }
1681 std::vector<Profile*>::const_iterator it;
1682 for (it = other_profiles.begin(); it != other_profiles.end(); ++it) {
1683 if (*it == last_active_profile)
1684 continue;
1685 if (!browser_init->LaunchBrowser(
1686 command_line_without_urls, *it, cur_dir, is_process_startup,
Peter Kasting 2012/01/10 02:20:12 Nit: This indenting is strange: * Since you're not
marja 2012/01/10 14:12:03 Done.
1687 is_first_run, return_code)) {
Peter Kasting 2012/01/10 02:20:12 Nit: No need for {}
marja 2012/01/10 14:12:03 Done.
1688 return false;
1689 }
1690 }
1691 return browser_init->LaunchBrowser(
1692 command_line, last_active_profile, cur_dir, is_process_startup,
1693 is_first_run, return_code);
1671 } 1694 }
1672 return true; 1695 return true;
1673 } 1696 }
1674 1697
1675 template <class AutomationProviderClass> 1698 template <class AutomationProviderClass>
1676 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, 1699 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id,
1677 Profile* profile, 1700 Profile* profile,
1678 size_t expected_tabs) { 1701 size_t expected_tabs) {
1679 scoped_refptr<AutomationProviderClass> automation = 1702 scoped_refptr<AutomationProviderClass> automation =
1680 new AutomationProviderClass(profile); 1703 new AutomationProviderClass(profile);
1681 1704
1682 if (!automation->InitializeChannel(channel_id)) 1705 if (!automation->InitializeChannel(channel_id))
1683 return false; 1706 return false;
1684 automation->SetExpectedTabCount(expected_tabs); 1707 automation->SetExpectedTabCount(expected_tabs);
1685 1708
1686 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); 1709 AutomationProviderList* list = g_browser_process->GetAutomationProviderList();
1687 DCHECK(list); 1710 DCHECK(list);
1688 list->AddProvider(automation); 1711 list->AddProvider(automation);
1689 1712
1690 return true; 1713 return true;
1691 } 1714 }
1692 1715
1693 // static 1716 // static
1694 void BrowserInit::ProcessCommandLineOnProfileCreated( 1717 void BrowserInit::ProcessCommandLineOnProfileCreated(
1695 const CommandLine& cmd_line, 1718 const CommandLine& cmd_line,
1696 const FilePath& cur_dir, 1719 const FilePath& cur_dir,
1697 Profile* profile, 1720 Profile* profile,
1698 Profile::CreateStatus status) { 1721 Profile::CreateStatus status) {
1699 if (status == Profile::CREATE_STATUS_INITIALIZED) 1722 if (status == Profile::CREATE_STATUS_INITIALIZED)
1700 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, NULL, NULL); 1723 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile,
1724 std::vector<Profile*>(), NULL, NULL);
1701 } 1725 }
1702 1726
1703 // static 1727 // static
1704 void BrowserInit::ProcessCommandLineAlreadyRunning(const CommandLine& cmd_line, 1728 void BrowserInit::ProcessCommandLineAlreadyRunning(const CommandLine& cmd_line,
1705 const FilePath& cur_dir) { 1729 const FilePath& cur_dir) {
1706 if (cmd_line.HasSwitch(switches::kProfileDirectory)) { 1730 if (cmd_line.HasSwitch(switches::kProfileDirectory)) {
1707 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1731 ProfileManager* profile_manager = g_browser_process->profile_manager();
1708 FilePath path = cmd_line.GetSwitchValuePath(switches::kProfileDirectory); 1732 FilePath path = cmd_line.GetSwitchValuePath(switches::kProfileDirectory);
1709 path = profile_manager->user_data_dir().Append(path); 1733 path = profile_manager->user_data_dir().Append(path);
1710 profile_manager->CreateProfileAsync(path, 1734 profile_manager->CreateProfileAsync(path,
1711 base::Bind(&BrowserInit::ProcessCommandLineOnProfileCreated, 1735 base::Bind(&BrowserInit::ProcessCommandLineOnProfileCreated,
1712 cmd_line, cur_dir)); 1736 cmd_line, cur_dir));
1713 return; 1737 return;
1714 } 1738 }
1715 1739
1716 Profile* profile = ProfileManager::GetLastUsedProfile(); 1740 Profile* profile = ProfileManager::GetLastUsedProfile();
1717 if (!profile) { 1741 if (!profile) {
1718 // We should only be able to get here if the profile already exists and 1742 // We should only be able to get here if the profile already exists and
1719 // has been created. 1743 // has been created.
1720 NOTREACHED(); 1744 NOTREACHED();
1721 return; 1745 return;
1722 } 1746 }
1723 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, NULL, NULL); 1747 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, std::vector<Profile*>(),
1748 NULL, NULL);
1724 } 1749 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698