-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinalDiffEvelina.txt
166 lines (152 loc) · 6.63 KB
/
FinalDiffEvelina.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
diff --git a/chrome/browser/ui/tabs/pinned_tab_service.cc b/chrome/browser/ui/tabs/pinned_tab_service.cc
index c3d7629877ae..2c1b916074bc 100644
--- a/chrome/browser/ui/tabs/pinned_tab_service.cc
+++ b/chrome/browser/ui/tabs/pinned_tab_service.cc
@@ -4,12 +4,25 @@
#include "chrome/browser/ui/tabs/pinned_tab_service.h"
+#include "base/feature_list.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/pinned_tab_codec.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
+#include "third_party/blink/public/common/features.h"
+
+using content::NavigationEntry;
+
+void AddTabToStartupRestore(content::WebContents* web_contents,
+ StartupTabs& tabs_to_restore) {
+ NavigationEntry* entry =
+ web_contents->GetController().GetLastCommittedEntry();
+ if (entry)
+ tabs_to_restore.emplace_back(entry->GetURL(), true);
+}
PinnedTabService::PinnedTabService(Profile* profile) : profile_(profile) {
registrar_.Add(this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
@@ -44,8 +57,13 @@ void PinnedTabService::Observe(int type,
// over-writing the correct state.
// Saving is re-enabled if a new tab or window is opened.
DCHECK_EQ(type, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST);
- if (TabStripModelObserver::IsObservingAny(this))
+ if (TabStripModelObserver::IsObservingAny(this)) {
+ if (base::FeatureList::IsEnabled(
+ blink::features::kRestorePinnedTabsInNextStartup)) {
+ RememberPinnedTabs();
+ }
WritePinnedTabsIfNecessary();
+ }
}
void PinnedTabService::OnBrowserAdded(Browser* browser) {
@@ -60,6 +78,11 @@ void PinnedTabService::OnBrowserClosing(Browser* browser) {
if (browser->profile() != profile_ || !browser->is_type_normal())
return;
+ if (base::FeatureList::IsEnabled(
+ blink::features::kRestorePinnedTabsInNextStartup)) {
+ RememberPinnedTabs(browser);
+ }
+
if (TabStripModelObserver::CountObservedModels(this) == 1)
WritePinnedTabsIfNecessary();
}
@@ -88,7 +111,33 @@ void PinnedTabService::OnTabStripModelChanged(
}
void PinnedTabService::WritePinnedTabsIfNecessary() {
- if (need_to_write_pinned_tabs_)
- PinnedTabCodec::WritePinnedTabs(profile_);
+ if (need_to_write_pinned_tabs_) {
+ if (base::FeatureList::IsEnabled(
+ blink::features::kRestorePinnedTabsInNextStartup)) {
+ PinnedTabCodec::WritePinnedTabs(profile_,
+ closed_pinned_tabs_to_startup_restore_);
+ } else {
+ PinnedTabCodec::WritePinnedTabs(profile_);
+ }
+ }
need_to_write_pinned_tabs_ = false;
}
+
+void PinnedTabService::RememberPinnedTabs(const Browser* browser) {
+ if (browser->profile() != profile_ || !browser->is_type_normal())
+ return;
+
+ TabStripModel* tab_model = browser->tab_strip_model();
+
+ for (int i = 0; i < tab_model->count() && tab_model->IsTabPinned(i); ++i) {
+ StartupTab tab;
+ content::WebContents* web_contents = tab_model->GetWebContentsAt(i);
+ AddTabToStartupRestore(web_contents,
+ closed_pinned_tabs_to_startup_restore_);
+ }
+}
+
+void PinnedTabService::RememberPinnedTabs() {
+ for (auto* browser : *BrowserList::GetInstance())
+ RememberPinnedTabs(browser);
+}
diff --git a/chrome/browser/ui/tabs/pinned_tab_service.h b/chrome/browser/ui/tabs/pinned_tab_service.h
index f8f047fb9e0d..13a10fcdbdf1 100644
--- a/chrome/browser/ui/tabs/pinned_tab_service.h
+++ b/chrome/browser/ui/tabs/pinned_tab_service.h
@@ -8,7 +8,9 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
+#include "chrome/browser/ui/startup/startup_tab.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "components/keyed_service/core/keyed_service.h"
@@ -45,6 +47,11 @@ class PinnedTabService : public content::NotificationObserver,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
+ // Writes the pinned tabs from the closing browser(s) window(s) to
+ // |closed_pinned_tabs_to_startup_restore_|.
+ void RememberPinnedTabs(const Browser* browser);
+ void RememberPinnedTabs();
+
// Writes the pinned tabs for |profile_|, but only if a new tab or browser
// window has been added since the last time the method was called.
void WritePinnedTabsIfNecessary();
@@ -58,6 +65,9 @@ class PinnedTabService : public content::NotificationObserver,
content::NotificationRegistrar registrar_;
+ // Closed pinned tabs that will be restored in the next session.
+ StartupTabs closed_pinned_tabs_to_startup_restore_;
+
DISALLOW_COPY_AND_ASSIGN(PinnedTabService);
};
diff --git a/third_party/blink/common/features.cc b/third_party/blink/common/features.cc
index afc23a8cd972..62e6114b8492 100644
--- a/third_party/blink/common/features.cc
+++ b/third_party/blink/common/features.cc
@@ -275,7 +275,7 @@ const base::Feature kAudioWorkletRealtimeThread{
"AudioWorkletRealtimeThread", base::FEATURE_DISABLED_BY_DEFAULT};
// A feature to reduce the set of resources fetched by No-State Prefetch.
-const base::Feature kLightweightNoStatePrefetch{
+const base::Feature kLightweightNoStatePrefetch {
"LightweightNoStatePrefetch",
#if defined(OS_ANDROID)
base::FEATURE_ENABLED_BY_DEFAULT
@@ -478,5 +478,10 @@ const base::Feature kSuppressContentTypeForBeaconMadeWithArrayBufferView{
"SuppressContentTypeForBeaconMadeWithArrayBufferView",
base::FEATURE_ENABLED_BY_DEFAULT};
+// If the user has not chosen to restore the last session on startup, the
+// pinned tabs from all closing windows are restored on next start the browser.
+const base::Feature kRestorePinnedTabsInNextStartup{
+ "RestorePinnedTabsInNextStartup", base::FEATURE_ENABLED_BY_DEFAULT};
+
} // namespace features
} // namespace blink
diff --git a/third_party/blink/public/common/features.h b/third_party/blink/public/common/features.h
index 1cd7f39ced81..0b2cfc57818e 100644
--- a/third_party/blink/public/common/features.h
+++ b/third_party/blink/public/common/features.h
@@ -157,6 +157,8 @@ BLINK_COMMON_EXPORT extern const base::Feature kDiscardCodeCacheAfterFirstUse;
BLINK_COMMON_EXPORT extern const base::Feature
kSuppressContentTypeForBeaconMadeWithArrayBufferView;
+BLINK_COMMON_EXPORT extern const base::Feature kRestorePinnedTabsInNextStartup;
+
} // namespace features
} // namespace blink