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

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

Issue 341043: Changes session restore to use a normal load rather than preferring... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/tab_restore_service.h" 5 #include "chrome/browser/sessions/tab_restore_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 10
11 #include "base/scoped_vector.h" 11 #include "base/scoped_vector.h"
12 #include "base/stl_util-inl.h" 12 #include "base/stl_util-inl.h"
13 #include "chrome/browser/browser_list.h" 13 #include "chrome/browser/browser_list.h"
14 #include "chrome/browser/browser_window.h" 14 #include "chrome/browser/browser_window.h"
15 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
16 #include "chrome/browser/sessions/session_service.h" 16 #include "chrome/browser/sessions/session_service.h"
17 #include "chrome/browser/sessions/session_command.h" 17 #include "chrome/browser/sessions/session_command.h"
18 #include "chrome/browser/tab_contents/navigation_controller.h" 18 #include "chrome/browser/tab_contents/navigation_controller.h"
19 #include "chrome/browser/tab_contents/navigation_entry.h" 19 #include "chrome/browser/tab_contents/navigation_entry.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 20 #include "chrome/browser/tab_contents/tab_contents.h"
21 21
22 using base::Time; 22 using base::Time;
23 23
24 // Entry ---------------------------------------------------------------------- 24 // Entry ----------------------------------------------------------------------
25 25
26 // ID of the next Entry. 26 // ID of the next Entry.
27 static SessionID::id_type next_entry_id = 1; 27 static SessionID::id_type next_entry_id = 1;
28 28
29 TabRestoreService::Entry::Entry() : id(next_entry_id++), type(TAB) {} 29 TabRestoreService::Entry::Entry()
30 : id(next_entry_id++),
31 type(TAB),
32 from_last_session(false) {}
30 33
31 TabRestoreService::Entry::Entry(Type type) : id(next_entry_id++), type(type) {} 34 TabRestoreService::Entry::Entry(Type type)
35 : id(next_entry_id++),
36 type(type),
37 from_last_session(false) {}
32 38
33 // TabRestoreService ---------------------------------------------------------- 39 // TabRestoreService ----------------------------------------------------------
34 40
35 // static 41 // static
36 const size_t TabRestoreService::kMaxEntries = 10; 42 const size_t TabRestoreService::kMaxEntries = 10;
37 43
38 // Identifier for commands written to file. 44 // Identifier for commands written to file.
39 // The ordering in the file is as follows: 45 // The ordering in the file is as follows:
40 // . When the user closes a tab a command of type 46 // . When the user closes a tab a command of type
41 // kCommandSelectedNavigationInTab is written identifying the tab and 47 // kCommandSelectedNavigationInTab is written identifying the tab and
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 entries_.erase(i); 249 entries_.erase(i);
244 i = entries_.end(); 250 i = entries_.end();
245 251
246 // |browser| will be NULL in cases where one isn't already available (eg, 252 // |browser| will be NULL in cases where one isn't already available (eg,
247 // when invoked on Mac OS X with no windows open). In this case, create a 253 // when invoked on Mac OS X with no windows open). In this case, create a
248 // new browser into which we restore the tabs. 254 // new browser into which we restore the tabs.
249 if (entry->type == TAB) { 255 if (entry->type == TAB) {
250 Tab* tab = static_cast<Tab*>(entry); 256 Tab* tab = static_cast<Tab*>(entry);
251 if (replace_existing_tab && browser) { 257 if (replace_existing_tab && browser) {
252 browser->ReplaceRestoredTab(tab->navigations, 258 browser->ReplaceRestoredTab(tab->navigations,
253 tab->current_navigation_index); 259 tab->current_navigation_index,
260 tab->from_last_session);
254 } else { 261 } else {
255 // Use the tab's former browser and index, if available. 262 // Use the tab's former browser and index, if available.
256 Browser* tab_browser = NULL; 263 Browser* tab_browser = NULL;
257 int tab_index = -1; 264 int tab_index = -1;
258 if (tab->has_browser()) 265 if (tab->has_browser())
259 tab_browser = BrowserList::FindBrowserWithID(tab->browser_id); 266 tab_browser = BrowserList::FindBrowserWithID(tab->browser_id);
260 267
261 if (tab_browser) { 268 if (tab_browser) {
262 tab_index = tab->tabstrip_index; 269 tab_index = tab->tabstrip_index;
263 } else { 270 } else {
264 tab_browser = Browser::Create(profile()); 271 tab_browser = Browser::Create(profile());
265 if (tab->has_browser()) { 272 if (tab->has_browser()) {
266 UpdateTabBrowserIDs(tab->browser_id, 273 UpdateTabBrowserIDs(tab->browser_id,
267 tab_browser->session_id().id()); 274 tab_browser->session_id().id());
268 } 275 }
269 tab_browser->window()->Show(); 276 tab_browser->window()->Show();
270 } 277 }
271 278
272 if (tab_index < 0 || tab_index > tab_browser->tab_count()) 279 if (tab_index < 0 || tab_index > tab_browser->tab_count())
273 tab_index = tab_browser->tab_count(); 280 tab_index = tab_browser->tab_count();
274 tab_browser->AddRestoredTab(tab->navigations, tab_index, 281 tab_browser->AddRestoredTab(tab->navigations, tab_index,
275 tab->current_navigation_index, true, 282 tab->current_navigation_index, true,
276 tab->pinned); 283 tab->pinned, tab->from_last_session);
277 } 284 }
278 } else if (entry->type == WINDOW) { 285 } else if (entry->type == WINDOW) {
279 const Window* window = static_cast<Window*>(entry); 286 const Window* window = static_cast<Window*>(entry);
280 browser = Browser::Create(profile()); 287 browser = Browser::Create(profile());
281 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) { 288 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) {
282 const Tab& tab = window->tabs[tab_i]; 289 const Tab& tab = window->tabs[tab_i];
283 TabContents* restored_tab = 290 TabContents* restored_tab =
284 browser->AddRestoredTab(tab.navigations, browser->tab_count(), 291 browser->AddRestoredTab(tab.navigations, browser->tab_count(),
285 tab.current_navigation_index, 292 tab.current_navigation_index,
286 (static_cast<int>(tab_i) == 293 (static_cast<int>(tab_i) ==
287 window->selected_tab_index), 294 window->selected_tab_index),
288 tab.pinned); 295 tab.pinned, tab.from_last_session);
289 if (restored_tab) 296 if (restored_tab)
290 restored_tab->controller().LoadIfNecessary(); 297 restored_tab->controller().LoadIfNecessary();
291 } 298 }
292 // All the window's tabs had the same former browser_id. 299 // All the window's tabs had the same former browser_id.
293 if (window->tabs[0].has_browser()) { 300 if (window->tabs[0].has_browser()) {
294 UpdateTabBrowserIDs(window->tabs[0].browser_id, 301 UpdateTabBrowserIDs(window->tabs[0].browser_id,
295 browser->session_id().id()); 302 browser->session_id().id());
296 } 303 }
297 browser->window()->Show(); 304 browser->window()->Show();
298 } else { 305 } else {
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 DCHECK(entries_.size() < kMaxEntries); 869 DCHECK(entries_.size() < kMaxEntries);
863 STLDeleteContainerPointers( 870 STLDeleteContainerPointers(
864 staging_entries_.begin() + (kMaxEntries - entries_.size()), 871 staging_entries_.begin() + (kMaxEntries - entries_.size()),
865 staging_entries_.end()); 872 staging_entries_.end());
866 staging_entries_.erase( 873 staging_entries_.erase(
867 staging_entries_.begin() + (kMaxEntries - entries_.size()), 874 staging_entries_.begin() + (kMaxEntries - entries_.size()),
868 staging_entries_.end()); 875 staging_entries_.end());
869 } 876 }
870 877
871 // And add them. 878 // And add them.
872 for (size_t i = 0; i < staging_entries_.size(); ++i) 879 for (size_t i = 0; i < staging_entries_.size(); ++i) {
880 staging_entries_[i]->from_last_session = true;
873 AddEntry(staging_entries_[i], false, false); 881 AddEntry(staging_entries_[i], false, false);
882 }
874 883
875 // AddEntry takes ownership of the entry, need to clear out entries so that 884 // AddEntry takes ownership of the entry, need to clear out entries so that
876 // it doesn't delete them. 885 // it doesn't delete them.
877 staging_entries_.clear(); 886 staging_entries_.clear();
878 887
879 // Make it so we rewrite all the tabs. We need to do this otherwise we won't 888 // Make it so we rewrite all the tabs. We need to do this otherwise we won't
880 // correctly write out the entries when Save is invoked (Save starts from 889 // correctly write out the entries when Save is invoked (Save starts from
881 // the front, not the end and we just added the entries to the end). 890 // the front, not the end and we just added the entries to the end).
882 entries_to_write_ = staging_entries_.size(); 891 entries_to_write_ = staging_entries_.size();
883 892
884 PruneAndNotify(); 893 PruneAndNotify();
885 } 894 }
886 895
887 Time TabRestoreService::TimeNow() const { 896 Time TabRestoreService::TimeNow() const {
888 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); 897 return time_factory_ ? time_factory_->TimeNow() : Time::Now();
889 } 898 }
890 899
OLDNEW
« no previous file with comments | « chrome/browser/sessions/tab_restore_service.h ('k') | chrome/browser/tab_contents/navigation_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698