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

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

Issue 2345763002: Fix tabs duplication when restoring last closed window. (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_service.h" 5 #include "chrome/browser/sessions/session_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // from the dock or the menubar. 125 // from the dock or the menubar.
126 && !app_controller_mac::IsOpeningNewWindow() 126 && !app_controller_mac::IsOpeningNewWindow()
127 #endif // OS_MACOSX 127 #endif // OS_MACOSX
128 ) { 128 ) {
129 return true; 129 return true;
130 } 130 }
131 return false; 131 return false;
132 } 132 }
133 133
134 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open) { 134 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open) {
135 return RestoreIfNecessary(urls_to_open, NULL); 135 return RestoreIfNecessary(urls_to_open, NULL, false);
136 } 136 }
137 137
138 void SessionService::ResetFromCurrentBrowsers() { 138 void SessionService::ResetFromCurrentBrowsers() {
139 ScheduleResetCommands(); 139 ScheduleResetCommands();
140 } 140 }
141 141
142 void SessionService::MoveCurrentSessionToLastSession() { 142 void SessionService::MoveCurrentSessionToLastSession() {
143 pending_tab_close_ids_.clear(); 143 pending_tab_close_ids_.clear();
144 window_closing_ids_.clear(); 144 window_closing_ids_.clear();
145 pending_window_close_ids_.clear(); 145 pending_window_close_ids_.clear();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // In all cases we need to mark the tab as explicitly closed. 227 // In all cases we need to mark the tab as explicitly closed.
228 ScheduleCommand(sessions::CreateTabClosedCommand(tab_id.id())); 228 ScheduleCommand(sessions::CreateTabClosedCommand(tab_id.id()));
229 } else { 229 } else {
230 // User closed the last tab in the last tabbed browser. Don't mark the 230 // User closed the last tab in the last tabbed browser. Don't mark the
231 // tab closed. 231 // tab closed.
232 pending_tab_close_ids_.insert(tab_id.id()); 232 pending_tab_close_ids_.insert(tab_id.id());
233 has_open_trackable_browsers_ = false; 233 has_open_trackable_browsers_ = false;
234 } 234 }
235 } 235 }
236 236
237 void SessionService::WindowOpened(Browser* browser) { 237 void SessionService::WindowOpened(Browser* browser, bool dont_restore) {
238 if (!ShouldTrackBrowser(browser)) 238 if (!ShouldTrackBrowser(browser))
239 return; 239 return;
240 240
241 RestoreIfNecessary(std::vector<GURL>(), browser); 241 RestoreIfNecessary(std::vector<GURL>(), browser, dont_restore);
242 SetWindowType(browser->session_id(), 242 SetWindowType(browser->session_id(),
243 browser->type(), 243 browser->type(),
244 browser->is_app() ? TYPE_APP : TYPE_NORMAL); 244 browser->is_app() ? TYPE_APP : TYPE_NORMAL);
245 SetWindowAppName(browser->session_id(), browser->app_name()); 245 SetWindowAppName(browser->session_id(), browser->app_name());
246 } 246 }
247 247
248 void SessionService::WindowClosing(const SessionID& window_id) { 248 void SessionService::WindowClosing(const SessionID& window_id) {
249 if (!ShouldTrackChangesToWindow(window_id)) 249 if (!ShouldTrackChangesToWindow(window_id))
250 return; 250 return;
251 251
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 TYPE_APP)) { 570 TYPE_APP)) {
571 delete window; 571 delete window;
572 i = window_list->erase(i); 572 i = window_list->erase(i);
573 } else { 573 } else {
574 ++i; 574 ++i;
575 } 575 }
576 } 576 }
577 } 577 }
578 578
579 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open, 579 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open,
580 Browser* browser) { 580 Browser* browser, bool dont_restore) {
581 if (ShouldNewWindowStartSession()) { 581 if (ShouldNewWindowStartSession()) {
582 // We're going from no tabbed browsers to a tabbed browser (and not in 582 // We're going from no tabbed browsers to a tabbed browser (and not in
583 // process startup), restore the last session. 583 // process startup), restore the last session.
584 if (move_on_new_browser_) { 584 if (move_on_new_browser_) {
585 // Make the current session the last. 585 // Make the current session the last.
586 MoveCurrentSessionToLastSession(); 586 MoveCurrentSessionToLastSession();
587 move_on_new_browser_ = false; 587 move_on_new_browser_ = false;
588 } 588 }
589 SessionStartupPref pref = StartupBrowserCreator::GetSessionStartupPref( 589 SessionStartupPref pref = StartupBrowserCreator::GetSessionStartupPref(
590 *base::CommandLine::ForCurrentProcess(), profile()); 590 *base::CommandLine::ForCurrentProcess(), profile());
591 if (pref.type == SessionStartupPref::LAST) { 591 if (pref.type == SessionStartupPref::LAST && !dont_restore) {
592 SessionRestore::RestoreSession( 592 SessionRestore::RestoreSession(
593 profile(), browser, 593 profile(), browser,
594 browser ? 0 : SessionRestore::ALWAYS_CREATE_TABBED_BROWSER, 594 browser ? 0 : SessionRestore::ALWAYS_CREATE_TABBED_BROWSER,
595 urls_to_open); 595 urls_to_open);
596 return true; 596 return true;
597 } 597 }
598 } 598 }
599 return false; 599 return false;
600 } 600 }
601 601
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 for (auto* browser : *BrowserList::GetInstance()) { 1096 for (auto* browser : *BrowserList::GetInstance()) {
1097 if (browser->profile() == profile()) 1097 if (browser->profile() == profile())
1098 return; 1098 return;
1099 } 1099 }
1100 DeleteSessionOnlyData(profile()); 1100 DeleteSessionOnlyData(profile());
1101 } 1101 }
1102 1102
1103 sessions::BaseSessionService* SessionService::GetBaseSessionServiceForTest() { 1103 sessions::BaseSessionService* SessionService::GetBaseSessionServiceForTest() {
1104 return base_session_service_.get(); 1104 return base_session_service_.get();
1105 } 1105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698