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

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

Issue 10536074: TabContentsWrapper -> TabContents, part 26. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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 11 matching lines...) Expand all
22 #include "chrome/browser/prefs/session_startup_pref.h" 22 #include "chrome/browser/prefs/session_startup_pref.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/sessions/restore_tab_helper.h" 24 #include "chrome/browser/sessions/restore_tab_helper.h"
25 #include "chrome/browser/sessions/session_backend.h" 25 #include "chrome/browser/sessions/session_backend.h"
26 #include "chrome/browser/sessions/session_command.h" 26 #include "chrome/browser/sessions/session_command.h"
27 #include "chrome/browser/sessions/session_restore.h" 27 #include "chrome/browser/sessions/session_restore.h"
28 #include "chrome/browser/sessions/session_types.h" 28 #include "chrome/browser/sessions/session_types.h"
29 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/browser/ui/browser_window.h" 30 #include "chrome/browser/ui/browser_window.h"
31 #include "chrome/browser/ui/startup/startup_browser_creator.h" 31 #include "chrome/browser/ui/startup/startup_browser_creator.h"
32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 32 #include "chrome/browser/ui/tab_contents/tab_contents.h"
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" 33 #include "chrome/browser/ui/tabs/tab_strip_model.h"
34 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
35 #include "chrome/common/extensions/extension.h" 35 #include "chrome/common/extensions/extension.h"
36 #include "content/public/browser/navigation_details.h" 36 #include "content/public/browser/navigation_details.h"
37 #include "content/public/browser/navigation_entry.h" 37 #include "content/public/browser/navigation_entry.h"
38 #include "content/public/browser/notification_details.h" 38 #include "content/public/browser/notification_details.h"
39 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
40 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
41 41
42 #if defined(OS_MACOSX) 42 #if defined(OS_MACOSX)
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 if (tab_to_available_range_.find(tab_id.id()) != 436 if (tab_to_available_range_.find(tab_id.id()) !=
437 tab_to_available_range_.end()) { 437 tab_to_available_range_.end()) {
438 std::pair<int, int>& range = tab_to_available_range_[tab_id.id()]; 438 std::pair<int, int>& range = tab_to_available_range_[tab_id.id()];
439 range.first = std::min(index, range.first); 439 range.first = std::min(index, range.first);
440 range.second = std::max(index, range.second); 440 range.second = std::max(index, range.second);
441 } 441 }
442 ScheduleCommand(CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, 442 ScheduleCommand(CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation,
443 tab_id.id(), index, entry)); 443 tab_id.id(), index, entry));
444 } 444 }
445 445
446 void SessionService::TabRestored(TabContentsWrapper* tab, bool pinned) { 446 void SessionService::TabRestored(TabContents* tab, bool pinned) {
447 if (!ShouldTrackChangesToWindow(tab->restore_tab_helper()->window_id())) 447 if (!ShouldTrackChangesToWindow(tab->restore_tab_helper()->window_id()))
448 return; 448 return;
449 449
450 BuildCommandsForTab(tab->restore_tab_helper()->window_id(), tab, -1, 450 BuildCommandsForTab(tab->restore_tab_helper()->window_id(), tab, -1,
451 pinned, &pending_commands(), NULL); 451 pinned, &pending_commands(), NULL);
452 StartSaveTimer(); 452 StartSaveTimer();
453 } 453 }
454 454
455 void SessionService::SetSelectedNavigationIndex(const SessionID& window_id, 455 void SessionService::SetSelectedNavigationIndex(const SessionID& window_id,
456 const SessionID& tab_id, 456 const SessionID& tab_id,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 !should_track_changes_for_browser_type(browser->type(), app_type)) 581 !should_track_changes_for_browser_type(browser->type(), app_type))
582 return; 582 return;
583 583
584 RestoreIfNecessary(std::vector<GURL>(), browser); 584 RestoreIfNecessary(std::vector<GURL>(), browser);
585 SetWindowType(browser->session_id(), browser->type(), app_type); 585 SetWindowType(browser->session_id(), browser->type(), app_type);
586 SetWindowAppName(browser->session_id(), browser->app_name()); 586 SetWindowAppName(browser->session_id(), browser->app_name());
587 break; 587 break;
588 } 588 }
589 589
590 case chrome::NOTIFICATION_TAB_PARENTED: { 590 case chrome::NOTIFICATION_TAB_PARENTED: {
591 TabContentsWrapper* tab = 591 TabContents* tab = content::Source<TabContents>(source).ptr();
592 content::Source<TabContentsWrapper>(source).ptr();
593 if (tab->profile() != profile()) 592 if (tab->profile() != profile())
594 return; 593 return;
595 SetTabWindow(tab->restore_tab_helper()->window_id(), 594 SetTabWindow(tab->restore_tab_helper()->window_id(),
596 tab->restore_tab_helper()->session_id()); 595 tab->restore_tab_helper()->session_id());
597 if (tab->extension_tab_helper()->extension_app()) { 596 if (tab->extension_tab_helper()->extension_app()) {
598 SetTabExtensionAppID( 597 SetTabExtensionAppID(
599 tab->restore_tab_helper()->window_id(), 598 tab->restore_tab_helper()->window_id(),
600 tab->restore_tab_helper()->session_id(), 599 tab->restore_tab_helper()->session_id(),
601 tab->extension_tab_helper()->extension_app()->id()); 600 tab->extension_tab_helper()->extension_app()->id());
602 } 601 }
603 break; 602 break;
604 } 603 }
605 604
606 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { 605 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: {
607 TabContentsWrapper* tab = 606 TabContents* tab = content::Source<TabContents>(source).ptr();
608 content::Source<TabContentsWrapper>(source).ptr();
609 if (!tab || tab->profile() != profile()) 607 if (!tab || tab->profile() != profile())
610 return; 608 return;
611 TabClosed(tab->restore_tab_helper()->window_id(), 609 TabClosed(tab->restore_tab_helper()->window_id(),
612 tab->restore_tab_helper()->session_id(), 610 tab->restore_tab_helper()->session_id(),
613 tab->web_contents()->GetClosedByUserGesture()); 611 tab->web_contents()->GetClosedByUserGesture());
614 RecordSessionUpdateHistogramData(type, &last_updated_tab_closed_time_); 612 RecordSessionUpdateHistogramData(type, &last_updated_tab_closed_time_);
615 break; 613 break;
616 } 614 }
617 615
618 case content::NOTIFICATION_NAV_LIST_PRUNED: { 616 case content::NOTIFICATION_NAV_LIST_PRUNED: {
619 TabContentsWrapper* tab = 617 TabContents* tab = TabContents::FromWebContents(
620 TabContentsWrapper::GetCurrentWrapperForContents( 618 content::Source<content::NavigationController>(source).ptr()->
621 content::Source<content::NavigationController>( 619 GetWebContents());
622 source).ptr()->GetWebContents());
623 if (!tab || tab->profile() != profile()) 620 if (!tab || tab->profile() != profile())
624 return; 621 return;
625 content::Details<content::PrunedDetails> pruned_details(details); 622 content::Details<content::PrunedDetails> pruned_details(details);
626 if (pruned_details->from_front) { 623 if (pruned_details->from_front) {
627 TabNavigationPathPrunedFromFront( 624 TabNavigationPathPrunedFromFront(
628 tab->restore_tab_helper()->window_id(), 625 tab->restore_tab_helper()->window_id(),
629 tab->restore_tab_helper()->session_id(), 626 tab->restore_tab_helper()->session_id(),
630 pruned_details->count); 627 pruned_details->count);
631 } else { 628 } else {
632 TabNavigationPathPrunedFromBack( 629 TabNavigationPathPrunedFromBack(
633 tab->restore_tab_helper()->window_id(), 630 tab->restore_tab_helper()->window_id(),
634 tab->restore_tab_helper()->session_id(), 631 tab->restore_tab_helper()->session_id(),
635 tab->web_contents()->GetController().GetEntryCount()); 632 tab->web_contents()->GetController().GetEntryCount());
636 } 633 }
637 RecordSessionUpdateHistogramData(content::NOTIFICATION_NAV_LIST_PRUNED, 634 RecordSessionUpdateHistogramData(content::NOTIFICATION_NAV_LIST_PRUNED,
638 &last_updated_nav_list_pruned_time_); 635 &last_updated_nav_list_pruned_time_);
639 break; 636 break;
640 } 637 }
641 638
642 case content::NOTIFICATION_NAV_ENTRY_CHANGED: { 639 case content::NOTIFICATION_NAV_ENTRY_CHANGED: {
643 TabContentsWrapper* tab = 640 TabContents* tab = TabContents::FromWebContents(
644 TabContentsWrapper::GetCurrentWrapperForContents( 641 content::Source<content::NavigationController>(source).ptr()->
645 content::Source<content::NavigationController>( 642 GetWebContents());
646 source).ptr()->GetWebContents());
647 if (!tab || tab->profile() != profile()) 643 if (!tab || tab->profile() != profile())
648 return; 644 return;
649 content::Details<content::EntryChangedDetails> changed(details); 645 content::Details<content::EntryChangedDetails> changed(details);
650 UpdateTabNavigation( 646 UpdateTabNavigation(
651 tab->restore_tab_helper()->window_id(), 647 tab->restore_tab_helper()->window_id(),
652 tab->restore_tab_helper()->session_id(), 648 tab->restore_tab_helper()->session_id(),
653 changed->index, *changed->changed_entry); 649 changed->index, *changed->changed_entry);
654 break; 650 break;
655 } 651 }
656 652
657 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { 653 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
658 TabContentsWrapper* tab = 654 TabContents* tab = TabContents::FromWebContents(
659 TabContentsWrapper::GetCurrentWrapperForContents( 655 content::Source<content::NavigationController>(source).ptr()->
660 content::Source<content::NavigationController>( 656 GetWebContents());
661 source).ptr()->GetWebContents());
662 if (!tab || tab->profile() != profile()) 657 if (!tab || tab->profile() != profile())
663 return; 658 return;
664 int current_entry_index = 659 int current_entry_index =
665 tab->web_contents()->GetController().GetCurrentEntryIndex(); 660 tab->web_contents()->GetController().GetCurrentEntryIndex();
666 SetSelectedNavigationIndex(tab->restore_tab_helper()->window_id(), 661 SetSelectedNavigationIndex(tab->restore_tab_helper()->window_id(),
667 tab->restore_tab_helper()->session_id(), 662 tab->restore_tab_helper()->session_id(),
668 current_entry_index); 663 current_entry_index);
669 UpdateTabNavigation( 664 UpdateTabNavigation(
670 tab->restore_tab_helper()->window_id(), 665 tab->restore_tab_helper()->window_id(),
671 tab->restore_tab_helper()->session_id(), 666 tab->restore_tab_helper()->session_id(),
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 default: 1237 default:
1243 VLOG(1) << "Failed reading an unknown command " << command->id(); 1238 VLOG(1) << "Failed reading an unknown command " << command->id();
1244 return true; 1239 return true;
1245 } 1240 }
1246 } 1241 }
1247 return true; 1242 return true;
1248 } 1243 }
1249 1244
1250 void SessionService::BuildCommandsForTab( 1245 void SessionService::BuildCommandsForTab(
1251 const SessionID& window_id, 1246 const SessionID& window_id,
1252 TabContentsWrapper* tab, 1247 TabContents* tab,
1253 int index_in_window, 1248 int index_in_window,
1254 bool is_pinned, 1249 bool is_pinned,
1255 std::vector<SessionCommand*>* commands, 1250 std::vector<SessionCommand*>* commands,
1256 IdToRange* tab_to_available_range) { 1251 IdToRange* tab_to_available_range) {
1257 DCHECK(tab && commands && window_id.id()); 1252 DCHECK(tab && commands && window_id.id());
1258 const SessionID& session_id(tab->restore_tab_helper()->session_id()); 1253 const SessionID& session_id(tab->restore_tab_helper()->session_id());
1259 commands->push_back(CreateSetTabWindowCommand(window_id, session_id)); 1254 commands->push_back(CreateSetTabWindowCommand(window_id, session_id));
1260 1255
1261 const int current_index = 1256 const int current_index =
1262 tab->web_contents()->GetController().GetCurrentEntryIndex(); 1257 tab->web_contents()->GetController().GetCurrentEntryIndex();
1263 const int min_index = std::max(0, 1258 const int min_index = std::max(0,
1264 current_index - max_persist_navigation_count); 1259 current_index - max_persist_navigation_count);
1265 const int max_index = 1260 const int max_index =
1266 std::min(current_index + max_persist_navigation_count, 1261 std::min(current_index + max_persist_navigation_count,
1267 tab->web_contents()->GetController().GetEntryCount()); 1262 tab->web_contents()->GetController().GetEntryCount());
1268 const int pending_index = 1263 const int pending_index =
1269 tab->web_contents()->GetController().GetPendingEntryIndex(); 1264 tab->web_contents()->GetController().GetPendingEntryIndex();
1270 if (tab_to_available_range) { 1265 if (tab_to_available_range) {
1271 (*tab_to_available_range)[session_id.id()] = 1266 (*tab_to_available_range)[session_id.id()] =
1272 std::pair<int, int>(min_index, max_index); 1267 std::pair<int, int>(min_index, max_index);
1273 } 1268 }
1274 1269
1275 if (is_pinned) { 1270 if (is_pinned) {
1276 commands->push_back(CreatePinnedStateCommand(session_id, true)); 1271 commands->push_back(CreatePinnedStateCommand(session_id, true));
1277 } 1272 }
1278 1273
1279 TabContentsWrapper* wrapper = 1274 if (tab->extension_tab_helper()->extension_app()) {
1280 TabContentsWrapper::GetCurrentWrapperForContents(tab->web_contents());
1281 if (wrapper->extension_tab_helper()->extension_app()) {
1282 commands->push_back( 1275 commands->push_back(
1283 CreateSetTabExtensionAppIDCommand( 1276 CreateSetTabExtensionAppIDCommand(
1284 kCommandSetExtensionAppID, session_id.id(), 1277 kCommandSetExtensionAppID, session_id.id(),
1285 wrapper->extension_tab_helper()->extension_app()->id())); 1278 tab->extension_tab_helper()->extension_app()->id()));
1286 } 1279 }
1287 1280
1288 const std::string& ua_override = tab->web_contents()->GetUserAgentOverride(); 1281 const std::string& ua_override = tab->web_contents()->GetUserAgentOverride();
1289 if (!ua_override.empty()) { 1282 if (!ua_override.empty()) {
1290 commands->push_back( 1283 commands->push_back(
1291 CreateSetTabUserAgentOverrideCommand( 1284 CreateSetTabUserAgentOverrideCommand(
1292 kCommandSetTabUserAgentOverride, session_id.id(), ua_override)); 1285 kCommandSetTabUserAgentOverride, session_id.id(), ua_override));
1293 } 1286 }
1294 1287
1295 for (int i = min_index; i < max_index; ++i) { 1288 for (int i = min_index; i < max_index; ++i) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 1329
1337 if (!browser->app_name().empty()) { 1330 if (!browser->app_name().empty()) {
1338 commands->push_back(CreateSetWindowAppNameCommand( 1331 commands->push_back(CreateSetWindowAppNameCommand(
1339 kCommandSetWindowAppName, 1332 kCommandSetWindowAppName,
1340 browser->session_id().id(), 1333 browser->session_id().id(),
1341 browser->app_name())); 1334 browser->app_name()));
1342 } 1335 }
1343 1336
1344 bool added_to_windows_to_track = false; 1337 bool added_to_windows_to_track = false;
1345 for (int i = 0; i < browser->tab_count(); ++i) { 1338 for (int i = 0; i < browser->tab_count(); ++i) {
1346 TabContentsWrapper* tab = browser->GetTabContentsWrapperAt(i); 1339 TabContents* tab = browser->GetTabContentsAt(i);
1347 DCHECK(tab); 1340 DCHECK(tab);
1348 if (tab->profile() == profile() || profile() == NULL) { 1341 if (tab->profile() == profile() || profile() == NULL) {
1349 BuildCommandsForTab(browser->session_id(), tab, i, 1342 BuildCommandsForTab(browser->session_id(), tab, i,
1350 browser->IsTabPinned(i), 1343 browser->IsTabPinned(i),
1351 commands, tab_to_available_range); 1344 commands, tab_to_available_range);
1352 if (windows_to_track && !added_to_windows_to_track) { 1345 if (windows_to_track && !added_to_windows_to_track) {
1353 windows_to_track->insert(browser->session_id().id()); 1346 windows_to_track->insert(browser->session_id().id());
1354 added_to_windows_to_track = true; 1347 added_to_windows_to_track = true;
1355 } 1348 }
1356 } 1349 }
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 50); 1678 50);
1686 if (use_long_period) { 1679 if (use_long_period) {
1687 std::string long_name_("SessionRestore.SaveLongPeriod"); 1680 std::string long_name_("SessionRestore.SaveLongPeriod");
1688 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, 1681 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
1689 delta, 1682 delta,
1690 save_delay_in_mins_, 1683 save_delay_in_mins_,
1691 save_delay_in_hrs_, 1684 save_delay_in_hrs_,
1692 50); 1685 50);
1693 } 1686 }
1694 } 1687 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/browser/sessions/tab_restore_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698