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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 if (urls_to_open_.empty()) { | 290 if (urls_to_open_.empty()) { |
| 291 // No tab browsers were created and no URLs were supplied on the command | 291 // No tab browsers were created and no URLs were supplied on the command |
| 292 // line. Open the new tab page. | 292 // line. Open the new tab page. |
| 293 urls_to_open_.push_back(GURL(chrome::kChromeUINewTabURL)); | 293 urls_to_open_.push_back(GURL(chrome::kChromeUINewTabURL)); |
| 294 } | 294 } |
| 295 AppendURLsToBrowser(browser, urls_to_open_); | 295 AppendURLsToBrowser(browser, urls_to_open_); |
| 296 browser->window()->Show(); | 296 browser->window()->Show(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 if (succeeded) { | 299 if (succeeded) { |
| 300 if (SessionRestore::GetSmartRestoreMode() != | |
| 301 SessionRestore::SMART_RESTORE_MODE_OFF) { | |
| 302 if (SessionRestore::GetSmartRestoreMode() == | |
| 303 SessionRestore::SMART_RESTORE_MODE_MRU) { | |
| 304 // Sanitize the last active time by keeping the same time lapse | |
| 305 // between tabs. The latest tab will have its time set to Now() while | |
| 306 // the rest of the tabs will have theirs set earlier. | |
| 307 base::TimeTicks now = base::TimeTicks::Now(); | |
| 308 base::TimeTicks highest_time = base::TimeTicks::UnixEpoch(); | |
| 309 for (const auto& tab : *contents_created) { | |
| 310 if (tab.contents()->GetLastActiveTime() > highest_time) | |
| 311 highest_time = tab.contents()->GetLastActiveTime(); | |
| 312 } | |
| 313 for (const auto& tab : *contents_created) { | |
| 314 base::TimeDelta delta = | |
| 315 highest_time - tab.contents()->GetLastActiveTime(); | |
| 316 tab.contents()->SetLastActiveTime(now - delta); | |
| 317 } | |
| 318 } | |
| 319 std::stable_sort(contents_created->begin(), contents_created->end()); | |
| 320 } | |
| 300 // Start Loading tabs. | 321 // Start Loading tabs. |
| 301 if (SessionRestore::GetSmartRestoreMode() != | |
| 302 SessionRestore::SMART_RESTORE_MODE_OFF) | |
| 303 std::stable_sort(contents_created->begin(), contents_created->end()); | |
| 304 SessionRestoreDelegate::RestoreTabs(*contents_created, restore_started_); | 322 SessionRestoreDelegate::RestoreTabs(*contents_created, restore_started_); |
| 305 } | 323 } |
| 306 | 324 |
| 307 if (!synchronous_) { | 325 if (!synchronous_) { |
| 308 // If we're not synchronous we need to delete ourself. | 326 // If we're not synchronous we need to delete ourself. |
| 309 // NOTE: we must use DeleteLater here as most likely we're in a callback | 327 // NOTE: we must use DeleteLater here as most likely we're in a callback |
| 310 // from the history service which doesn't deal well with deleting the | 328 // from the history service which doesn't deal well with deleting the |
| 311 // object it is notifying. | 329 // object it is notifying. |
| 312 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 330 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 313 | 331 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 WebContents* web_contents = chrome::AddRestoredTab( | 602 WebContents* web_contents = chrome::AddRestoredTab( |
| 585 browser, tab.navigations, tab_index, selected_index, | 603 browser, tab.navigations, tab_index, selected_index, |
| 586 tab.extension_app_id, | 604 tab.extension_app_id, |
| 587 false, // select | 605 false, // select |
| 588 tab.pinned, true, session_storage_namespace.get(), | 606 tab.pinned, true, session_storage_namespace.get(), |
| 589 tab.user_agent_override); | 607 tab.user_agent_override); |
| 590 // Regression check: check that the tab didn't start loading right away. The | 608 // Regression check: check that the tab didn't start loading right away. The |
| 591 // focused tab will be loaded by Browser, and TabLoader will load the rest. | 609 // focused tab will be loaded by Browser, and TabLoader will load the rest. |
| 592 DCHECK(web_contents->GetController().NeedsReload()); | 610 DCHECK(web_contents->GetController().NeedsReload()); |
| 593 | 611 |
| 612 // Restore the saved last active time since by default, the last active time | |
| 613 // of a WebContent is initially set to the creation time of the tab, which | |
| 614 // is not necessarly the same as the loading time. This makes sure that the | |
| 615 // state is preserved between restores. Also, since TimeTicks only make | |
| 616 // sense in their current session, these values are sanitized later on | |
| 617 // (before we start loading background tabs). | |
| 618 if (SessionRestore::GetSmartRestoreMode() == | |
| 619 SessionRestore::SMART_RESTORE_MODE_MRU) { | |
| 620 web_contents->SetLastActiveTime(tab.last_active_time); | |
|
sky
2015/05/22 03:00:19
I don't like pushing potentially bogus times to th
Georges Khalil
2015/05/22 20:14:09
That was done because otherwise, by the time we sa
| |
| 621 } | |
| 622 | |
| 594 return web_contents; | 623 return web_contents; |
| 595 } | 624 } |
| 596 | 625 |
| 597 Browser* CreateRestoredBrowser(Browser::Type type, | 626 Browser* CreateRestoredBrowser(Browser::Type type, |
| 598 gfx::Rect bounds, | 627 gfx::Rect bounds, |
| 599 ui::WindowShowState show_state, | 628 ui::WindowShowState show_state, |
| 600 const std::string& app_name) { | 629 const std::string& app_name) { |
| 601 Browser::CreateParams params(type, profile_, host_desktop_type_); | 630 Browser::CreateParams params(type, profile_, host_desktop_type_); |
| 602 if (!app_name.empty()) { | 631 if (!app_name.empty()) { |
| 603 const bool trusted_source = true; // We only store trusted app windows. | 632 const bool trusted_source = true; // We only store trusted app windows. |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 if (prioritize_tabs == "mru") | 854 if (prioritize_tabs == "mru") |
| 826 return SMART_RESTORE_MODE_MRU; | 855 return SMART_RESTORE_MODE_MRU; |
| 827 if (prioritize_tabs == "simple") | 856 if (prioritize_tabs == "simple") |
| 828 return SMART_RESTORE_MODE_SIMPLE; | 857 return SMART_RESTORE_MODE_SIMPLE; |
| 829 return SMART_RESTORE_MODE_OFF; | 858 return SMART_RESTORE_MODE_OFF; |
| 830 } | 859 } |
| 831 | 860 |
| 832 // static | 861 // static |
| 833 base::CallbackList<void(int)>* | 862 base::CallbackList<void(int)>* |
| 834 SessionRestore::on_session_restored_callbacks_ = nullptr; | 863 SessionRestore::on_session_restored_callbacks_ = nullptr; |
| OLD | NEW |