OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 static_cast<Browser::Type>((*i)->type), | 463 static_cast<Browser::Type>((*i)->type), |
464 (*i)->bounds, | 464 (*i)->bounds, |
465 (*i)->show_state); | 465 (*i)->show_state); |
466 | 466 |
467 // Restore and show the browser. | 467 // Restore and show the browser. |
468 const int initial_tab_count = browser->tab_count(); | 468 const int initial_tab_count = browser->tab_count(); |
469 int selected_tab_index = (*i)->selected_tab_index; | 469 int selected_tab_index = (*i)->selected_tab_index; |
470 RestoreTabsToBrowser(*(*i), browser, selected_tab_index); | 470 RestoreTabsToBrowser(*(*i), browser, selected_tab_index); |
471 ShowBrowser(browser, initial_tab_count, selected_tab_index); | 471 ShowBrowser(browser, initial_tab_count, selected_tab_index); |
472 tab_loader_->TabIsLoading( | 472 tab_loader_->TabIsLoading( |
473 &browser->GetSelectedTabContents()->GetController()); | 473 &browser->GetSelectedWebContents()->GetController()); |
474 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); | 474 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); |
475 } | 475 } |
476 | 476 |
477 // Always create in a new window | 477 // Always create in a new window |
478 FinishedTabCreation(true, true); | 478 FinishedTabCreation(true, true); |
479 } | 479 } |
480 | 480 |
481 // Restore a single tab from a foreign session. | 481 // Restore a single tab from a foreign session. |
482 // Note: we currently restore the tab to the last active browser. | 482 // Note: we currently restore the tab to the last active browser. |
483 void RestoreForeignTab(const SessionTab& tab) { | 483 void RestoreForeignTab(const SessionTab& tab) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 | 644 |
645 browser = CreateRestoredBrowser( | 645 browser = CreateRestoredBrowser( |
646 static_cast<Browser::Type>((*i)->type), (*i)->bounds, show_state); | 646 static_cast<Browser::Type>((*i)->type), (*i)->bounds, show_state); |
647 #if defined(OS_CHROMEOS) | 647 #if defined(OS_CHROMEOS) |
648 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 648 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
649 "SessionRestore-CreateRestoredBrowser-End", false); | 649 "SessionRestore-CreateRestoredBrowser-End", false); |
650 #endif | 650 #endif |
651 } | 651 } |
652 if ((*i)->type == Browser::TYPE_TABBED) | 652 if ((*i)->type == Browser::TYPE_TABBED) |
653 last_browser = browser; | 653 last_browser = browser; |
654 TabContents* active_tab = browser->GetSelectedTabContents(); | 654 WebContents* active_tab = browser->GetSelectedWebContents(); |
655 int initial_tab_count = browser->tab_count(); | 655 int initial_tab_count = browser->tab_count(); |
656 int selected_tab_index = (*i)->selected_tab_index; | 656 int selected_tab_index = (*i)->selected_tab_index; |
657 RestoreTabsToBrowser(*(*i), browser, selected_tab_index); | 657 RestoreTabsToBrowser(*(*i), browser, selected_tab_index); |
658 ShowBrowser(browser, initial_tab_count, selected_tab_index); | 658 ShowBrowser(browser, initial_tab_count, selected_tab_index); |
659 if (clobber_existing_tab_ && i == windows->begin() && | 659 if (clobber_existing_tab_ && i == windows->begin() && |
660 (*i)->type == Browser::TYPE_TABBED && active_tab && | 660 (*i)->type == Browser::TYPE_TABBED && active_tab && |
661 browser == browser_ && browser->tab_count() > initial_tab_count) { | 661 browser == browser_ && browser->tab_count() > initial_tab_count) { |
662 browser->CloseTabContents(active_tab); | 662 browser->CloseTabContents(active_tab); |
663 active_tab = NULL; | 663 active_tab = NULL; |
664 } | 664 } |
665 tab_loader_->TabIsLoading( | 665 tab_loader_->TabIsLoading( |
666 &browser->GetSelectedTabContents()->GetController()); | 666 &browser->GetSelectedWebContents()->GetController()); |
667 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); | 667 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); |
668 } | 668 } |
669 | 669 |
670 if (last_browser && !urls_to_open_.empty()) | 670 if (last_browser && !urls_to_open_.empty()) |
671 AppendURLsToBrowser(last_browser, urls_to_open_); | 671 AppendURLsToBrowser(last_browser, urls_to_open_); |
672 #if defined(OS_CHROMEOS) | 672 #if defined(OS_CHROMEOS) |
673 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 673 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
674 "SessionRestore-CreatingTabs-End", false); | 674 "SessionRestore-CreatingTabs-End", false); |
675 #endif | 675 #endif |
676 // If last_browser is NULL and urls_to_open_ is non-empty, | 676 // If last_browser is NULL and urls_to_open_ is non-empty, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 if ( | 715 if ( |
716 #if defined(OS_CHROMEOS) | 716 #if defined(OS_CHROMEOS) |
717 browser->profile()->GetExtensionService() && | 717 browser->profile()->GetExtensionService() && |
718 #endif | 718 #endif |
719 browser->profile()->GetExtensionService()->IsInstalledApp(url)) { | 719 browser->profile()->GetExtensionService()->IsInstalledApp(url)) { |
720 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, | 720 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, |
721 extension_misc::APP_LAUNCH_SESSION_RESTORE, | 721 extension_misc::APP_LAUNCH_SESSION_RESTORE, |
722 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 722 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
723 } | 723 } |
724 | 724 |
725 TabContents* tab_contents = | 725 WebContents* web_contents = |
726 browser->AddRestoredTab(tab.navigations, | 726 browser->AddRestoredTab(tab.navigations, |
727 tab_index, | 727 tab_index, |
728 selected_index, | 728 selected_index, |
729 tab.extension_app_id, | 729 tab.extension_app_id, |
730 false, | 730 false, |
731 tab.pinned, | 731 tab.pinned, |
732 true, | 732 true, |
733 NULL); | 733 NULL); |
734 if (schedule_load) | 734 if (schedule_load) |
735 tab_loader_->ScheduleLoad(&tab_contents->GetController()); | 735 tab_loader_->ScheduleLoad(&web_contents->GetController()); |
736 } | 736 } |
737 | 737 |
738 Browser* CreateRestoredBrowser(Browser::Type type, | 738 Browser* CreateRestoredBrowser(Browser::Type type, |
739 gfx::Rect bounds, | 739 gfx::Rect bounds, |
740 ui::WindowShowState show_state) { | 740 ui::WindowShowState show_state) { |
741 Browser* browser = new Browser(type, profile_); | 741 Browser* browser = new Browser(type, profile_); |
742 browser->set_override_bounds(bounds); | 742 browser->set_override_bounds(bounds); |
743 browser->set_show_state(show_state); | 743 browser->set_show_state(show_state); |
744 browser->set_is_session_restore(true); | 744 browser->set_is_session_restore(true); |
745 browser->InitBrowserWindow(); | 745 browser->InitBrowserWindow(); |
(...skipping 10 matching lines...) Expand all Loading... |
756 browser->tab_count() - 1), true); | 756 browser->tab_count() - 1), true); |
757 | 757 |
758 if (browser_ == browser) | 758 if (browser_ == browser) |
759 return; | 759 return; |
760 | 760 |
761 browser->window()->Show(); | 761 browser->window()->Show(); |
762 browser->set_is_session_restore(false); | 762 browser->set_is_session_restore(false); |
763 | 763 |
764 // TODO(jcampan): http://crbug.com/8123 we should not need to set the | 764 // TODO(jcampan): http://crbug.com/8123 we should not need to set the |
765 // initial focus explicitly. | 765 // initial focus explicitly. |
766 browser->GetSelectedTabContents()->GetView()->SetInitialFocus(); | 766 browser->GetSelectedWebContents()->GetView()->SetInitialFocus(); |
767 | 767 |
768 if (!browser_shown_) { | 768 if (!browser_shown_) { |
769 browser_shown_ = true; | 769 browser_shown_ = true; |
770 base::TimeDelta time_to_first_show = | 770 base::TimeDelta time_to_first_show = |
771 base::TimeTicks::Now() - restore_started_; | 771 base::TimeTicks::Now() - restore_started_; |
772 UMA_HISTOGRAM_CUSTOM_TIMES( | 772 UMA_HISTOGRAM_CUSTOM_TIMES( |
773 "SessionRestore.TimeToFirstShow", | 773 "SessionRestore.TimeToFirstShow", |
774 time_to_first_show, | 774 time_to_first_show, |
775 base::TimeDelta::FromMilliseconds(10), | 775 base::TimeDelta::FromMilliseconds(10), |
776 base::TimeDelta::FromSeconds(1000), | 776 base::TimeDelta::FromSeconds(1000), |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 std::vector<GURL> gurls; | 899 std::vector<GURL> gurls; |
900 SessionRestoreImpl restorer(profile, | 900 SessionRestoreImpl restorer(profile, |
901 static_cast<Browser*>(NULL), true, false, true, gurls); | 901 static_cast<Browser*>(NULL), true, false, true, gurls); |
902 restorer.RestoreForeignTab(tab); | 902 restorer.RestoreForeignTab(tab); |
903 } | 903 } |
904 | 904 |
905 // static | 905 // static |
906 bool SessionRestore::IsRestoring() { | 906 bool SessionRestore::IsRestoring() { |
907 return restoring; | 907 return restoring; |
908 } | 908 } |
OLD | NEW |