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

Side by Side Diff: chrome/browser/sessions/session_restore.cc

Issue 557026: Disables pinned tabs until I land apps. I've #ifdef parts that are... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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
« no previous file with comments | « chrome/browser/browser_init.cc ('k') | chrome/browser/sessions/session_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/sessions/session_restore.h" 5 #include "chrome/browser/sessions/session_restore.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Invoked when done with creating all the tabs/browsers. 221 // Invoked when done with creating all the tabs/browsers.
222 // 222 //
223 // |created_tabbed_browser| indicates whether a tabbed browser was created, 223 // |created_tabbed_browser| indicates whether a tabbed browser was created,
224 // or we used an existing tabbed browser. 224 // or we used an existing tabbed browser.
225 // 225 //
226 // If successful, this begins loading tabs and deletes itself when all tabs 226 // If successful, this begins loading tabs and deletes itself when all tabs
227 // have been loaded. 227 // have been loaded.
228 void FinishedTabCreation(bool succeeded, bool created_tabbed_browser) { 228 void FinishedTabCreation(bool succeeded, bool created_tabbed_browser) {
229 if (!created_tabbed_browser && always_create_tabbed_browser_) { 229 if (!created_tabbed_browser && always_create_tabbed_browser_) {
230 Browser* browser = Browser::Create(profile_); 230 Browser* browser = Browser::Create(profile_);
231 // Honor --pinned-tab-count if we're synchronous (which means we're run
232 // during startup) and the user specified urls on the command line.
233 bool honor_pin_tabs = synchronous_ && !urls_to_open_.empty();
234 if (urls_to_open_.empty()) { 231 if (urls_to_open_.empty()) {
235 // No tab browsers were created and no URLs were supplied on the command 232 // No tab browsers were created and no URLs were supplied on the command
236 // line. Add an empty URL, which is treated as opening the users home 233 // line. Add an empty URL, which is treated as opening the users home
237 // page. 234 // page.
238 urls_to_open_.push_back(GURL()); 235 urls_to_open_.push_back(GURL());
239 } 236 }
240 AppendURLsToBrowser(browser, urls_to_open_, honor_pin_tabs); 237 AppendURLsToBrowser(browser, urls_to_open_);
241 browser->window()->Show(); 238 browser->window()->Show();
242 } 239 }
243 240
244 if (succeeded) { 241 if (succeeded) {
245 DCHECK(tab_loader_.get()); 242 DCHECK(tab_loader_.get());
246 // TabLoader delets itself when done loading. 243 // TabLoader delets itself when done loading.
247 tab_loader_.release()->LoadTabs(); 244 tab_loader_.release()->LoadTabs();
248 } 245 }
249 246
250 if (!synchronous_) { 247 if (!synchronous_) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 311 }
315 312
316 // If we're restoring a session as the result of a crash and the session 313 // If we're restoring a session as the result of a crash and the session
317 // included at least one tabbed browser, then close the browser window 314 // included at least one tabbed browser, then close the browser window
318 // that was opened when the user clicked to restore the session. 315 // that was opened when the user clicked to restore the session.
319 if (clobber_existing_window_ && current_browser && has_tabbed_browser && 316 if (clobber_existing_window_ && current_browser && has_tabbed_browser &&
320 current_browser->type() == Browser::TYPE_NORMAL) { 317 current_browser->type() == Browser::TYPE_NORMAL) {
321 current_browser->CloseAllTabs(); 318 current_browser->CloseAllTabs();
322 } 319 }
323 if (last_browser && !urls_to_open_.empty()) 320 if (last_browser && !urls_to_open_.empty())
324 AppendURLsToBrowser(last_browser, urls_to_open_, false); 321 AppendURLsToBrowser(last_browser, urls_to_open_);
325 // If last_browser is NULL and urls_to_open_ is non-empty, 322 // If last_browser is NULL and urls_to_open_ is non-empty,
326 // FinishedTabCreation will create a new TabbedBrowser and add the urls to 323 // FinishedTabCreation will create a new TabbedBrowser and add the urls to
327 // it. 324 // it.
328 FinishedTabCreation(true, has_tabbed_browser); 325 FinishedTabCreation(true, has_tabbed_browser);
329 } 326 }
330 327
331 void RestoreTabsToBrowser(const SessionWindow& window, Browser* browser) { 328 void RestoreTabsToBrowser(const SessionWindow& window, Browser* browser) {
332 DCHECK(!window.tabs.empty()); 329 DCHECK(!window.tabs.empty());
333 for (std::vector<SessionTab*>::const_iterator i = window.tabs.begin(); 330 for (std::vector<SessionTab*>::const_iterator i = window.tabs.begin();
334 i != window.tabs.end(); ++i) { 331 i != window.tabs.end(); ++i) {
(...skipping 26 matching lines...) Expand all
361 DCHECK(browser->tab_count()); 358 DCHECK(browser->tab_count());
362 browser->SelectTabContentsAt( 359 browser->SelectTabContentsAt(
363 std::min(initial_tab_count + std::max(0, selected_session_index), 360 std::min(initial_tab_count + std::max(0, selected_session_index),
364 browser->tab_count() - 1), true); 361 browser->tab_count() - 1), true);
365 browser->window()->Show(); 362 browser->window()->Show();
366 // TODO(jcampan): http://crbug.com/8123 we should not need to set the 363 // TODO(jcampan): http://crbug.com/8123 we should not need to set the
367 // initial focus explicitly. 364 // initial focus explicitly.
368 browser->GetSelectedTabContents()->view()->SetInitialFocus(); 365 browser->GetSelectedTabContents()->view()->SetInitialFocus();
369 } 366 }
370 367
371 // Appends the urls in |urls| to |browser|. If |pin_tabs| is true the first n 368 // Appends the urls in |urls| to |browser|.
372 // tabs are pinned, where n is the command line value for --pinned-tab-count.
373 void AppendURLsToBrowser(Browser* browser, 369 void AppendURLsToBrowser(Browser* browser,
374 const std::vector<GURL>& urls, 370 const std::vector<GURL>& urls) {
375 bool pin_tabs) {
376 int pin_count = 0;
377 if (pin_tabs) {
378 std::string pin_count_string =
379 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
380 switches::kPinnedTabCount);
381 if (!pin_count_string.empty())
382 pin_count = StringToInt(pin_count_string);
383 }
384
385 for (size_t i = 0; i < urls.size(); ++i) { 371 for (size_t i = 0; i < urls.size(); ++i) {
386 browser->AddTabWithURL(urls[i], GURL(), PageTransition::START_PAGE, 372 browser->AddTabWithURL(urls[i], GURL(), PageTransition::START_PAGE,
387 (i == 0), -1, false, NULL); 373 (i == 0), -1, false, NULL);
388 if (i < static_cast<size_t>(pin_count)) {
389 browser->tabstrip_model()->SetTabPinned(browser->tab_count() - 1,
390 true);
391 }
392 } 374 }
393 } 375 }
394 376
395 // Invokes TabRestored on the SessionService for all tabs in browser after 377 // Invokes TabRestored on the SessionService for all tabs in browser after
396 // initial_count. 378 // initial_count.
397 void NotifySessionServiceOfRestoredTabs(Browser* browser, int initial_count) { 379 void NotifySessionServiceOfRestoredTabs(Browser* browser, int initial_count) {
398 SessionService* session_service = profile_->GetSessionService(); 380 SessionService* session_service = profile_->GetSessionService();
399 for (int i = initial_count; i < browser->tab_count(); ++i) 381 for (int i = initial_count; i < browser->tab_count(); ++i)
400 session_service->TabRestored(&browser->GetTabContentsAt(i)->controller(), 382 session_service->TabRestored(&browser->GetTabContentsAt(i)->controller(),
401 browser->tabstrip_model()->IsTabPinned(i)); 383 browser->tabstrip_model()->IsTabPinned(i));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 Restore(profile, browser, false, clobber_existing_window, 457 Restore(profile, browser, false, clobber_existing_window,
476 always_create_tabbed_browser, urls_to_open); 458 always_create_tabbed_browser, urls_to_open);
477 } 459 }
478 460
479 // static 461 // static
480 void SessionRestore::RestoreSessionSynchronously( 462 void SessionRestore::RestoreSessionSynchronously(
481 Profile* profile, 463 Profile* profile,
482 const std::vector<GURL>& urls_to_open) { 464 const std::vector<GURL>& urls_to_open) {
483 Restore(profile, NULL, true, false, true, urls_to_open); 465 Restore(profile, NULL, true, false, true, urls_to_open);
484 } 466 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_init.cc ('k') | chrome/browser/sessions/session_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698