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/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 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 if (command_line.HasSwitch(switches::kRestoreLastSession) || | 737 if (command_line.HasSwitch(switches::kRestoreLastSession) || |
738 BrowserInit::WasRestarted()) { | 738 BrowserInit::WasRestarted()) { |
739 pref.type = SessionStartupPref::LAST; | 739 pref.type = SessionStartupPref::LAST; |
740 } | 740 } |
741 if (pref.type == SessionStartupPref::LAST && | 741 if (pref.type == SessionStartupPref::LAST && |
742 IncognitoModePrefs::ShouldLaunchIncognito(command_line, | 742 IncognitoModePrefs::ShouldLaunchIncognito(command_line, |
743 profile->GetPrefs())) { | 743 profile->GetPrefs())) { |
744 // We don't store session information when incognito. If the user has | 744 // We don't store session information when incognito. If the user has |
745 // chosen to restore last session and launched incognito, fallback to | 745 // chosen to restore last session and launched incognito, fallback to |
746 // default launch behavior. | 746 // default launch behavior. |
747 pref.type = SessionStartupPref::DEFAULT; | 747 pref.type = SessionStartupPref::NEWTAB; |
748 } | 748 } |
749 return pref; | 749 return pref; |
750 } | 750 } |
751 | 751 |
752 | 752 |
753 // BrowserInit::LaunchWithProfile::Tab ---------------------------------------- | 753 // BrowserInit::LaunchWithProfile::Tab ---------------------------------------- |
754 | 754 |
755 BrowserInit::LaunchWithProfile::Tab::Tab() : is_app(false), is_pinned(true) {} | 755 BrowserInit::LaunchWithProfile::Tab::Tab() : is_app(false), is_pinned(true) {} |
756 | 756 |
757 BrowserInit::LaunchWithProfile::Tab::~Tab() {} | 757 BrowserInit::LaunchWithProfile::Tab::~Tab() {} |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 if (process_startup) | 1030 if (process_startup) |
1031 AddInfoBarsIfNecessary(browser); | 1031 AddInfoBarsIfNecessary(browser); |
1032 } | 1032 } |
1033 | 1033 |
1034 bool BrowserInit::LaunchWithProfile::ProcessStartupURLs( | 1034 bool BrowserInit::LaunchWithProfile::ProcessStartupURLs( |
1035 const std::vector<GURL>& urls_to_open) { | 1035 const std::vector<GURL>& urls_to_open) { |
1036 SessionStartupPref pref = GetSessionStartupPref(command_line_, profile_); | 1036 SessionStartupPref pref = GetSessionStartupPref(command_line_, profile_); |
1037 if (command_line_.HasSwitch(switches::kTestingChannelID) && | 1037 if (command_line_.HasSwitch(switches::kTestingChannelID) && |
1038 !command_line_.HasSwitch(switches::kRestoreLastSession) && | 1038 !command_line_.HasSwitch(switches::kRestoreLastSession) && |
1039 browser_defaults::kDefaultSessionStartupType != | 1039 browser_defaults::kDefaultSessionStartupType != |
1040 SessionStartupPref::DEFAULT) { | 1040 SessionStartupPref::NEWTAB) { |
1041 // When we have non DEFAULT session start type, then we won't open up a | 1041 // When we have non DEFAULT session start type, then we won't open up a |
1042 // fresh session. But none of the tests are written with this in mind, so | 1042 // fresh session. But none of the tests are written with this in mind, so |
1043 // we explicitly ignore it during testing. | 1043 // we explicitly ignore it during testing. |
1044 return false; | 1044 return false; |
1045 } | 1045 } |
1046 | 1046 |
1047 if (pref.type == SessionStartupPref::LAST) { | 1047 if (pref.type == SessionStartupPref::LAST) { |
1048 if (!profile_->DidLastSessionExitCleanly() && | 1048 if (!profile_->DidLastSessionExitCleanly() && |
1049 !command_line_.HasSwitch(switches::kRestoreLastSession)) { | 1049 !command_line_.HasSwitch(switches::kRestoreLastSession)) { |
1050 // The last session crashed. It's possible automatically loading the | 1050 // The last session crashed. It's possible automatically loading the |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 RecordAppLaunches(profile_, urls_to_open, tabs); | 1096 RecordAppLaunches(profile_, urls_to_open, tabs); |
1097 | 1097 |
1098 if (!urls_to_open.empty()) { | 1098 if (!urls_to_open.empty()) { |
1099 // If urls were specified on the command line, use them. | 1099 // If urls were specified on the command line, use them. |
1100 UrlsToTabs(urls_to_open, &tabs); | 1100 UrlsToTabs(urls_to_open, &tabs); |
1101 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty()) { | 1101 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty()) { |
1102 // Only use the set of urls specified in preferences if nothing was | 1102 // Only use the set of urls specified in preferences if nothing was |
1103 // specified on the command line. Filter out any urls that are to be | 1103 // specified on the command line. Filter out any urls that are to be |
1104 // restored by virtue of having been previously pinned. | 1104 // restored by virtue of having been previously pinned. |
1105 AddUniqueURLs(pref.urls, &tabs); | 1105 AddUniqueURLs(pref.urls, &tabs); |
1106 } else if (pref.type == SessionStartupPref::DEFAULT && !tabs.empty()) { | 1106 } else if (pref.type == SessionStartupPref::NEWTAB) { |
1107 // Make sure the home page is opened even if there are pinned tabs. | 1107 BrowserInit::LaunchWithProfile::Tab tab; |
1108 std::vector<GURL> urls; | 1108 tab.is_pinned = false; |
1109 AddStartupURLs(&urls); | 1109 tab.url = GURL(chrome::kChromeUINewTabURL); |
1110 UrlsToTabs(urls, &tabs); | 1110 tabs.push_back(tab); |
| 1111 } else if (pref.type == SessionStartupPref::HOMEPAGE) { |
| 1112 // If the user had 'homepage' selected, we should have migrated |
| 1113 // them to 'URLS' instead. |
| 1114 DLOG(ERROR) << "pref.type == HOMEPAGE"; |
| 1115 NOTREACHED(); |
1111 } | 1116 } |
1112 | 1117 |
1113 if (tabs.empty()) | 1118 if (tabs.empty()) |
1114 return NULL; | 1119 return NULL; |
1115 | 1120 |
1116 Browser* browser = OpenTabsInBrowser(NULL, true, tabs); | 1121 Browser* browser = OpenTabsInBrowser(NULL, true, tabs); |
1117 return browser; | 1122 return browser; |
1118 } | 1123 } |
1119 | 1124 |
1120 void BrowserInit::LaunchWithProfile::AddUniqueURLs( | 1125 void BrowserInit::LaunchWithProfile::AddUniqueURLs( |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1769 | 1774 |
1770 Profile* profile = ProfileManager::GetLastUsedProfile(); | 1775 Profile* profile = ProfileManager::GetLastUsedProfile(); |
1771 if (!profile) { | 1776 if (!profile) { |
1772 // We should only be able to get here if the profile already exists and | 1777 // We should only be able to get here if the profile already exists and |
1773 // has been created. | 1778 // has been created. |
1774 NOTREACHED(); | 1779 NOTREACHED(); |
1775 return; | 1780 return; |
1776 } | 1781 } |
1777 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); | 1782 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); |
1778 } | 1783 } |
OLD | NEW |