diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 05:14:13 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 05:14:13 +0000 |
commit | 48e4c173c27c8b539b0719c96985e50651b80d3b (patch) | |
tree | fb5b8f2fbf3e4dec9df5ca8701c176d961575ffe /chrome/browser/sessions/session_restore.cc | |
parent | 6f0d470c811bd661163bda6525bf3c0bfe1758bd (diff) | |
download | chromium_src-48e4c173c27c8b539b0719c96985e50651b80d3b.zip chromium_src-48e4c173c27c8b539b0719c96985e50651b80d3b.tar.gz chromium_src-48e4c173c27c8b539b0719c96985e50651b80d3b.tar.bz2 |
Makes --pinned-tab-count work if session restore is enabled, but we
don't restore anything.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/155667
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20935 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions/session_restore.cc')
-rw-r--r-- | chrome/browser/sessions/session_restore.cc | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc index 871d256..79f3d36 100644 --- a/chrome/browser/sessions/session_restore.cc +++ b/chrome/browser/sessions/session_restore.cc @@ -6,7 +6,9 @@ #include <vector> +#include "base/command_line.h" #include "base/scoped_ptr.h" +#include "base/string_util.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" @@ -17,6 +19,7 @@ #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" @@ -222,13 +225,16 @@ class SessionRestoreImpl : public NotificationObserver { void FinishedTabCreation(bool succeeded, bool created_tabbed_browser) { if (!created_tabbed_browser && always_create_tabbed_browser_) { Browser* browser = Browser::Create(profile_); + // Honor --pinned-tab-count if we're synchronous (which means we're run + // during startup) and the user specified urls on the command line. + bool honor_pin_tabs = synchronous_ && !urls_to_open_.empty(); if (urls_to_open_.empty()) { // No tab browsers were created and no URLs were supplied on the command // line. Add an empty URL, which is treated as opening the users home // page. urls_to_open_.push_back(GURL()); } - AppendURLsToBrowser(browser, urls_to_open_); + AppendURLsToBrowser(browser, urls_to_open_, honor_pin_tabs); browser->window()->Show(); } @@ -305,7 +311,7 @@ class SessionRestoreImpl : public NotificationObserver { current_browser->CloseAllTabs(); } if (last_browser && !urls_to_open_.empty()) - AppendURLsToBrowser(last_browser, urls_to_open_); + AppendURLsToBrowser(last_browser, urls_to_open_, false); // If last_browser is NULL and urls_to_open_ is non-empty, // FinishedTabCreation will create a new TabbedBrowser and add the urls to // it. @@ -351,10 +357,27 @@ class SessionRestoreImpl : public NotificationObserver { browser->GetSelectedTabContents()->view()->SetInitialFocus(); } - void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) { + // Appends the urls in |urls| to |browser|. If |pin_tabs| is true the first n + // tabs are pinned, where n is the command line value for --pinned-tab-count. + void AppendURLsToBrowser(Browser* browser, + const std::vector<GURL>& urls, + bool pin_tabs) { + int pin_count = 0; + if (pin_tabs) { + std::wstring pin_count_string = + CommandLine::ForCurrentProcess()->GetSwitchValue( + switches::kPinnedTabCount); + if (!pin_count_string.empty()) + pin_count = StringToInt(WideToUTF16Hack(pin_count_string)); + } + for (size_t i = 0; i < urls.size(); ++i) { browser->AddTabWithURL(urls[i], GURL(), PageTransition::START_PAGE, (i == 0), -1, false, NULL); + if (i < static_cast<size_t>(pin_count)) { + browser->tabstrip_model()->SetTabPinned(browser->tab_count() - 1, + true); + } } } |