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

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

Issue 10890023: Miscellaneous cleanups from several months ago I never got around to landing. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 483 }
484 484
485 void SessionService::SetTabUserAgentOverride( 485 void SessionService::SetTabUserAgentOverride(
486 const SessionID& window_id, 486 const SessionID& window_id,
487 const SessionID& tab_id, 487 const SessionID& tab_id,
488 const std::string& user_agent_override) { 488 const std::string& user_agent_override) {
489 if (!ShouldTrackChangesToWindow(window_id)) 489 if (!ShouldTrackChangesToWindow(window_id))
490 return; 490 return;
491 491
492 ScheduleCommand(CreateSetTabUserAgentOverrideCommand( 492 ScheduleCommand(CreateSetTabUserAgentOverrideCommand(
493 kCommandSetTabUserAgentOverride, 493 kCommandSetTabUserAgentOverride, tab_id.id(), user_agent_override));
494 tab_id.id(),
495 user_agent_override));
496 } 494 }
497 495
498 SessionService::Handle SessionService::GetLastSession( 496 SessionService::Handle SessionService::GetLastSession(
499 CancelableRequestConsumerBase* consumer, 497 CancelableRequestConsumerBase* consumer,
500 const SessionCallback& callback) { 498 const SessionCallback& callback) {
501 return ScheduleGetLastSessionCommands( 499 return ScheduleGetLastSessionCommands(
502 new InternalSessionRequest( 500 new InternalSessionRequest(
503 base::Bind(&SessionService::OnGotSessionCommands, 501 base::Bind(&SessionService::OnGotSessionCommands,
504 base::Unretained(this)), 502 base::Unretained(this)),
505 callback), 503 callback),
506 consumer); 504 consumer);
507 } 505 }
508 506
509 void SessionService::Save() { 507 void SessionService::Save() {
510 bool had_commands = !pending_commands().empty(); 508 bool had_commands = !pending_commands().empty();
511 BaseSessionService::Save(); 509 BaseSessionService::Save();
512 if (had_commands) { 510 if (had_commands) {
513 RecordSessionUpdateHistogramData( 511 RecordSessionUpdateHistogramData(chrome::NOTIFICATION_SESSION_SERVICE_SAVED,
514 chrome::NOTIFICATION_SESSION_SERVICE_SAVED, 512 &last_updated_save_time_);
515 &last_updated_save_time_);
516 content::NotificationService::current()->Notify( 513 content::NotificationService::current()->Notify(
517 chrome::NOTIFICATION_SESSION_SERVICE_SAVED, 514 chrome::NOTIFICATION_SESSION_SERVICE_SAVED,
518 content::Source<Profile>(profile()), 515 content::Source<Profile>(profile()),
519 content::NotificationService::NoDetails()); 516 content::NotificationService::NoDetails());
520 } 517 }
521 } 518 }
522 519
523 void SessionService::Init() { 520 void SessionService::Init() {
524 // Register for the notifications we're interested in. 521 // Register for the notifications we're interested in.
525 registrar_.Add(this, chrome::NOTIFICATION_TAB_PARENTED, 522 registrar_.Add(this, chrome::NOTIFICATION_TAB_PARENTED,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 break; 600 break;
604 } 601 }
605 602
606 case chrome::NOTIFICATION_TAB_PARENTED: { 603 case chrome::NOTIFICATION_TAB_PARENTED: {
607 TabContents* tab = content::Source<TabContents>(source).ptr(); 604 TabContents* tab = content::Source<TabContents>(source).ptr();
608 if (tab->profile() != profile()) 605 if (tab->profile() != profile())
609 return; 606 return;
610 SetTabWindow(tab->restore_tab_helper()->window_id(), 607 SetTabWindow(tab->restore_tab_helper()->window_id(),
611 tab->restore_tab_helper()->session_id()); 608 tab->restore_tab_helper()->session_id());
612 if (tab->extension_tab_helper()->extension_app()) { 609 if (tab->extension_tab_helper()->extension_app()) {
613 SetTabExtensionAppID( 610 SetTabExtensionAppID(tab->restore_tab_helper()->window_id(),
614 tab->restore_tab_helper()->window_id(),
615 tab->restore_tab_helper()->session_id(), 611 tab->restore_tab_helper()->session_id(),
616 tab->extension_tab_helper()->extension_app()->id()); 612 tab->extension_tab_helper()->extension_app()->id());
617 } 613 }
618 614
619 // Record the association between the SessionStorageNamespace and the 615 // Record the association between the SessionStorageNamespace and the
620 // tab. 616 // tab.
621 // 617 //
622 // TODO(ajwong): This should be processing the whole map rather than 618 // TODO(ajwong): This should be processing the whole map rather than
623 // just the default. This in particular will not work for tabs with only 619 // just the default. This in particular will not work for tabs with only
624 // isolated apps which won't have a default partition. 620 // isolated apps which won't have a default partition.
(...skipping 25 matching lines...) Expand all
650 } 646 }
651 647
652 case content::NOTIFICATION_NAV_LIST_PRUNED: { 648 case content::NOTIFICATION_NAV_LIST_PRUNED: {
653 TabContents* tab = TabContents::FromWebContents( 649 TabContents* tab = TabContents::FromWebContents(
654 content::Source<content::NavigationController>(source).ptr()-> 650 content::Source<content::NavigationController>(source).ptr()->
655 GetWebContents()); 651 GetWebContents());
656 if (!tab || tab->profile() != profile()) 652 if (!tab || tab->profile() != profile())
657 return; 653 return;
658 content::Details<content::PrunedDetails> pruned_details(details); 654 content::Details<content::PrunedDetails> pruned_details(details);
659 if (pruned_details->from_front) { 655 if (pruned_details->from_front) {
660 TabNavigationPathPrunedFromFront( 656 TabNavigationPathPrunedFromFront(tab->restore_tab_helper()->window_id(),
661 tab->restore_tab_helper()->window_id(),
662 tab->restore_tab_helper()->session_id(), 657 tab->restore_tab_helper()->session_id(),
663 pruned_details->count); 658 pruned_details->count);
664 } else { 659 } else {
665 TabNavigationPathPrunedFromBack( 660 TabNavigationPathPrunedFromBack(tab->restore_tab_helper()->window_id(),
666 tab->restore_tab_helper()->window_id(),
667 tab->restore_tab_helper()->session_id(), 661 tab->restore_tab_helper()->session_id(),
668 tab->web_contents()->GetController().GetEntryCount()); 662 tab->web_contents()->GetController().GetEntryCount());
669 } 663 }
670 RecordSessionUpdateHistogramData(content::NOTIFICATION_NAV_LIST_PRUNED, 664 RecordSessionUpdateHistogramData(type,
671 &last_updated_nav_list_pruned_time_); 665 &last_updated_nav_list_pruned_time_);
672 break; 666 break;
673 } 667 }
674 668
675 case content::NOTIFICATION_NAV_ENTRY_CHANGED: { 669 case content::NOTIFICATION_NAV_ENTRY_CHANGED: {
676 TabContents* tab = TabContents::FromWebContents( 670 TabContents* tab = TabContents::FromWebContents(
677 content::Source<content::NavigationController>(source).ptr()-> 671 content::Source<content::NavigationController>(source).ptr()->
678 GetWebContents()); 672 GetWebContents());
679 if (!tab || tab->profile() != profile()) 673 if (!tab || tab->profile() != profile())
680 return; 674 return;
681 content::Details<content::EntryChangedDetails> changed(details); 675 content::Details<content::EntryChangedDetails> changed(details);
682 UpdateTabNavigation( 676 UpdateTabNavigation(tab->restore_tab_helper()->window_id(),
683 tab->restore_tab_helper()->window_id(), 677 tab->restore_tab_helper()->session_id(),
684 tab->restore_tab_helper()->session_id(), 678 changed->index, *changed->changed_entry);
685 changed->index, *changed->changed_entry);
686 break; 679 break;
687 } 680 }
688 681
689 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { 682 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
690 TabContents* tab = TabContents::FromWebContents( 683 TabContents* tab = TabContents::FromWebContents(
691 content::Source<content::NavigationController>(source).ptr()-> 684 content::Source<content::NavigationController>(source).ptr()->
692 GetWebContents()); 685 GetWebContents());
693 if (!tab || tab->profile() != profile()) 686 if (!tab || tab->profile() != profile())
694 return; 687 return;
695 int current_entry_index = 688 int current_entry_index =
696 tab->web_contents()->GetController().GetCurrentEntryIndex(); 689 tab->web_contents()->GetController().GetCurrentEntryIndex();
697 SetSelectedNavigationIndex(tab->restore_tab_helper()->window_id(), 690 SetSelectedNavigationIndex(tab->restore_tab_helper()->window_id(),
698 tab->restore_tab_helper()->session_id(), 691 tab->restore_tab_helper()->session_id(), current_entry_index);
699 current_entry_index); 692 UpdateTabNavigation(tab->restore_tab_helper()->window_id(),
700 UpdateTabNavigation(
701 tab->restore_tab_helper()->window_id(),
702 tab->restore_tab_helper()->session_id(), 693 tab->restore_tab_helper()->session_id(),
703 current_entry_index, 694 current_entry_index,
704 *tab->web_contents()->GetController().GetEntryAtIndex( 695 *tab->web_contents()->GetController().GetEntryAtIndex(
705 current_entry_index)); 696 current_entry_index));
706 content::Details<content::LoadCommittedDetails> changed(details); 697 content::Details<content::LoadCommittedDetails> changed(details);
707 if (changed->type == content::NAVIGATION_TYPE_NEW_PAGE || 698 if (changed->type == content::NAVIGATION_TYPE_NEW_PAGE ||
708 changed->type == content::NAVIGATION_TYPE_EXISTING_PAGE) { 699 changed->type == content::NAVIGATION_TYPE_EXISTING_PAGE) {
709 RecordSessionUpdateHistogramData( 700 RecordSessionUpdateHistogramData(type,
710 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 701 &last_updated_nav_entry_commit_time_);
711 &last_updated_nav_entry_commit_time_);
712 } 702 }
713 break; 703 break;
714 } 704 }
715 705
716 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { 706 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: {
717 extensions::TabHelper* extension_tab_helper = 707 extensions::TabHelper* extension_tab_helper =
718 content::Source<extensions::TabHelper>(source).ptr(); 708 content::Source<extensions::TabHelper>(source).ptr();
719 if (extension_tab_helper->tab_contents()->profile() != profile()) 709 if (extension_tab_helper->tab_contents()->profile() != profile())
720 return; 710 return;
721 if (extension_tab_helper->extension_app()) { 711 if (extension_tab_helper->extension_app()) {
722 RestoreTabHelper* helper = 712 RestoreTabHelper* helper =
723 extension_tab_helper->tab_contents()->restore_tab_helper(); 713 extension_tab_helper->tab_contents()->restore_tab_helper();
724 SetTabExtensionAppID(helper->window_id(), 714 SetTabExtensionAppID(helper->window_id(), helper->session_id(),
725 helper->session_id(),
726 extension_tab_helper->extension_app()->id()); 715 extension_tab_helper->extension_app()->id());
727 } 716 }
728 break; 717 break;
729 } 718 }
730 719
731 default: 720 default:
732 NOTREACHED(); 721 NOTREACHED();
733 } 722 }
734 } 723 }
735 724
736 void SessionService::SetTabExtensionAppID( 725 void SessionService::SetTabExtensionAppID(
737 const SessionID& window_id, 726 const SessionID& window_id,
738 const SessionID& tab_id, 727 const SessionID& tab_id,
739 const std::string& extension_app_id) { 728 const std::string& extension_app_id) {
740 if (!ShouldTrackChangesToWindow(window_id)) 729 if (!ShouldTrackChangesToWindow(window_id))
741 return; 730 return;
742 731
743 ScheduleCommand(CreateSetTabExtensionAppIDCommand( 732 ScheduleCommand(CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID,
744 kCommandSetExtensionAppID, 733 tab_id.id(), extension_app_id));
745 tab_id.id(),
746 extension_app_id));
747 } 734 }
748 735
749 SessionCommand* SessionService::CreateSetSelectedTabInWindow( 736 SessionCommand* SessionService::CreateSetSelectedTabInWindow(
750 const SessionID& window_id, 737 const SessionID& window_id,
751 int index) { 738 int index) {
752 SelectedTabInIndexPayload payload = { 0 }; 739 SelectedTabInIndexPayload payload = { 0 };
753 payload.id = window_id.id(); 740 payload.id = window_id.id();
754 payload.index = index; 741 payload.index = index;
755 SessionCommand* command = new SessionCommand(kCommandSetSelectedTabInIndex, 742 SessionCommand* command = new SessionCommand(kCommandSetSelectedTabInIndex,
756 sizeof(payload)); 743 sizeof(payload));
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 50); 1718 50);
1732 if (use_long_period) { 1719 if (use_long_period) {
1733 std::string long_name_("SessionRestore.SaveLongPeriod"); 1720 std::string long_name_("SessionRestore.SaveLongPeriod");
1734 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, 1721 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
1735 delta, 1722 delta,
1736 save_delay_in_mins_, 1723 save_delay_in_mins_,
1737 save_delay_in_hrs_, 1724 save_delay_in_hrs_,
1738 50); 1725 50);
1739 } 1726 }
1740 } 1727 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698