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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 browser->tab_strip_model()->GetWebContentsAt(0); | 84 browser->tab_strip_model()->GetWebContentsAt(0); |
85 return active_tab->GetURL() == chrome::kChromeUINewTabURL || | 85 return active_tab->GetURL() == chrome::kChromeUINewTabURL || |
86 search::IsInstantNTP(active_tab); | 86 search::IsInstantNTP(active_tab); |
87 } | 87 } |
88 | 88 |
89 // Pointers to SessionRestoreImpls which are currently restoring the session. | 89 // Pointers to SessionRestoreImpls which are currently restoring the session. |
90 std::set<SessionRestoreImpl*>* active_session_restorers = nullptr; | 90 std::set<SessionRestoreImpl*>* active_session_restorers = nullptr; |
91 | 91 |
92 } // namespace | 92 } // namespace |
93 | 93 |
| 94 DEFINE_WEB_CONTENTS_USER_DATA_KEY(RestoreOrigin); |
| 95 |
| 96 // static |
| 97 void RestoreOrigin::CreateForWebContents(content::WebContents* contents, |
| 98 RestoreOrigin::Type type) { |
| 99 DCHECK(contents); |
| 100 if (!FromWebContents(contents)) |
| 101 contents->SetUserData(UserDataKey(), |
| 102 base::WrapUnique(new RestoreOrigin(type))); |
| 103 } |
| 104 |
| 105 // static |
| 106 void RestoreOrigin::RemoveFromWebContents(content::WebContents* contents) { |
| 107 if (FromWebContents(contents)) |
| 108 contents->RemoveUserData(UserDataKey()); |
| 109 } |
| 110 |
| 111 RestoreOrigin::RestoreOrigin(RestoreOrigin::Type type) : type_(type) {} |
| 112 |
| 113 RestoreOrigin::~RestoreOrigin() = default; |
| 114 |
94 // SessionRestoreImpl --------------------------------------------------------- | 115 // SessionRestoreImpl --------------------------------------------------------- |
95 | 116 |
96 // SessionRestoreImpl is responsible for fetching the set of tabs to create | 117 // SessionRestoreImpl is responsible for fetching the set of tabs to create |
97 // from SessionService. SessionRestoreImpl deletes itself when done. | 118 // from SessionService. SessionRestoreImpl deletes itself when done. |
98 | 119 |
99 class SessionRestoreImpl : public content::NotificationObserver { | 120 class SessionRestoreImpl : public content::NotificationObserver { |
100 public: | 121 public: |
101 SessionRestoreImpl(Profile* profile, | 122 SessionRestoreImpl(Profile* profile, |
102 Browser* browser, | 123 Browser* browser, |
103 bool synchronous, | 124 bool synchronous, |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 if (!tab.session_storage_persistent_id.empty()) { | 630 if (!tab.session_storage_persistent_id.empty()) { |
610 session_storage_namespace = | 631 session_storage_namespace = |
611 content::BrowserContext::GetDefaultStoragePartition(profile_) | 632 content::BrowserContext::GetDefaultStoragePartition(profile_) |
612 ->GetDOMStorageContext() | 633 ->GetDOMStorageContext() |
613 ->RecreateSessionStorage(tab.session_storage_persistent_id); | 634 ->RecreateSessionStorage(tab.session_storage_persistent_id); |
614 } | 635 } |
615 | 636 |
616 WebContents* web_contents = chrome::AddRestoredTab( | 637 WebContents* web_contents = chrome::AddRestoredTab( |
617 browser, tab.navigations, tab_index, selected_index, | 638 browser, tab.navigations, tab_index, selected_index, |
618 tab.extension_app_id, is_selected_tab, tab.pinned, true, | 639 tab.extension_app_id, is_selected_tab, tab.pinned, true, |
619 session_storage_namespace.get(), tab.user_agent_override); | 640 session_storage_namespace.get(), tab.user_agent_override, |
| 641 RestoreOrigin::Type::SESSION_RESTORE); |
620 // Regression check: if the current tab |is_selected_tab|, it should load | 642 // Regression check: if the current tab |is_selected_tab|, it should load |
621 // immediately, otherwise, tabs should not start loading right away. The | 643 // immediately, otherwise, tabs should not start loading right away. The |
622 // focused tab will be loaded by Browser, and TabLoader will load the rest. | 644 // focused tab will be loaded by Browser, and TabLoader will load the rest. |
623 DCHECK(is_selected_tab || web_contents->GetController().NeedsReload()); | 645 DCHECK(is_selected_tab || web_contents->GetController().NeedsReload()); |
624 | 646 |
625 return web_contents; | 647 return web_contents; |
626 } | 648 } |
627 | 649 |
628 Browser* CreateRestoredBrowser(Browser::Type type, | 650 Browser* CreateRestoredBrowser(Browser::Type type, |
629 gfx::Rect bounds, | 651 gfx::Rect bounds, |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 // static | 902 // static |
881 base::CallbackList<void(int)>* | 903 base::CallbackList<void(int)>* |
882 SessionRestore::on_session_restored_callbacks_ = nullptr; | 904 SessionRestore::on_session_restored_callbacks_ = nullptr; |
883 | 905 |
884 // static | 906 // static |
885 base::ObserverList<SessionRestoreObserver>* SessionRestore::observers_ = | 907 base::ObserverList<SessionRestoreObserver>* SessionRestore::observers_ = |
886 nullptr; | 908 nullptr; |
887 | 909 |
888 // static | 910 // static |
889 bool SessionRestore::session_restore_started_ = false; | 911 bool SessionRestore::session_restore_started_ = false; |
OLD | NEW |