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

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

Issue 10969012: Fix: Prerendering was confusing SessionService to not save sessionStorage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 &last_updated_save_time_); 514 &last_updated_save_time_);
515 content::NotificationService::current()->Notify( 515 content::NotificationService::current()->Notify(
516 chrome::NOTIFICATION_SESSION_SERVICE_SAVED, 516 chrome::NOTIFICATION_SESSION_SERVICE_SAVED,
517 content::Source<Profile>(profile()), 517 content::Source<Profile>(profile()),
518 content::NotificationService::NoDetails()); 518 content::NotificationService::NoDetails());
519 } 519 }
520 } 520 }
521 521
522 void SessionService::Init() { 522 void SessionService::Init() {
523 // Register for the notifications we're interested in. 523 // Register for the notifications we're interested in.
524 registrar_.Add(this, chrome::NOTIFICATION_TAB_PARENTED,
525 content::NotificationService::AllSources());
526 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED,
527 content::NotificationService::AllSources());
528 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, 524 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED,
529 content::NotificationService::AllSources()); 525 content::NotificationService::AllSources());
530 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, 526 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED,
531 content::NotificationService::AllSources()); 527 content::NotificationService::AllSources());
532 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 528 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
533 content::NotificationService::AllSources()); 529 content::NotificationService::AllSources());
534 // Wait for NOTIFICATION_BROWSER_WINDOW_READY so that is_app() is set. 530 // Wait for NOTIFICATION_BROWSER_WINDOW_READY so that is_app() is set.
535 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 531 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
536 content::NotificationService::AllBrowserContextsAndSources()); 532 content::NotificationService::AllBrowserContextsAndSources());
537 registrar_.Add( 533 registrar_.Add(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 if (browser->profile() != profile() || 591 if (browser->profile() != profile() ||
596 !should_track_changes_for_browser_type(browser->type(), app_type)) 592 !should_track_changes_for_browser_type(browser->type(), app_type))
597 return; 593 return;
598 594
599 RestoreIfNecessary(std::vector<GURL>(), browser); 595 RestoreIfNecessary(std::vector<GURL>(), browser);
600 SetWindowType(browser->session_id(), browser->type(), app_type); 596 SetWindowType(browser->session_id(), browser->type(), app_type);
601 SetWindowAppName(browser->session_id(), browser->app_name()); 597 SetWindowAppName(browser->session_id(), browser->app_name());
602 break; 598 break;
603 } 599 }
604 600
605 case chrome::NOTIFICATION_TAB_PARENTED: {
606 WebContents* web_contents = content::Source<WebContents>(source).ptr();
607 if (web_contents->GetBrowserContext() != profile())
608 return;
609 SessionTabHelper* session_tab_helper =
610 SessionTabHelper::FromWebContents(web_contents);
611 SetTabWindow(session_tab_helper->window_id(),
612 session_tab_helper->session_id());
613 extensions::TabHelper* extensions_tab_helper =
614 extensions::TabHelper::FromWebContents(web_contents);
615 if (extensions_tab_helper &&
616 extensions_tab_helper->extension_app()) {
617 SetTabExtensionAppID(
618 session_tab_helper->window_id(),
619 session_tab_helper->session_id(),
620 extensions_tab_helper->extension_app()->id());
621 }
622
623 // Record the association between the SessionStorageNamespace and the
624 // tab.
625 //
626 // TODO(ajwong): This should be processing the whole map rather than
627 // just the default. This in particular will not work for tabs with only
628 // isolated apps which won't have a default partition.
629 content::SessionStorageNamespace* session_storage_namespace =
630 web_contents->GetController().GetDefaultSessionStorageNamespace();
631 ScheduleCommand(CreateSessionStorageAssociatedCommand(
632 session_tab_helper->session_id(),
633 session_storage_namespace->persistent_id()));
634 session_storage_namespace->SetShouldPersist(true);
635 break;
636 }
637
638 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: {
639 TabContents* tab = content::Source<TabContents>(source).ptr();
640 if (!tab || tab->profile() != profile())
641 return;
642 // Allow the associated sessionStorage to get deleted; it won't be needed
643 // in the session restore.
644 content::SessionStorageNamespace* session_storage_namespace =
645 tab->web_contents()->GetController().
646 GetDefaultSessionStorageNamespace();
647 session_storage_namespace->SetShouldPersist(false);
648 SessionTabHelper* session_tab_helper =
649 SessionTabHelper::FromWebContents(tab->web_contents());
650 TabClosed(session_tab_helper->window_id(),
651 session_tab_helper->session_id(),
652 tab->web_contents()->GetClosedByUserGesture());
653 RecordSessionUpdateHistogramData(type, &last_updated_tab_closed_time_);
654 break;
655 }
656
657 case content::NOTIFICATION_NAV_LIST_PRUNED: { 601 case content::NOTIFICATION_NAV_LIST_PRUNED: {
658 WebContents* web_contents = 602 WebContents* web_contents =
659 content::Source<content::NavigationController>(source).ptr()-> 603 content::Source<content::NavigationController>(source).ptr()->
660 GetWebContents(); 604 GetWebContents();
661 SessionTabHelper* session_tab_helper = 605 SessionTabHelper* session_tab_helper =
662 SessionTabHelper::FromWebContents(web_contents); 606 SessionTabHelper::FromWebContents(web_contents);
663 if (!session_tab_helper || web_contents->GetBrowserContext() != profile()) 607 if (!session_tab_helper || web_contents->GetBrowserContext() != profile())
664 return; 608 return;
665 content::Details<content::PrunedDetails> pruned_details(details); 609 content::Details<content::PrunedDetails> pruned_details(details);
666 if (pruned_details->from_front) { 610 if (pruned_details->from_front) {
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 50); 1700 50);
1757 if (use_long_period) { 1701 if (use_long_period) {
1758 std::string long_name_("SessionRestore.SaveLongPeriod"); 1702 std::string long_name_("SessionRestore.SaveLongPeriod");
1759 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, 1703 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
1760 delta, 1704 delta,
1761 save_delay_in_mins_, 1705 save_delay_in_mins_,
1762 save_delay_in_hrs_, 1706 save_delay_in_hrs_,
1763 50); 1707 50);
1764 } 1708 }
1765 } 1709 }
1710
1711 void SessionService::TabInserted(WebContents* contents) {
1712 SessionTabHelper* session_tab_helper =
1713 SessionTabHelper::FromWebContents(contents);
1714 SetTabWindow(session_tab_helper->window_id(),
1715 session_tab_helper->session_id());
1716 extensions::TabHelper* extensions_tab_helper =
1717 extensions::TabHelper::FromWebContents(contents);
1718 if (extensions_tab_helper &&
1719 extensions_tab_helper->extension_app()) {
1720 SetTabExtensionAppID(
1721 session_tab_helper->window_id(),
1722 session_tab_helper->session_id(),
1723 extensions_tab_helper->extension_app()->id());
1724 }
1725
1726 // Record the association between the SessionStorageNamespace and the
1727 // tab.
1728 //
1729 // TODO(ajwong): This should be processing the whole map rather than
1730 // just the default. This in particular will not work for tabs with only
1731 // isolated apps which won't have a default partition.
1732 content::SessionStorageNamespace* session_storage_namespace =
1733 contents->GetController().GetDefaultSessionStorageNamespace();
1734 ScheduleCommand(CreateSessionStorageAssociatedCommand(
1735 session_tab_helper->session_id(),
1736 session_storage_namespace->persistent_id()));
1737 session_storage_namespace->SetShouldPersist(true);
1738 }
1739
1740 void SessionService::TabClosing(WebContents* contents) {
1741 // Allow the associated sessionStorage to get deleted; it won't be needed
1742 // in the session restore.
1743 content::SessionStorageNamespace* session_storage_namespace =
1744 contents->GetController().GetDefaultSessionStorageNamespace();
1745 session_storage_namespace->SetShouldPersist(false);
1746 SessionTabHelper* session_tab_helper =
1747 SessionTabHelper::FromWebContents(contents);
1748 TabClosed(session_tab_helper->window_id(),
1749 session_tab_helper->session_id(),
1750 contents->GetClosedByUserGesture());
1751 RecordSessionUpdateHistogramData(chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED,
1752 &last_updated_tab_closed_time_);
1753 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698