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

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

Issue 2714483003: cros: Fix restoring session windows after crash inconsistent minimized window counts (Closed)
Patch Set: improved comments Created 3 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
« no previous file with comments | « no previous file | chrome/browser/sessions/session_restore_browsertest.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/sessions/session_restore.h" 5 #include "chrome/browser/sessions/session_restore.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 386
387 // After the for loop, this contains the browser to activate, if one of the 387 // After the for loop, this contains the browser to activate, if one of the
388 // windows has the same id as specified in active_window_id. 388 // windows has the same id as specified in active_window_id.
389 Browser* browser_to_activate = nullptr; 389 Browser* browser_to_activate = nullptr;
390 390
391 // Determine if there is a visible window, or if the active window exists. 391 // Determine if there is a visible window, or if the active window exists.
392 // Even if all windows are ui::SHOW_STATE_MINIMIZED, if one of them is the 392 // Even if all windows are ui::SHOW_STATE_MINIMIZED, if one of them is the
393 // active window it will be made visible by the call to 393 // active window it will be made visible by the call to
394 // browser_to_activate->window()->Activate() later on in this method. 394 // browser_to_activate->window()->Activate() later on in this method.
395 bool has_visible_browser = false; 395 bool has_visible_browser = false;
396 for (const auto& window : *windows) { 396 for (const auto& window : *windows) {
sky 2017/03/07 22:41:33 This function is getting rather long and hard to r
397 if (window->show_state != ui::SHOW_STATE_MINIMIZED || 397 if (window->show_state != ui::SHOW_STATE_MINIMIZED ||
398 window->window_id.id() == active_window_id) 398 window->window_id.id() == active_window_id) {
399 has_visible_browser = true; 399 has_visible_browser = true;
400 break;
401 }
402 }
403
404 // If |browser_| exists, is on-record, and tabbed, we need to firstly
405 // consider restoring tabs from active window to |browser_|. If active
406 // tabbed window doesn't exist, restore the first set of tabs instead.
407 bool active_window_on_existing_browser = false;
sky 2017/03/07 22:41:33 Renane to browser_is_active_window.
408 bool first_window_on_existing_browser = false;
sky 2017/03/07 22:41:32 Rename to restore_first_window_to_browser.
409 if (browser_ && browser_->is_type_tabbed() &&
410 !browser_->profile()->IsOffTheRecord()) {
411 for (auto i = windows->begin(); i != windows->end(); ++i) {
412 if ((*i)->type != sessions::SessionWindow::TYPE_TABBED)
413 continue;
414
415 if ((*i)->window_id.id() == active_window_id) {
416 active_window_on_existing_browser = true;
sky 2017/03/07 22:41:33 I think you should only do this logic if the brows
Qiang(Joe) Xu 2017/03/08 04:59:38 I checked the visibility of |browser_|'s native wi
417 break;
418 }
419 }
420
421 if (!active_window_on_existing_browser &&
422 (*windows->begin())->type == sessions::SessionWindow::TYPE_TABBED) {
423 first_window_on_existing_browser = true;
424 }
400 } 425 }
401 426
402 for (auto i = windows->begin(); i != windows->end(); ++i) { 427 for (auto i = windows->begin(); i != windows->end(); ++i) {
403 Browser* browser = nullptr; 428 Browser* browser = nullptr;
404 if (!has_tabbed_browser && 429 if (!has_tabbed_browser &&
405 (*i)->type == sessions::SessionWindow::TYPE_TABBED) 430 (*i)->type == sessions::SessionWindow::TYPE_TABBED) {
406 has_tabbed_browser = true; 431 has_tabbed_browser = true;
407 if (i == windows->begin() && 432 }
408 (*i)->type == sessions::SessionWindow::TYPE_TABBED && browser_ && 433
409 browser_->is_type_tabbed() && 434 if ((active_window_on_existing_browser &&
410 !browser_->profile()->IsOffTheRecord()) { 435 (*i)->window_id.id() == active_window_id) ||
411 // The first set of tabs is added to the existing browser. 436 (first_window_on_existing_browser && i == windows->begin())) {
sky 2017/03/07 22:41:33 That you have to check windows->begin() here is co
412 browser = browser_; 437 browser = browser_;
413 } else { 438 } else {
414 #if defined(OS_CHROMEOS) 439 #if defined(OS_CHROMEOS)
415 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( 440 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker(
416 "SessionRestore-CreateRestoredBrowser-Start", false); 441 "SessionRestore-CreateRestoredBrowser-Start", false);
417 #endif 442 #endif
418 // Show the first window if none are visible. 443 // Show the first window if none are visible.
419 ui::WindowShowState show_state = (*i)->show_state; 444 ui::WindowShowState show_state = (*i)->show_state;
420 if (!has_visible_browser) { 445 if (!has_visible_browser) {
421 show_state = ui::SHOW_STATE_NORMAL; 446 show_state = ui::SHOW_STATE_NORMAL;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 browser->tab_strip_model()->ActivateTabAt(selected_tab_index, true); 674 browser->tab_strip_model()->ActivateTabAt(selected_tab_index, true);
650 675
651 if (browser_ == browser) 676 if (browser_ == browser)
652 return; 677 return;
653 678
654 browser->window()->Show(); 679 browser->window()->Show();
655 browser->set_is_session_restore(false); 680 browser->set_is_session_restore(false);
656 681
657 // TODO(jcampan): http://crbug.com/8123 we should not need to set the 682 // TODO(jcampan): http://crbug.com/8123 we should not need to set the
658 // initial focus explicitly. 683 // initial focus explicitly.
659 browser->tab_strip_model()->GetActiveWebContents()->SetInitialFocus(); 684 if (browser->window()->IsActive())
685 browser->tab_strip_model()->GetActiveWebContents()->SetInitialFocus();
660 } 686 }
661 687
662 // Appends the urls in |urls| to |browser|. 688 // Appends the urls in |urls| to |browser|.
663 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) { 689 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) {
664 for (size_t i = 0; i < urls.size(); ++i) { 690 for (size_t i = 0; i < urls.size(); ++i) {
665 int add_types = TabStripModel::ADD_FORCE_INDEX; 691 int add_types = TabStripModel::ADD_FORCE_INDEX;
666 if (i == 0) 692 if (i == 0)
667 add_types |= TabStripModel::ADD_ACTIVE; 693 add_types |= TabStripModel::ADD_ACTIVE;
668 chrome::NavigateParams params(browser, urls[i], 694 chrome::NavigateParams params(browser, urls[i],
669 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); 695 ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 // static 870 // static
845 SessionRestore::CallbackSubscription 871 SessionRestore::CallbackSubscription
846 SessionRestore::RegisterOnSessionRestoredCallback( 872 SessionRestore::RegisterOnSessionRestoredCallback(
847 const base::Callback<void(int)>& callback) { 873 const base::Callback<void(int)>& callback) {
848 return on_session_restored_callbacks()->Add(callback); 874 return on_session_restored_callbacks()->Add(callback);
849 } 875 }
850 876
851 // static 877 // static
852 base::CallbackList<void(int)>* 878 base::CallbackList<void(int)>*
853 SessionRestore::on_session_restored_callbacks_ = nullptr; 879 SessionRestore::on_session_restored_callbacks_ = nullptr;
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sessions/session_restore_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698