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

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

Issue 11359201: Remove TabContents from TabStripModelObserver::TabReplacedAt. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 if (tab_to_available_range_.find(tab_id.id()) != 445 if (tab_to_available_range_.find(tab_id.id()) !=
446 tab_to_available_range_.end()) { 446 tab_to_available_range_.end()) {
447 std::pair<int, int>& range = tab_to_available_range_[tab_id.id()]; 447 std::pair<int, int>& range = tab_to_available_range_[tab_id.id()];
448 range.first = std::min(navigation.index(), range.first); 448 range.first = std::min(navigation.index(), range.first);
449 range.second = std::max(navigation.index(), range.second); 449 range.second = std::max(navigation.index(), range.second);
450 } 450 }
451 ScheduleCommand(CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, 451 ScheduleCommand(CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation,
452 tab_id.id(), navigation)); 452 tab_id.id(), navigation));
453 } 453 }
454 454
455 void SessionService::TabRestored(TabContents* tab, bool pinned) { 455 void SessionService::TabRestored(WebContents* tab, bool pinned) {
456 SessionTabHelper* session_tab_helper = 456 SessionTabHelper* session_tab_helper = SessionTabHelper::FromWebContents(tab);
457 SessionTabHelper::FromWebContents(tab->web_contents());
458 if (!ShouldTrackChangesToWindow(session_tab_helper->window_id())) 457 if (!ShouldTrackChangesToWindow(session_tab_helper->window_id()))
459 return; 458 return;
460 459
461 BuildCommandsForTab(session_tab_helper->window_id(), tab, -1, 460 BuildCommandsForTab(session_tab_helper->window_id(), tab, -1,
462 pinned, &pending_commands(), NULL); 461 pinned, &pending_commands(), NULL);
463 StartSaveTimer(); 462 StartSaveTimer();
464 } 463 }
465 464
466 void SessionService::SetSelectedNavigationIndex(const SessionID& window_id, 465 void SessionService::SetSelectedNavigationIndex(const SessionID& window_id,
467 const SessionID& tab_id, 466 const SessionID& tab_id,
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 } 1276 }
1278 1277
1279 default: 1278 default:
1280 VLOG(1) << "Failed reading an unknown command " << command->id(); 1279 VLOG(1) << "Failed reading an unknown command " << command->id();
1281 return true; 1280 return true;
1282 } 1281 }
1283 } 1282 }
1284 return true; 1283 return true;
1285 } 1284 }
1286 1285
1287 void SessionService::BuildCommandsForTab( 1286 void SessionService::BuildCommandsForTab(const SessionID& window_id,
1288 const SessionID& window_id, 1287 WebContents* tab,
1289 TabContents* tab, 1288 int index_in_window,
1290 int index_in_window, 1289 bool is_pinned,
1291 bool is_pinned, 1290 std::vector<SessionCommand*>* commands,
1292 std::vector<SessionCommand*>* commands, 1291 IdToRange* tab_to_available_range) {
1293 IdToRange* tab_to_available_range) {
1294 DCHECK(tab && commands && window_id.id()); 1292 DCHECK(tab && commands && window_id.id());
1295 SessionTabHelper* session_tab_helper = 1293 SessionTabHelper* session_tab_helper = SessionTabHelper::FromWebContents(tab);
1296 SessionTabHelper::FromWebContents(tab->web_contents());
1297 const SessionID& session_id(session_tab_helper->session_id()); 1294 const SessionID& session_id(session_tab_helper->session_id());
1298 commands->push_back(CreateSetTabWindowCommand(window_id, session_id)); 1295 commands->push_back(CreateSetTabWindowCommand(window_id, session_id));
1299 1296
1300 const int current_index = 1297 const int current_index = tab->GetController().GetCurrentEntryIndex();
1301 tab->web_contents()->GetController().GetCurrentEntryIndex();
1302 const int min_index = std::max(0, 1298 const int min_index = std::max(0,
1303 current_index - max_persist_navigation_count); 1299 current_index - max_persist_navigation_count);
1304 const int max_index = 1300 const int max_index =
1305 std::min(current_index + max_persist_navigation_count, 1301 std::min(current_index + max_persist_navigation_count,
1306 tab->web_contents()->GetController().GetEntryCount()); 1302 tab->GetController().GetEntryCount());
1307 const int pending_index = 1303 const int pending_index = tab->GetController().GetPendingEntryIndex();
1308 tab->web_contents()->GetController().GetPendingEntryIndex();
1309 if (tab_to_available_range) { 1304 if (tab_to_available_range) {
1310 (*tab_to_available_range)[session_id.id()] = 1305 (*tab_to_available_range)[session_id.id()] =
1311 std::pair<int, int>(min_index, max_index); 1306 std::pair<int, int>(min_index, max_index);
1312 } 1307 }
1313 1308
1314 if (is_pinned) { 1309 if (is_pinned) {
1315 commands->push_back(CreatePinnedStateCommand(session_id, true)); 1310 commands->push_back(CreatePinnedStateCommand(session_id, true));
1316 } 1311 }
1317 1312
1318 extensions::TabHelper* extensions_tab_helper = 1313 extensions::TabHelper* extensions_tab_helper =
1319 extensions::TabHelper::FromWebContents(tab->web_contents()); 1314 extensions::TabHelper::FromWebContents(tab);
1320 if (extensions_tab_helper->extension_app()) { 1315 if (extensions_tab_helper->extension_app()) {
1321 commands->push_back( 1316 commands->push_back(
1322 CreateSetTabExtensionAppIDCommand( 1317 CreateSetTabExtensionAppIDCommand(
1323 kCommandSetExtensionAppID, session_id.id(), 1318 kCommandSetExtensionAppID, session_id.id(),
1324 extensions_tab_helper->extension_app()->id())); 1319 extensions_tab_helper->extension_app()->id()));
1325 } 1320 }
1326 1321
1327 const std::string& ua_override = tab->web_contents()->GetUserAgentOverride(); 1322 const std::string& ua_override = tab->GetUserAgentOverride();
1328 if (!ua_override.empty()) { 1323 if (!ua_override.empty()) {
1329 commands->push_back( 1324 commands->push_back(
1330 CreateSetTabUserAgentOverrideCommand( 1325 CreateSetTabUserAgentOverrideCommand(
1331 kCommandSetTabUserAgentOverride, session_id.id(), ua_override)); 1326 kCommandSetTabUserAgentOverride, session_id.id(), ua_override));
1332 } 1327 }
1333 1328
1334 for (int i = min_index; i < max_index; ++i) { 1329 for (int i = min_index; i < max_index; ++i) {
1335 const NavigationEntry* entry = (i == pending_index) ? 1330 const NavigationEntry* entry = (i == pending_index) ?
1336 tab->web_contents()->GetController().GetPendingEntry() : 1331 tab->GetController().GetPendingEntry() :
1337 tab->web_contents()->GetController().GetEntryAtIndex(i); 1332 tab->GetController().GetEntryAtIndex(i);
1338 DCHECK(entry); 1333 DCHECK(entry);
1339 if (ShouldTrackEntry(entry->GetVirtualURL())) { 1334 if (ShouldTrackEntry(entry->GetVirtualURL())) {
1340 const TabNavigation navigation = 1335 const TabNavigation navigation =
1341 TabNavigation::FromNavigationEntry(i, *entry); 1336 TabNavigation::FromNavigationEntry(i, *entry);
1342 commands->push_back( 1337 commands->push_back(
1343 CreateUpdateTabNavigationCommand( 1338 CreateUpdateTabNavigationCommand(
1344 kCommandUpdateTabNavigation, session_id.id(), navigation)); 1339 kCommandUpdateTabNavigation, session_id.id(), navigation));
1345 } 1340 }
1346 } 1341 }
1347 commands->push_back( 1342 commands->push_back(
1348 CreateSetSelectedNavigationIndexCommand(session_id, current_index)); 1343 CreateSetSelectedNavigationIndexCommand(session_id, current_index));
1349 1344
1350 if (index_in_window != -1) { 1345 if (index_in_window != -1) {
1351 commands->push_back( 1346 commands->push_back(
1352 CreateSetTabIndexInWindowCommand(session_id, index_in_window)); 1347 CreateSetTabIndexInWindowCommand(session_id, index_in_window));
1353 } 1348 }
1354 1349
1355 // Record the association between the sessionStorage namespace and the tab. 1350 // Record the association between the sessionStorage namespace and the tab.
1356 content::SessionStorageNamespace* session_storage_namespace = 1351 content::SessionStorageNamespace* session_storage_namespace =
1357 tab->web_contents()->GetController().GetDefaultSessionStorageNamespace(); 1352 tab->GetController().GetDefaultSessionStorageNamespace();
1358 ScheduleCommand(CreateSessionStorageAssociatedCommand( 1353 ScheduleCommand(CreateSessionStorageAssociatedCommand(
1359 session_tab_helper->session_id(), 1354 session_tab_helper->session_id(),
1360 session_storage_namespace->persistent_id())); 1355 session_storage_namespace->persistent_id()));
1361 } 1356 }
1362 1357
1363 void SessionService::BuildCommandsForBrowser( 1358 void SessionService::BuildCommandsForBrowser(
1364 Browser* browser, 1359 Browser* browser,
1365 std::vector<SessionCommand*>* commands, 1360 std::vector<SessionCommand*>* commands,
1366 IdToRange* tab_to_available_range, 1361 IdToRange* tab_to_available_range,
1367 std::set<SessionID::id_type>* windows_to_track) { 1362 std::set<SessionID::id_type>* windows_to_track) {
(...skipping 16 matching lines...) Expand all
1384 1379
1385 if (!browser->app_name().empty()) { 1380 if (!browser->app_name().empty()) {
1386 commands->push_back(CreateSetWindowAppNameCommand( 1381 commands->push_back(CreateSetWindowAppNameCommand(
1387 kCommandSetWindowAppName, 1382 kCommandSetWindowAppName,
1388 browser->session_id().id(), 1383 browser->session_id().id(),
1389 browser->app_name())); 1384 browser->app_name()));
1390 } 1385 }
1391 1386
1392 windows_to_track->insert(browser->session_id().id()); 1387 windows_to_track->insert(browser->session_id().id());
1393 for (int i = 0; i < browser->tab_count(); ++i) { 1388 for (int i = 0; i < browser->tab_count(); ++i) {
1394 TabContents* tab = chrome::GetTabContentsAt(browser, i); 1389 WebContents* tab = chrome::GetWebContentsAt(browser, i);
1395 DCHECK(tab); 1390 DCHECK(tab);
1396 BuildCommandsForTab(browser->session_id(), tab, i, 1391 BuildCommandsForTab(browser->session_id(), tab, i,
1397 browser->tab_strip_model()->IsTabPinned(i), 1392 browser->tab_strip_model()->IsTabPinned(i),
1398 commands, tab_to_available_range); 1393 commands, tab_to_available_range);
1399 } 1394 }
1400 1395
1401 commands->push_back( 1396 commands->push_back(
1402 CreateSetSelectedTabInWindow(browser->session_id(), 1397 CreateSetSelectedTabInWindow(browser->session_id(),
1403 browser->active_index())); 1398 browser->active_index()));
1404 } 1399 }
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 contents->GetController().GetDefaultSessionStorageNamespace(); 1776 contents->GetController().GetDefaultSessionStorageNamespace();
1782 session_storage_namespace->SetShouldPersist(false); 1777 session_storage_namespace->SetShouldPersist(false);
1783 SessionTabHelper* session_tab_helper = 1778 SessionTabHelper* session_tab_helper =
1784 SessionTabHelper::FromWebContents(contents); 1779 SessionTabHelper::FromWebContents(contents);
1785 TabClosed(session_tab_helper->window_id(), 1780 TabClosed(session_tab_helper->window_id(),
1786 session_tab_helper->session_id(), 1781 session_tab_helper->session_id(),
1787 contents->GetClosedByUserGesture()); 1782 contents->GetClosedByUserGesture());
1788 RecordSessionUpdateHistogramData(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 1783 RecordSessionUpdateHistogramData(content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1789 &last_updated_tab_closed_time_); 1784 &last_updated_tab_closed_time_);
1790 } 1785 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698