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

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

Issue 10917231: Revamp TabNavigation class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indent 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 682
684 case content::NOTIFICATION_NAV_ENTRY_CHANGED: { 683 case content::NOTIFICATION_NAV_ENTRY_CHANGED: {
685 WebContents* web_contents = 684 WebContents* web_contents =
686 content::Source<content::NavigationController>(source).ptr()-> 685 content::Source<content::NavigationController>(source).ptr()->
687 GetWebContents(); 686 GetWebContents();
688 SessionTabHelper* session_tab_helper = 687 SessionTabHelper* session_tab_helper =
689 SessionTabHelper::FromWebContents(web_contents); 688 SessionTabHelper::FromWebContents(web_contents);
690 if (!session_tab_helper || web_contents->GetBrowserContext() != profile()) 689 if (!session_tab_helper || web_contents->GetBrowserContext() != profile())
691 return; 690 return;
692 content::Details<content::EntryChangedDetails> changed(details); 691 content::Details<content::EntryChangedDetails> changed(details);
692 const TabNavigation& navigation =
693 TabNavigation::FromNavigationEntry(
694 changed->index, *changed->changed_entry,
695 base::Time::Now());
693 UpdateTabNavigation(session_tab_helper->window_id(), 696 UpdateTabNavigation(session_tab_helper->window_id(),
694 session_tab_helper->session_id(), 697 session_tab_helper->session_id(),
695 changed->index, *changed->changed_entry); 698 navigation);
696 break; 699 break;
697 } 700 }
698 701
699 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { 702 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
700 WebContents* web_contents = 703 WebContents* web_contents =
701 content::Source<content::NavigationController>(source).ptr()-> 704 content::Source<content::NavigationController>(source).ptr()->
702 GetWebContents(); 705 GetWebContents();
703 SessionTabHelper* session_tab_helper = 706 SessionTabHelper* session_tab_helper =
704 SessionTabHelper::FromWebContents(web_contents); 707 SessionTabHelper::FromWebContents(web_contents);
705 if (!session_tab_helper || web_contents->GetBrowserContext() != profile()) 708 if (!session_tab_helper || web_contents->GetBrowserContext() != profile())
706 return; 709 return;
707 int current_entry_index = 710 int current_entry_index =
708 web_contents->GetController().GetCurrentEntryIndex(); 711 web_contents->GetController().GetCurrentEntryIndex();
709 SetSelectedNavigationIndex( 712 SetSelectedNavigationIndex(
710 session_tab_helper->window_id(), 713 session_tab_helper->window_id(),
711 session_tab_helper->session_id(), 714 session_tab_helper->session_id(),
712 current_entry_index); 715 current_entry_index);
716 const TabNavigation& navigation =
717 TabNavigation::FromNavigationEntry(
718 current_entry_index,
719 *web_contents->GetController().GetEntryAtIndex(
720 current_entry_index),
721 base::Time::Now());
713 UpdateTabNavigation( 722 UpdateTabNavigation(
714 session_tab_helper->window_id(), 723 session_tab_helper->window_id(),
715 session_tab_helper->session_id(), 724 session_tab_helper->session_id(),
716 current_entry_index, 725 navigation);
717 *web_contents->GetController().GetEntryAtIndex(current_entry_index));
718 content::Details<content::LoadCommittedDetails> changed(details); 726 content::Details<content::LoadCommittedDetails> changed(details);
719 if (changed->type == content::NAVIGATION_TYPE_NEW_PAGE || 727 if (changed->type == content::NAVIGATION_TYPE_NEW_PAGE ||
720 changed->type == content::NAVIGATION_TYPE_EXISTING_PAGE) { 728 changed->type == content::NAVIGATION_TYPE_EXISTING_PAGE) {
721 RecordSessionUpdateHistogramData(type, 729 RecordSessionUpdateHistogramData(type,
722 &last_updated_nav_entry_commit_time_); 730 &last_updated_nav_entry_commit_time_);
723 } 731 }
724 break; 732 break;
725 } 733 }
726 734
727 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { 735 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: {
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 CreateSetTabUserAgentOverrideCommand( 1354 CreateSetTabUserAgentOverrideCommand(
1347 kCommandSetTabUserAgentOverride, session_id.id(), ua_override)); 1355 kCommandSetTabUserAgentOverride, session_id.id(), ua_override));
1348 } 1356 }
1349 1357
1350 for (int i = min_index; i < max_index; ++i) { 1358 for (int i = min_index; i < max_index; ++i) {
1351 const NavigationEntry* entry = (i == pending_index) ? 1359 const NavigationEntry* entry = (i == pending_index) ?
1352 tab->web_contents()->GetController().GetPendingEntry() : 1360 tab->web_contents()->GetController().GetPendingEntry() :
1353 tab->web_contents()->GetController().GetEntryAtIndex(i); 1361 tab->web_contents()->GetController().GetEntryAtIndex(i);
1354 DCHECK(entry); 1362 DCHECK(entry);
1355 if (ShouldTrackEntry(entry->GetVirtualURL())) { 1363 if (ShouldTrackEntry(entry->GetVirtualURL())) {
1364 const TabNavigation& navigation =
1365 TabNavigation::FromNavigationEntry(i, *entry, base::Time::Now());
1356 commands->push_back( 1366 commands->push_back(
1357 CreateUpdateTabNavigationCommand( 1367 CreateUpdateTabNavigationCommand(
1358 kCommandUpdateTabNavigation, session_id.id(), i, *entry)); 1368 kCommandUpdateTabNavigation, session_id.id(), navigation));
1359 } 1369 }
1360 } 1370 }
1361 commands->push_back( 1371 commands->push_back(
1362 CreateSetSelectedNavigationIndexCommand(session_id, current_index)); 1372 CreateSetSelectedNavigationIndexCommand(session_id, current_index));
1363 1373
1364 if (index_in_window != -1) { 1374 if (index_in_window != -1) {
1365 commands->push_back( 1375 commands->push_back(
1366 CreateSetTabIndexInWindowCommand(session_id, index_in_window)); 1376 CreateSetTabIndexInWindowCommand(session_id, index_in_window));
1367 } 1377 }
1368 1378
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 50); 1757 50);
1748 if (use_long_period) { 1758 if (use_long_period) {
1749 std::string long_name_("SessionRestore.SaveLongPeriod"); 1759 std::string long_name_("SessionRestore.SaveLongPeriod");
1750 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, 1760 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
1751 delta, 1761 delta,
1752 save_delay_in_mins_, 1762 save_delay_in_mins_,
1753 save_delay_in_hrs_, 1763 save_delay_in_hrs_,
1754 50); 1764 50);
1755 } 1765 }
1756 } 1766 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698