Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 void TabIsLoading(NavigationController* controller); | 104 void TabIsLoading(NavigationController* controller); |
| 105 | 105 |
| 106 // Invokes |LoadNextTab| to load a tab. | 106 // Invokes |LoadNextTab| to load a tab. |
| 107 // | 107 // |
| 108 // This must be invoked once to start loading. | 108 // This must be invoked once to start loading. |
| 109 void StartLoading(); | 109 void StartLoading(); |
| 110 | 110 |
| 111 // TabLoaderCallback: | 111 // TabLoaderCallback: |
| 112 void SetTabLoadingEnabled(bool enable_tab_loading) override; | 112 void SetTabLoadingEnabled(bool enable_tab_loading) override; |
| 113 | 113 |
| 114 void set_on_session_restored_callbacks( | |
| 115 SessionRestore::CallbackList* callbacks) { | |
| 116 on_session_restored_callbacks_ = callbacks; | |
| 117 } | |
| 118 | |
| 119 private: | 114 private: |
| 120 friend class base::RefCounted<TabLoader>; | 115 friend class base::RefCounted<TabLoader>; |
| 121 | 116 |
| 122 typedef std::set<NavigationController*> TabsLoading; | 117 typedef std::set<NavigationController*> TabsLoading; |
| 123 typedef std::list<NavigationController*> TabsToLoad; | 118 typedef std::list<NavigationController*> TabsToLoad; |
| 124 typedef std::set<RenderWidgetHost*> RenderWidgetHostSet; | 119 typedef std::set<RenderWidgetHost*> RenderWidgetHostSet; |
| 125 | 120 |
| 126 explicit TabLoader(base::TimeTicks restore_started); | 121 explicit TabLoader(base::TimeTicks restore_started); |
| 127 ~TabLoader() override; | 122 ~TabLoader() override; |
| 128 | 123 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 int tab_count_; | 198 int tab_count_; |
| 204 | 199 |
| 205 base::OneShotTimer<TabLoader> force_load_timer_; | 200 base::OneShotTimer<TabLoader> force_load_timer_; |
| 206 | 201 |
| 207 // The time the restore process started. | 202 // The time the restore process started. |
| 208 base::TimeTicks restore_started_; | 203 base::TimeTicks restore_started_; |
| 209 | 204 |
| 210 // Max number of tabs that were loaded in parallel (for metrics). | 205 // Max number of tabs that were loaded in parallel (for metrics). |
| 211 size_t max_parallel_tab_loads_; | 206 size_t max_parallel_tab_loads_; |
| 212 | 207 |
| 213 // Callback list for sending a session restore notification. | |
| 214 SessionRestore::CallbackList* on_session_restored_callbacks_; | |
| 215 | |
| 216 // For keeping TabLoader alive while it's loading even if no | 208 // For keeping TabLoader alive while it's loading even if no |
| 217 // SessionRestoreImpls reference it. | 209 // SessionRestoreImpls reference it. |
| 218 scoped_refptr<TabLoader> this_retainer_; | 210 scoped_refptr<TabLoader> this_retainer_; |
| 219 | 211 |
| 220 DISALLOW_COPY_AND_ASSIGN(TabLoader); | 212 DISALLOW_COPY_AND_ASSIGN(TabLoader); |
| 221 }; | 213 }; |
| 222 | 214 |
| 223 // static | 215 // static |
| 224 TabLoader* TabLoader::GetTabLoader(base::TimeTicks restore_started) { | 216 TabLoader* TabLoader::GetTabLoader(base::TimeTicks restore_started) { |
| 225 if (!shared_tab_loader) | 217 if (!shared_tab_loader) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 return; | 268 return; |
| 277 loading_enabled_ = enable_tab_loading; | 269 loading_enabled_ = enable_tab_loading; |
| 278 if (loading_enabled_) | 270 if (loading_enabled_) |
| 279 LoadNextTab(); | 271 LoadNextTab(); |
| 280 else | 272 else |
| 281 force_load_timer_.Stop(); | 273 force_load_timer_.Stop(); |
| 282 } | 274 } |
| 283 | 275 |
| 284 TabLoader::TabLoader(base::TimeTicks restore_started) | 276 TabLoader::TabLoader(base::TimeTicks restore_started) |
| 285 : memory_pressure_listener_( | 277 : memory_pressure_listener_( |
| 286 base::Bind(&TabLoader::OnMemoryPressure, base::Unretained(this))), | 278 base::Bind(&TabLoader::OnMemoryPressure, base::Unretained(this))), |
| 287 force_load_delay_multiplier_(1), | 279 force_load_delay_multiplier_(1), |
| 288 loading_enabled_(true), | 280 loading_enabled_(true), |
| 289 got_first_foreground_load_(false), | 281 got_first_foreground_load_(false), |
| 290 got_first_paint_(false), | 282 got_first_paint_(false), |
| 291 tab_count_(0), | 283 tab_count_(0), |
| 292 restore_started_(restore_started), | 284 restore_started_(restore_started), |
| 293 max_parallel_tab_loads_(0), | 285 max_parallel_tab_loads_(0) { |
| 294 on_session_restored_callbacks_(nullptr) { | |
| 295 } | 286 } |
| 296 | 287 |
| 297 TabLoader::~TabLoader() { | 288 TabLoader::~TabLoader() { |
| 298 DCHECK((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && | 289 DCHECK((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && |
| 299 tabs_loading_.empty() && tabs_to_load_.empty()); | 290 tabs_loading_.empty() && tabs_to_load_.empty()); |
| 300 shared_tab_loader = NULL; | 291 shared_tab_loader = NULL; |
| 301 } | 292 } |
| 302 | 293 |
| 303 void TabLoader::LoadNextTab() { | 294 void TabLoader::LoadNextTab() { |
| 304 // LoadNextTab should only get called after we have started the tab | 295 // LoadNextTab should only get called after we have started the tab |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 324 // NOTE: We need to do this here rather than when the tab is added to | 315 // NOTE: We need to do this here rather than when the tab is added to |
| 325 // the Browser as at that time not everything has been created, so that | 316 // the Browser as at that time not everything has been created, so that |
| 326 // the call would do nothing. | 317 // the call would do nothing. |
| 327 contents->WasHidden(); | 318 contents->WasHidden(); |
| 328 } | 319 } |
| 329 } | 320 } |
| 330 } | 321 } |
| 331 | 322 |
| 332 if (!tabs_to_load_.empty()) | 323 if (!tabs_to_load_.empty()) |
| 333 StartTimer(); | 324 StartTimer(); |
| 334 | |
| 335 // When the session restore is done synchronously, notification is sent from | |
| 336 // SessionRestoreImpl::Restore . | |
| 337 if (tabs_to_load_.empty() && !SessionRestore::IsRestoringSynchronously()) { | |
| 338 on_session_restored_callbacks_->Notify(tab_count_); | |
| 339 } | |
| 340 } | 325 } |
| 341 | 326 |
| 342 void TabLoader::StartTimer() { | 327 void TabLoader::StartTimer() { |
| 343 force_load_timer_.Stop(); | 328 force_load_timer_.Stop(); |
| 344 force_load_timer_.Start(FROM_HERE, | 329 force_load_timer_.Start(FROM_HERE, |
| 345 delegate_->GetTimeoutBeforeLoadingNextTab() * | 330 delegate_->GetTimeoutBeforeLoadingNextTab() * |
| 346 force_load_delay_multiplier_, | 331 force_load_delay_multiplier_, |
| 347 this, &TabLoader::ForceLoadTimerFired); | 332 this, &TabLoader::ForceLoadTimerFired); |
| 348 } | 333 } |
| 349 | 334 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 | 638 |
| 654 if (synchronous_) { | 639 if (synchronous_) { |
| 655 { | 640 { |
| 656 base::MessageLoop::ScopedNestableTaskAllower allow( | 641 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 657 base::MessageLoop::current()); | 642 base::MessageLoop::current()); |
| 658 base::RunLoop loop; | 643 base::RunLoop loop; |
| 659 quit_closure_for_sync_restore_ = loop.QuitClosure(); | 644 quit_closure_for_sync_restore_ = loop.QuitClosure(); |
| 660 loop.Run(); | 645 loop.Run(); |
| 661 quit_closure_for_sync_restore_ = base::Closure(); | 646 quit_closure_for_sync_restore_ = base::Closure(); |
| 662 } | 647 } |
| 663 // Count the total number of tabs in |windows_|. | 648 Browser* browser = |
| 664 int total_num_tabs = 0; | 649 ProcessSessionWindowsAndNotify(&windows_, active_window_id_); |
| 665 for (int i = 0; i < static_cast<int>(windows_.size()); ++i) | |
| 666 total_num_tabs += windows_[i]->tabs.size(); | |
| 667 | |
| 668 Browser* browser = ProcessSessionWindows(&windows_, active_window_id_); | |
| 669 on_session_restored_callbacks_->Notify(total_num_tabs); | |
| 670 delete this; | 650 delete this; |
| 671 return browser; | 651 return browser; |
| 672 } | 652 } |
| 673 | 653 |
| 674 if (browser_) { | 654 if (browser_) { |
| 675 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, | 655 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, |
| 676 content::Source<Browser>(browser_)); | 656 content::Source<Browser>(browser_)); |
| 677 } | 657 } |
| 678 | 658 |
| 679 return browser_; | 659 return browser_; |
| 680 } | 660 } |
| 681 | 661 |
| 682 // Restore window(s) from a foreign session. Returns newly created Browsers. | 662 // Restore window(s) from a foreign session. Returns newly created Browsers. |
| 683 std::vector<Browser*> RestoreForeignSession( | 663 std::vector<Browser*> RestoreForeignSession( |
| 684 std::vector<const sessions::SessionWindow*>::const_iterator begin, | 664 std::vector<const sessions::SessionWindow*>::const_iterator begin, |
| 685 std::vector<const sessions::SessionWindow*>::const_iterator end) { | 665 std::vector<const sessions::SessionWindow*>::const_iterator end) { |
| 686 StartTabCreation(); | 666 StartTabCreation(); |
| 687 std::vector<Browser*> browsers; | 667 std::vector<Browser*> browsers; |
| 668 std::vector<WebContents*> created_contents; | |
| 688 // Create a browser instance to put the restored tabs in. | 669 // Create a browser instance to put the restored tabs in. |
| 689 for (std::vector<const sessions::SessionWindow*>::const_iterator i = begin; | 670 for (std::vector<const sessions::SessionWindow*>::const_iterator i = begin; |
| 690 i != end; ++i) { | 671 i != end; ++i) { |
| 691 Browser* browser = CreateRestoredBrowser( | 672 Browser* browser = CreateRestoredBrowser( |
| 692 BrowserTypeForWindowType((*i)->type), | 673 BrowserTypeForWindowType((*i)->type), |
| 693 (*i)->bounds, | 674 (*i)->bounds, |
| 694 (*i)->show_state, | 675 (*i)->show_state, |
| 695 (*i)->app_name); | 676 (*i)->app_name); |
| 696 browsers.push_back(browser); | 677 browsers.push_back(browser); |
| 697 | 678 |
| 698 // Restore and show the browser. | 679 // Restore and show the browser. |
| 699 const int initial_tab_count = 0; | 680 const int initial_tab_count = 0; |
| 700 int selected_tab_index = std::max( | 681 int selected_tab_index = std::max( |
| 701 0, | 682 0, |
| 702 std::min((*i)->selected_tab_index, | 683 std::min((*i)->selected_tab_index, |
| 703 static_cast<int>((*i)->tabs.size()) - 1)); | 684 static_cast<int>((*i)->tabs.size()) - 1)); |
| 704 RestoreTabsToBrowser(*(*i), browser, initial_tab_count, | 685 RestoreTabsToBrowser(*(*i), browser, initial_tab_count, |
| 705 selected_tab_index); | 686 selected_tab_index, &created_contents); |
| 706 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); | 687 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); |
| 707 } | 688 } |
| 708 | 689 |
| 709 // Always create in a new window | 690 // Always create in a new window. |
| 710 FinishedTabCreation(true, true); | 691 FinishedTabCreation(true, true); |
| 692 | |
| 693 on_session_restored_callbacks_->Notify( | |
| 694 static_cast<int>(created_contents.size())); | |
| 695 | |
| 711 return browsers; | 696 return browsers; |
| 712 } | 697 } |
| 713 | 698 |
| 714 // Restore a single tab from a foreign session. | 699 // Restore a single tab from a foreign session. |
| 715 // Opens in the tab in the last active browser, unless disposition is | 700 // Opens in the tab in the last active browser, unless disposition is |
| 716 // NEW_WINDOW, in which case the tab will be opened in a new browser. Returns | 701 // NEW_WINDOW, in which case the tab will be opened in a new browser. Returns |
| 717 // the WebContents of the restored tab. | 702 // the WebContents of the restored tab. |
| 718 WebContents* RestoreForeignTab(const sessions::SessionTab& tab, | 703 WebContents* RestoreForeignTab(const sessions::SessionTab& tab, |
| 719 WindowOpenDisposition disposition) { | 704 WindowOpenDisposition disposition) { |
| 720 DCHECK(!tab.navigations.empty()); | 705 DCHECK(!tab.navigations.empty()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 if (use_new_window) { | 748 if (use_new_window) { |
| 764 browser->tab_strip_model()->ActivateTabAt(0, true); | 749 browser->tab_strip_model()->ActivateTabAt(0, true); |
| 765 browser->window()->Show(); | 750 browser->window()->Show(); |
| 766 } | 751 } |
| 767 NotifySessionServiceOfRestoredTabs(browser, | 752 NotifySessionServiceOfRestoredTabs(browser, |
| 768 browser->tab_strip_model()->count()); | 753 browser->tab_strip_model()->count()); |
| 769 | 754 |
| 770 // Since FinishedTabCreation() is not called here, |this| will leak if we | 755 // Since FinishedTabCreation() is not called here, |this| will leak if we |
| 771 // are not in sychronous mode. | 756 // are not in sychronous mode. |
| 772 DCHECK(synchronous_); | 757 DCHECK(synchronous_); |
| 758 | |
| 759 on_session_restored_callbacks_->Notify(1); | |
| 760 | |
| 773 return web_contents; | 761 return web_contents; |
| 774 } | 762 } |
| 775 | 763 |
| 776 ~SessionRestoreImpl() override { | 764 ~SessionRestoreImpl() override { |
| 777 STLDeleteElements(&windows_); | 765 STLDeleteElements(&windows_); |
| 778 | 766 |
| 779 active_session_restorers->erase(this); | 767 active_session_restorers->erase(this); |
| 780 if (active_session_restorers->empty()) { | 768 if (active_session_restorers->empty()) { |
| 781 delete active_session_restorers; | 769 delete active_session_restorers; |
| 782 active_session_restorers = NULL; | 770 active_session_restorers = NULL; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 798 break; | 786 break; |
| 799 } | 787 } |
| 800 } | 788 } |
| 801 | 789 |
| 802 Profile* profile() { return profile_; } | 790 Profile* profile() { return profile_; } |
| 803 | 791 |
| 804 private: | 792 private: |
| 805 // Invoked when beginning to create new tabs. Resets the |tab_loader_|. | 793 // Invoked when beginning to create new tabs. Resets the |tab_loader_|. |
| 806 void StartTabCreation() { | 794 void StartTabCreation() { |
| 807 tab_loader_ = TabLoader::GetTabLoader(restore_started_); | 795 tab_loader_ = TabLoader::GetTabLoader(restore_started_); |
| 808 tab_loader_->set_on_session_restored_callbacks( | |
| 809 on_session_restored_callbacks_); | |
| 810 } | 796 } |
| 811 | 797 |
| 812 // Invoked when done with creating all the tabs/browsers. | 798 // Invoked when done with creating all the tabs/browsers. |
| 813 // | 799 // |
| 814 // |created_tabbed_browser| indicates whether a tabbed browser was created, | 800 // |created_tabbed_browser| indicates whether a tabbed browser was created, |
| 815 // or we used an existing tabbed browser. | 801 // or we used an existing tabbed browser. |
| 816 // | 802 // |
| 817 // If successful, this begins loading tabs and deletes itself when all tabs | 803 // If successful, this begins loading tabs and deletes itself when all tabs |
| 818 // have been loaded. | 804 // have been loaded. |
| 819 // | 805 // |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 876 #endif | 862 #endif |
| 877 if (synchronous_) { | 863 if (synchronous_) { |
| 878 // See comment above windows_ as to why we don't process immediately. | 864 // See comment above windows_ as to why we don't process immediately. |
| 879 windows_.swap(windows.get()); | 865 windows_.swap(windows.get()); |
| 880 active_window_id_ = active_window_id; | 866 active_window_id_ = active_window_id; |
| 881 CHECK(!quit_closure_for_sync_restore_.is_null()); | 867 CHECK(!quit_closure_for_sync_restore_.is_null()); |
| 882 quit_closure_for_sync_restore_.Run(); | 868 quit_closure_for_sync_restore_.Run(); |
| 883 return; | 869 return; |
| 884 } | 870 } |
| 885 | 871 |
| 886 ProcessSessionWindows(&windows.get(), active_window_id); | 872 ProcessSessionWindowsAndNotify(&windows.get(), active_window_id); |
| 873 } | |
| 874 | |
| 875 Browser* ProcessSessionWindowsAndNotify( | |
| 876 std::vector<sessions::SessionWindow*>* windows, | |
| 877 SessionID::id_type active_window_id) { | |
| 878 std::vector<WebContents*> contents; | |
| 879 Browser* result = | |
| 880 ProcessSessionWindows(windows, active_window_id, &contents); | |
| 881 on_session_restored_callbacks_->Notify(static_cast<int>(contents.size())); | |
| 882 return result; | |
| 887 } | 883 } |
| 888 | 884 |
| 889 Browser* ProcessSessionWindows(std::vector<sessions::SessionWindow*>* windows, | 885 Browser* ProcessSessionWindows(std::vector<sessions::SessionWindow*>* windows, |
| 890 SessionID::id_type active_window_id) { | 886 SessionID::id_type active_window_id, |
| 887 std::vector<WebContents*>* created_contents) { | |
| 891 DVLOG(1) << "ProcessSessionWindows " << windows->size(); | 888 DVLOG(1) << "ProcessSessionWindows " << windows->size(); |
| 892 base::TimeDelta time_to_process_sessions = | 889 base::TimeDelta time_to_process_sessions = |
| 893 base::TimeTicks::Now() - restore_started_; | 890 base::TimeTicks::Now() - restore_started_; |
| 894 UMA_HISTOGRAM_CUSTOM_TIMES( | 891 UMA_HISTOGRAM_CUSTOM_TIMES( |
| 895 "SessionRestore.TimeToProcessSessions", | 892 "SessionRestore.TimeToProcessSessions", |
| 896 time_to_process_sessions, | 893 time_to_process_sessions, |
| 897 base::TimeDelta::FromMilliseconds(10), | 894 base::TimeDelta::FromMilliseconds(10), |
| 898 base::TimeDelta::FromSeconds(1000), | 895 base::TimeDelta::FromSeconds(1000), |
| 899 100); | 896 100); |
| 900 | 897 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 977 --initial_tab_count; | 974 --initial_tab_count; |
| 978 int selected_tab_index = | 975 int selected_tab_index = |
| 979 initial_tab_count > 0 ? browser->tab_strip_model()->active_index() | 976 initial_tab_count > 0 ? browser->tab_strip_model()->active_index() |
| 980 : std::max(0, | 977 : std::max(0, |
| 981 std::min((*i)->selected_tab_index, | 978 std::min((*i)->selected_tab_index, |
| 982 static_cast<int>((*i)->tabs.size()) - 1)); | 979 static_cast<int>((*i)->tabs.size()) - 1)); |
| 983 if ((*i)->window_id.id() == active_window_id) | 980 if ((*i)->window_id.id() == active_window_id) |
| 984 browser_to_activate = browser; | 981 browser_to_activate = browser; |
| 985 | 982 |
| 986 RestoreTabsToBrowser(*(*i), browser, initial_tab_count, | 983 RestoreTabsToBrowser(*(*i), browser, initial_tab_count, |
| 987 selected_tab_index); | 984 selected_tab_index, created_contents); |
| 988 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); | 985 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); |
| 989 // This needs to be done after restore because closing the last tab will | 986 // This needs to be done after restore because closing the last tab will |
| 990 // close the whole window. | 987 // close the whole window. |
| 991 if (close_active_tab) | 988 if (close_active_tab) |
| 992 chrome::CloseWebContents(browser, active_tab, true); | 989 chrome::CloseWebContents(browser, active_tab, true); |
| 993 } | 990 } |
| 994 | 991 |
| 995 if (browser_to_activate && browser_to_activate->is_type_tabbed()) | 992 if (browser_to_activate && browser_to_activate->is_type_tabbed()) |
| 996 last_browser = browser_to_activate; | 993 last_browser = browser_to_activate; |
| 997 | 994 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1036 extension_misc::APP_LAUNCH_SESSION_RESTORE, | 1033 extension_misc::APP_LAUNCH_SESSION_RESTORE, |
| 1037 extension->GetType()); | 1034 extension->GetType()); |
| 1038 } | 1035 } |
| 1039 } | 1036 } |
| 1040 | 1037 |
| 1041 // Adds the tabs from |window| to |browser|. Normal tabs go after the existing | 1038 // Adds the tabs from |window| to |browser|. Normal tabs go after the existing |
| 1042 // tabs but pinned tabs will be pushed in front. | 1039 // tabs but pinned tabs will be pushed in front. |
| 1043 // If there are no existing tabs, the tab at |selected_tab_index| will be | 1040 // If there are no existing tabs, the tab at |selected_tab_index| will be |
| 1044 // selected. Otherwise, the tab selection will remain untouched. | 1041 // selected. Otherwise, the tab selection will remain untouched. |
| 1045 void RestoreTabsToBrowser(const sessions::SessionWindow& window, | 1042 void RestoreTabsToBrowser(const sessions::SessionWindow& window, |
| 1046 Browser* browser, | 1043 Browser* browser, |
| 1047 int initial_tab_count, | 1044 int initial_tab_count, |
| 1048 int selected_tab_index) { | 1045 int selected_tab_index, |
| 1046 std::vector<WebContents*>* created_contents) { | |
|
Mr4D (OOO till 08-26)
2015/03/20 16:22:38
I did look over the code several times and I am no
sky
2015/03/20 16:35:10
Ya, sorry, I should have explained. TabLoader is g
| |
| 1049 DVLOG(1) << "RestoreTabsToBrowser " << window.tabs.size(); | 1047 DVLOG(1) << "RestoreTabsToBrowser " << window.tabs.size(); |
| 1050 DCHECK(!window.tabs.empty()); | 1048 DCHECK(!window.tabs.empty()); |
| 1051 if (initial_tab_count == 0) { | 1049 if (initial_tab_count == 0) { |
| 1052 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { | 1050 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { |
| 1053 const sessions::SessionTab& tab = *(window.tabs[i]); | 1051 const sessions::SessionTab& tab = *(window.tabs[i]); |
| 1054 | 1052 |
| 1055 // Loads are scheduled for each restored tab unless the tab is going to | 1053 // Loads are scheduled for each restored tab unless the tab is going to |
| 1056 // be selected as ShowBrowser() will load the selected tab. | 1054 // be selected as ShowBrowser() will load the selected tab. |
| 1057 bool is_selected_tab = (i == selected_tab_index); | 1055 bool is_selected_tab = (i == selected_tab_index); |
| 1058 WebContents* restored_tab = | 1056 WebContents* restored_tab = |
| 1059 RestoreTab(tab, i, browser, is_selected_tab); | 1057 RestoreTab(tab, i, browser, is_selected_tab); |
| 1060 | 1058 |
| 1061 // RestoreTab can return NULL if |tab| doesn't have valid data. | 1059 // RestoreTab can return NULL if |tab| doesn't have valid data. |
| 1062 if (!restored_tab) | 1060 if (!restored_tab) |
| 1063 continue; | 1061 continue; |
| 1064 | 1062 |
| 1063 created_contents->push_back(restored_tab); | |
| 1064 | |
| 1065 // If this isn't the selected tab, there's nothing else to do. | 1065 // If this isn't the selected tab, there's nothing else to do. |
| 1066 if (!is_selected_tab) | 1066 if (!is_selected_tab) |
| 1067 continue; | 1067 continue; |
| 1068 | 1068 |
| 1069 ShowBrowser( | 1069 ShowBrowser( |
| 1070 browser, | 1070 browser, |
| 1071 browser->tab_strip_model()->GetIndexOfWebContents(restored_tab)); | 1071 browser->tab_strip_model()->GetIndexOfWebContents(restored_tab)); |
| 1072 // TODO(sky): remove. For debugging 368236. | 1072 // TODO(sky): remove. For debugging 368236. |
| 1073 CHECK_EQ(browser->tab_strip_model()->GetActiveWebContents(), | 1073 CHECK_EQ(browser->tab_strip_model()->GetActiveWebContents(), |
| 1074 restored_tab); | 1074 restored_tab); |
| 1075 tab_loader_->TabIsLoading(&browser->tab_strip_model() | 1075 tab_loader_->TabIsLoading(&browser->tab_strip_model() |
| 1076 ->GetActiveWebContents() | 1076 ->GetActiveWebContents() |
| 1077 ->GetController()); | 1077 ->GetController()); |
| 1078 } | 1078 } |
| 1079 } else { | 1079 } else { |
| 1080 // If the browser already has tabs, we want to restore the new ones after | 1080 // If the browser already has tabs, we want to restore the new ones after |
| 1081 // the existing ones. E.g. this happens in Win8 Metro where we merge | 1081 // the existing ones. E.g. this happens in Win8 Metro where we merge |
| 1082 // windows or when launching a hosted app from the app launcher. | 1082 // windows or when launching a hosted app from the app launcher. |
| 1083 int tab_index_offset = initial_tab_count; | 1083 int tab_index_offset = initial_tab_count; |
| 1084 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { | 1084 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { |
| 1085 const sessions::SessionTab& tab = *(window.tabs[i]); | 1085 const sessions::SessionTab& tab = *(window.tabs[i]); |
| 1086 // Always schedule loads as we will not be calling ShowBrowser(). | 1086 // Always schedule loads as we will not be calling ShowBrowser(). |
| 1087 RestoreTab(tab, tab_index_offset + i, browser, false); | 1087 WebContents* contents = |
| 1088 RestoreTab(tab, tab_index_offset + i, browser, false); | |
| 1089 if (contents) | |
| 1090 created_contents->push_back(contents); | |
| 1088 } | 1091 } |
| 1089 } | 1092 } |
| 1090 } | 1093 } |
| 1091 | 1094 |
| 1092 // |tab_index| is ignored for pinned tabs which will always be pushed behind | 1095 // |tab_index| is ignored for pinned tabs which will always be pushed behind |
| 1093 // the last existing pinned tab. | 1096 // the last existing pinned tab. |
| 1094 // |tab_loader_| will schedule this tab for loading if |is_selected_tab| is | 1097 // |tab_loader_| will schedule this tab for loading if |is_selected_tab| is |
| 1095 // false. | 1098 // false. |
| 1096 WebContents* RestoreTab(const sessions::SessionTab& tab, | 1099 WebContents* RestoreTab(const sessions::SessionTab& tab, |
| 1097 const int tab_index, | 1100 const int tab_index, |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1378 // static | 1381 // static |
| 1379 SessionRestore::CallbackSubscription | 1382 SessionRestore::CallbackSubscription |
| 1380 SessionRestore::RegisterOnSessionRestoredCallback( | 1383 SessionRestore::RegisterOnSessionRestoredCallback( |
| 1381 const base::Callback<void(int)>& callback) { | 1384 const base::Callback<void(int)>& callback) { |
| 1382 return on_session_restored_callbacks()->Add(callback); | 1385 return on_session_restored_callbacks()->Add(callback); |
| 1383 } | 1386 } |
| 1384 | 1387 |
| 1385 // static | 1388 // static |
| 1386 base::CallbackList<void(int)>* | 1389 base::CallbackList<void(int)>* |
| 1387 SessionRestore::on_session_restored_callbacks_ = nullptr; | 1390 SessionRestore::on_session_restored_callbacks_ = nullptr; |
| OLD | NEW |