| OLD | NEW |
| 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 SessionCommand* command = | 423 SessionCommand* command = |
| 424 new SessionCommand(kCommandTabNavigationPathPrunedFromFront, | 424 new SessionCommand(kCommandTabNavigationPathPrunedFromFront, |
| 425 sizeof(payload)); | 425 sizeof(payload)); |
| 426 memcpy(command->contents(), &payload, sizeof(payload)); | 426 memcpy(command->contents(), &payload, sizeof(payload)); |
| 427 ScheduleCommand(command); | 427 ScheduleCommand(command); |
| 428 } | 428 } |
| 429 | 429 |
| 430 void SessionService::UpdateTabNavigation( | 430 void SessionService::UpdateTabNavigation( |
| 431 const SessionID& window_id, | 431 const SessionID& window_id, |
| 432 const SessionID& tab_id, | 432 const SessionID& tab_id, |
| 433 int index, | 433 const TabNavigation& navigation) { |
| 434 const NavigationEntry& entry) { | 434 if (!ShouldTrackEntry(navigation.virtual_url()) || |
| 435 if (!ShouldTrackEntry(entry.GetVirtualURL()) || | |
| 436 !ShouldTrackChangesToWindow(window_id)) { | 435 !ShouldTrackChangesToWindow(window_id)) { |
| 437 return; | 436 return; |
| 438 } | 437 } |
| 439 | 438 |
| 440 if (tab_to_available_range_.find(tab_id.id()) != | 439 if (tab_to_available_range_.find(tab_id.id()) != |
| 441 tab_to_available_range_.end()) { | 440 tab_to_available_range_.end()) { |
| 442 std::pair<int, int>& range = tab_to_available_range_[tab_id.id()]; | 441 std::pair<int, int>& range = tab_to_available_range_[tab_id.id()]; |
| 443 range.first = std::min(index, range.first); | 442 range.first = std::min(navigation.index(), range.first); |
| 444 range.second = std::max(index, range.second); | 443 range.second = std::max(navigation.index(), range.second); |
| 445 } | 444 } |
| 446 ScheduleCommand(CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, | 445 ScheduleCommand(CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, |
| 447 tab_id.id(), index, entry)); | 446 tab_id.id(), navigation)); |
| 448 } | 447 } |
| 449 | 448 |
| 450 void SessionService::TabRestored(TabContents* tab, bool pinned) { | 449 void SessionService::TabRestored(TabContents* tab, bool pinned) { |
| 451 SessionTabHelper* session_tab_helper = | 450 SessionTabHelper* session_tab_helper = |
| 452 SessionTabHelper::FromWebContents(tab->web_contents()); | 451 SessionTabHelper::FromWebContents(tab->web_contents()); |
| 453 if (!ShouldTrackChangesToWindow(session_tab_helper->window_id())) | 452 if (!ShouldTrackChangesToWindow(session_tab_helper->window_id())) |
| 454 return; | 453 return; |
| 455 | 454 |
| 456 BuildCommandsForTab(session_tab_helper->window_id(), tab, -1, | 455 BuildCommandsForTab(session_tab_helper->window_id(), tab, -1, |
| 457 pinned, &pending_commands(), NULL); | 456 pinned, &pending_commands(), NULL); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 | 681 |
| 683 case content::NOTIFICATION_NAV_ENTRY_CHANGED: { | 682 case content::NOTIFICATION_NAV_ENTRY_CHANGED: { |
| 684 WebContents* web_contents = | 683 WebContents* web_contents = |
| 685 content::Source<content::NavigationController>(source).ptr()-> | 684 content::Source<content::NavigationController>(source).ptr()-> |
| 686 GetWebContents(); | 685 GetWebContents(); |
| 687 SessionTabHelper* session_tab_helper = | 686 SessionTabHelper* session_tab_helper = |
| 688 SessionTabHelper::FromWebContents(web_contents); | 687 SessionTabHelper::FromWebContents(web_contents); |
| 689 if (!session_tab_helper || web_contents->GetBrowserContext() != profile()) | 688 if (!session_tab_helper || web_contents->GetBrowserContext() != profile()) |
| 690 return; | 689 return; |
| 691 content::Details<content::EntryChangedDetails> changed(details); | 690 content::Details<content::EntryChangedDetails> changed(details); |
| 691 const TabNavigation navigation = |
| 692 TabNavigation::FromNavigationEntry( |
| 693 changed->index, *changed->changed_entry, |
| 694 base::Time::Now()); |
| 692 UpdateTabNavigation(session_tab_helper->window_id(), | 695 UpdateTabNavigation(session_tab_helper->window_id(), |
| 693 session_tab_helper->session_id(), | 696 session_tab_helper->session_id(), |
| 694 changed->index, *changed->changed_entry); | 697 navigation); |
| 695 break; | 698 break; |
| 696 } | 699 } |
| 697 | 700 |
| 698 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { | 701 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
| 699 WebContents* web_contents = | 702 WebContents* web_contents = |
| 700 content::Source<content::NavigationController>(source).ptr()-> | 703 content::Source<content::NavigationController>(source).ptr()-> |
| 701 GetWebContents(); | 704 GetWebContents(); |
| 702 SessionTabHelper* session_tab_helper = | 705 SessionTabHelper* session_tab_helper = |
| 703 SessionTabHelper::FromWebContents(web_contents); | 706 SessionTabHelper::FromWebContents(web_contents); |
| 704 if (!session_tab_helper || web_contents->GetBrowserContext() != profile()) | 707 if (!session_tab_helper || web_contents->GetBrowserContext() != profile()) |
| 705 return; | 708 return; |
| 706 int current_entry_index = | 709 int current_entry_index = |
| 707 web_contents->GetController().GetCurrentEntryIndex(); | 710 web_contents->GetController().GetCurrentEntryIndex(); |
| 708 SetSelectedNavigationIndex( | 711 SetSelectedNavigationIndex( |
| 709 session_tab_helper->window_id(), | 712 session_tab_helper->window_id(), |
| 710 session_tab_helper->session_id(), | 713 session_tab_helper->session_id(), |
| 711 current_entry_index); | 714 current_entry_index); |
| 715 const TabNavigation navigation = |
| 716 TabNavigation::FromNavigationEntry( |
| 717 current_entry_index, |
| 718 *web_contents->GetController().GetEntryAtIndex( |
| 719 current_entry_index), |
| 720 base::Time::Now()); |
| 712 UpdateTabNavigation( | 721 UpdateTabNavigation( |
| 713 session_tab_helper->window_id(), | 722 session_tab_helper->window_id(), |
| 714 session_tab_helper->session_id(), | 723 session_tab_helper->session_id(), |
| 715 current_entry_index, | 724 navigation); |
| 716 *web_contents->GetController().GetEntryAtIndex(current_entry_index)); | |
| 717 content::Details<content::LoadCommittedDetails> changed(details); | 725 content::Details<content::LoadCommittedDetails> changed(details); |
| 718 if (changed->type == content::NAVIGATION_TYPE_NEW_PAGE || | 726 if (changed->type == content::NAVIGATION_TYPE_NEW_PAGE || |
| 719 changed->type == content::NAVIGATION_TYPE_EXISTING_PAGE) { | 727 changed->type == content::NAVIGATION_TYPE_EXISTING_PAGE) { |
| 720 RecordSessionUpdateHistogramData(type, | 728 RecordSessionUpdateHistogramData(type, |
| 721 &last_updated_nav_entry_commit_time_); | 729 &last_updated_nav_entry_commit_time_); |
| 722 } | 730 } |
| 723 break; | 731 break; |
| 724 } | 732 } |
| 725 | 733 |
| 726 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { | 734 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 CreateSetTabUserAgentOverrideCommand( | 1353 CreateSetTabUserAgentOverrideCommand( |
| 1346 kCommandSetTabUserAgentOverride, session_id.id(), ua_override)); | 1354 kCommandSetTabUserAgentOverride, session_id.id(), ua_override)); |
| 1347 } | 1355 } |
| 1348 | 1356 |
| 1349 for (int i = min_index; i < max_index; ++i) { | 1357 for (int i = min_index; i < max_index; ++i) { |
| 1350 const NavigationEntry* entry = (i == pending_index) ? | 1358 const NavigationEntry* entry = (i == pending_index) ? |
| 1351 tab->web_contents()->GetController().GetPendingEntry() : | 1359 tab->web_contents()->GetController().GetPendingEntry() : |
| 1352 tab->web_contents()->GetController().GetEntryAtIndex(i); | 1360 tab->web_contents()->GetController().GetEntryAtIndex(i); |
| 1353 DCHECK(entry); | 1361 DCHECK(entry); |
| 1354 if (ShouldTrackEntry(entry->GetVirtualURL())) { | 1362 if (ShouldTrackEntry(entry->GetVirtualURL())) { |
| 1363 const TabNavigation navigation = |
| 1364 TabNavigation::FromNavigationEntry(i, *entry, base::Time::Now()); |
| 1355 commands->push_back( | 1365 commands->push_back( |
| 1356 CreateUpdateTabNavigationCommand( | 1366 CreateUpdateTabNavigationCommand( |
| 1357 kCommandUpdateTabNavigation, session_id.id(), i, *entry)); | 1367 kCommandUpdateTabNavigation, session_id.id(), navigation)); |
| 1358 } | 1368 } |
| 1359 } | 1369 } |
| 1360 commands->push_back( | 1370 commands->push_back( |
| 1361 CreateSetSelectedNavigationIndexCommand(session_id, current_index)); | 1371 CreateSetSelectedNavigationIndexCommand(session_id, current_index)); |
| 1362 | 1372 |
| 1363 if (index_in_window != -1) { | 1373 if (index_in_window != -1) { |
| 1364 commands->push_back( | 1374 commands->push_back( |
| 1365 CreateSetTabIndexInWindowCommand(session_id, index_in_window)); | 1375 CreateSetTabIndexInWindowCommand(session_id, index_in_window)); |
| 1366 } | 1376 } |
| 1367 | 1377 |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1746 50); | 1756 50); |
| 1747 if (use_long_period) { | 1757 if (use_long_period) { |
| 1748 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1758 std::string long_name_("SessionRestore.SaveLongPeriod"); |
| 1749 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1759 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
| 1750 delta, | 1760 delta, |
| 1751 save_delay_in_mins_, | 1761 save_delay_in_mins_, |
| 1752 save_delay_in_hrs_, | 1762 save_delay_in_hrs_, |
| 1753 50); | 1763 50); |
| 1754 } | 1764 } |
| 1755 } | 1765 } |
| OLD | NEW |