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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = 7; | 59 static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = 7; |
60 static const SessionCommand::id_type kCommandSetSelectedTabInIndex = 8; | 60 static const SessionCommand::id_type kCommandSetSelectedTabInIndex = 8; |
61 static const SessionCommand::id_type kCommandSetWindowType = 9; | 61 static const SessionCommand::id_type kCommandSetWindowType = 9; |
62 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. | 62 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. |
63 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; | 63 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; |
64 static const SessionCommand::id_type | 64 static const SessionCommand::id_type |
65 kCommandTabNavigationPathPrunedFromFront = 11; | 65 kCommandTabNavigationPathPrunedFromFront = 11; |
66 static const SessionCommand::id_type kCommandSetPinnedState = 12; | 66 static const SessionCommand::id_type kCommandSetPinnedState = 12; |
67 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; | 67 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; |
68 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; | 68 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; |
| 69 static const SessionCommand::id_type kCommandSetWindowAppName = 15; |
69 | 70 |
70 // Every kWritesPerReset commands triggers recreating the file. | 71 // Every kWritesPerReset commands triggers recreating the file. |
71 static const int kWritesPerReset = 250; | 72 static const int kWritesPerReset = 250; |
72 | 73 |
73 namespace { | 74 namespace { |
74 | 75 |
75 // The callback from GetLastSession is internally routed to SessionService | 76 // The callback from GetLastSession is internally routed to SessionService |
76 // first and then the caller. This is done so that the SessionWindows can be | 77 // first and then the caller. This is done so that the SessionWindows can be |
77 // recreated from the SessionCommands and the SessionWindows passed to the | 78 // recreated from the SessionCommands and the SessionWindows passed to the |
78 // caller. The following class is used for this. | 79 // caller. The following class is used for this. |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // We'll hit this if user closed the last tab in a window. | 313 // We'll hit this if user closed the last tab in a window. |
313 has_open_trackable_browsers_ = HasOpenTrackableBrowsers(window_id); | 314 has_open_trackable_browsers_ = HasOpenTrackableBrowsers(window_id); |
314 if (should_record_close_as_pending()) | 315 if (should_record_close_as_pending()) |
315 pending_window_close_ids_.insert(window_id.id()); | 316 pending_window_close_ids_.insert(window_id.id()); |
316 else | 317 else |
317 ScheduleCommand(CreateWindowClosedCommand(window_id.id())); | 318 ScheduleCommand(CreateWindowClosedCommand(window_id.id())); |
318 } | 319 } |
319 } | 320 } |
320 | 321 |
321 void SessionService::SetWindowType(const SessionID& window_id, | 322 void SessionService::SetWindowType(const SessionID& window_id, |
322 Browser::Type type) { | 323 Browser::Type type, |
323 if (!should_track_changes_for_browser_type(type)) | 324 AppType app_type) { |
| 325 if (!should_track_changes_for_browser_type(type, app_type)) |
324 return; | 326 return; |
325 | 327 |
326 windows_tracking_.insert(window_id.id()); | 328 windows_tracking_.insert(window_id.id()); |
327 | 329 |
328 // The user created a new tabbed browser with our profile. Commit any | 330 // The user created a new tabbed browser with our profile. Commit any |
329 // pending closes. | 331 // pending closes. |
330 CommitPendingCloses(); | 332 CommitPendingCloses(); |
331 | 333 |
332 has_open_trackable_browsers_ = true; | 334 has_open_trackable_browsers_ = true; |
333 move_on_new_browser_ = true; | 335 move_on_new_browser_ = true; |
334 | 336 |
335 ScheduleCommand( | 337 ScheduleCommand( |
336 CreateSetWindowTypeCommand(window_id, WindowTypeForBrowserType(type))); | 338 CreateSetWindowTypeCommand(window_id, WindowTypeForBrowserType(type))); |
337 } | 339 } |
338 | 340 |
| 341 void SessionService::SetWindowAppName( |
| 342 const SessionID& window_id, |
| 343 const std::string& app_name) { |
| 344 if (!ShouldTrackChangesToWindow(window_id)) |
| 345 return; |
| 346 |
| 347 ScheduleCommand(CreateSetTabExtensionAppIDCommand( |
| 348 kCommandSetWindowAppName, |
| 349 window_id.id(), |
| 350 app_name)); |
| 351 } |
| 352 |
339 void SessionService::TabNavigationPathPrunedFromBack(const SessionID& window_id, | 353 void SessionService::TabNavigationPathPrunedFromBack(const SessionID& window_id, |
340 const SessionID& tab_id, | 354 const SessionID& tab_id, |
341 int count) { | 355 int count) { |
342 if (!ShouldTrackChangesToWindow(window_id)) | 356 if (!ShouldTrackChangesToWindow(window_id)) |
343 return; | 357 return; |
344 | 358 |
345 TabNavigationPathPrunedFromBackPayload payload = { 0 }; | 359 TabNavigationPathPrunedFromBackPayload payload = { 0 }; |
346 payload.id = tab_id.id(); | 360 payload.id = tab_id.id(); |
347 payload.index = count; | 361 payload.index = count; |
348 SessionCommand* command = | 362 SessionCommand* command = |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED, | 477 registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED, |
464 content::NotificationService::AllSources()); | 478 content::NotificationService::AllSources()); |
465 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, | 479 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
466 content::NotificationService::AllSources()); | 480 content::NotificationService::AllSources()); |
467 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, | 481 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, |
468 content::NotificationService::AllSources()); | 482 content::NotificationService::AllSources()); |
469 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, | 483 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, |
470 content::NotificationService::AllSources()); | 484 content::NotificationService::AllSources()); |
471 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 485 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
472 content::NotificationService::AllSources()); | 486 content::NotificationService::AllSources()); |
473 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 487 // Wait for NOTIFICATION_BROWSER_WINDOW_READY so that is_app() is set. |
| 488 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
474 content::NotificationService::AllBrowserContextsAndSources()); | 489 content::NotificationService::AllBrowserContextsAndSources()); |
475 registrar_.Add( | 490 registrar_.Add( |
476 this, chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 491 this, chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
477 content::NotificationService::AllSources()); | 492 content::NotificationService::AllSources()); |
478 } | 493 } |
479 | 494 |
480 bool SessionService::ShouldNewWindowStartSession() { | 495 bool SessionService::ShouldNewWindowStartSession() { |
481 if (!has_open_trackable_browsers_ && | 496 if (!has_open_trackable_browsers_ && |
482 !BrowserInit::InSynchronousProfileLaunch() && | 497 !BrowserInit::InSynchronousProfileLaunch() && |
483 !SessionRestore::IsRestoring(profile()) | 498 !SessionRestore::IsRestoring(profile()) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 } | 530 } |
516 } | 531 } |
517 return false; | 532 return false; |
518 } | 533 } |
519 | 534 |
520 void SessionService::Observe(int type, | 535 void SessionService::Observe(int type, |
521 const content::NotificationSource& source, | 536 const content::NotificationSource& source, |
522 const content::NotificationDetails& details) { | 537 const content::NotificationDetails& details) { |
523 // All of our messages have the NavigationController as the source. | 538 // All of our messages have the NavigationController as the source. |
524 switch (type) { | 539 switch (type) { |
525 case chrome::NOTIFICATION_BROWSER_OPENED: { | 540 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { |
526 Browser* browser = content::Source<Browser>(source).ptr(); | 541 Browser* browser = content::Source<Browser>(source).ptr(); |
| 542 AppType app_type = browser->is_app() ? TYPE_APP : TYPE_NORMAL; |
527 if (browser->profile() != profile() || | 543 if (browser->profile() != profile() || |
528 !should_track_changes_for_browser_type(browser->type())) { | 544 !should_track_changes_for_browser_type(browser->type(), app_type)) |
529 return; | 545 return; |
530 } | |
531 | 546 |
532 RestoreIfNecessary(std::vector<GURL>(), browser); | 547 RestoreIfNecessary(std::vector<GURL>(), browser); |
533 SetWindowType(browser->session_id(), browser->type()); | 548 SetWindowType(browser->session_id(), browser->type(), app_type); |
| 549 SetWindowAppName(browser->session_id(), browser->app_name()); |
534 break; | 550 break; |
535 } | 551 } |
536 | 552 |
537 case content::NOTIFICATION_TAB_PARENTED: { | 553 case content::NOTIFICATION_TAB_PARENTED: { |
538 TabContentsWrapper* tab = | 554 TabContentsWrapper* tab = |
539 content::Source<TabContentsWrapper>(source).ptr(); | 555 content::Source<TabContentsWrapper>(source).ptr(); |
540 if (tab->profile() != profile()) | 556 if (tab->profile() != profile()) |
541 return; | 557 return; |
542 SetTabWindow(tab->restore_tab_helper()->window_id(), | 558 SetTabWindow(tab->restore_tab_helper()->window_id(), |
543 tab->restore_tab_helper()->session_id()); | 559 tab->restore_tab_helper()->session_id()); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 const SessionTab* t2) { | 895 const SessionTab* t2) { |
880 const int delta = t1->tab_visual_index - t2->tab_visual_index; | 896 const int delta = t1->tab_visual_index - t2->tab_visual_index; |
881 return delta == 0 ? (t1->tab_id.id() < t2->tab_id.id()) : (delta < 0); | 897 return delta == 0 ? (t1->tab_id.id() < t2->tab_id.id()) : (delta < 0); |
882 } | 898 } |
883 | 899 |
884 void SessionService::SortTabsBasedOnVisualOrderAndPrune( | 900 void SessionService::SortTabsBasedOnVisualOrderAndPrune( |
885 std::map<int, SessionWindow*>* windows, | 901 std::map<int, SessionWindow*>* windows, |
886 std::vector<SessionWindow*>* valid_windows) { | 902 std::vector<SessionWindow*>* valid_windows) { |
887 std::map<int, SessionWindow*>::iterator i = windows->begin(); | 903 std::map<int, SessionWindow*>::iterator i = windows->begin(); |
888 while (i != windows->end()) { | 904 while (i != windows->end()) { |
889 if (i->second->tabs.empty() || i->second->is_constrained || | 905 SessionWindow* window = i->second; |
| 906 AppType app_type = window->app_name.empty() ? TYPE_NORMAL : TYPE_APP; |
| 907 if (window->tabs.empty() || window->is_constrained || |
890 !should_track_changes_for_browser_type( | 908 !should_track_changes_for_browser_type( |
891 static_cast<Browser::Type>(i->second->type))) { | 909 static_cast<Browser::Type>(window->type), |
892 delete i->second; | 910 app_type)) { |
| 911 delete window; |
893 windows->erase(i++); | 912 windows->erase(i++); |
894 } else { | 913 } else { |
895 // Valid window; sort the tabs and add it to the list of valid windows. | 914 // Valid window; sort the tabs and add it to the list of valid windows. |
896 std::sort(i->second->tabs.begin(), i->second->tabs.end(), | 915 std::sort(window->tabs.begin(), window->tabs.end(), |
897 &TabVisualIndexSortFunction); | 916 &TabVisualIndexSortFunction); |
898 // Add the window such that older windows appear first. | 917 // Add the window such that older windows appear first. |
899 if (valid_windows->empty()) { | 918 if (valid_windows->empty()) { |
900 valid_windows->push_back(i->second); | 919 valid_windows->push_back(window); |
901 } else { | 920 } else { |
902 valid_windows->insert( | 921 valid_windows->insert( |
903 std::upper_bound(valid_windows->begin(), valid_windows->end(), | 922 std::upper_bound(valid_windows->begin(), valid_windows->end(), |
904 i->second, &WindowOrderSortFunction), | 923 window, &WindowOrderSortFunction), |
905 i->second); | 924 window); |
906 } | 925 } |
907 ++i; | 926 ++i; |
908 } | 927 } |
909 } | 928 } |
910 } | 929 } |
911 | 930 |
912 void SessionService::AddTabsToWindows(std::map<int, SessionTab*>* tabs, | 931 void SessionService::AddTabsToWindows(std::map<int, SessionTab*>* tabs, |
913 std::map<int, SessionWindow*>* windows) { | 932 std::map<int, SessionWindow*>* windows) { |
914 std::map<int, SessionTab*>::iterator i = tabs->begin(); | 933 std::map<int, SessionTab*>::iterator i = tabs->begin(); |
915 while (i != tabs->end()) { | 934 while (i != tabs->end()) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 } | 1118 } |
1100 | 1119 |
1101 case kCommandSetPinnedState: { | 1120 case kCommandSetPinnedState: { |
1102 PinnedStatePayload payload; | 1121 PinnedStatePayload payload; |
1103 if (!command->GetPayload(&payload, sizeof(payload))) | 1122 if (!command->GetPayload(&payload, sizeof(payload))) |
1104 return true; | 1123 return true; |
1105 GetTab(payload.tab_id, tabs)->pinned = payload.pinned_state; | 1124 GetTab(payload.tab_id, tabs)->pinned = payload.pinned_state; |
1106 break; | 1125 break; |
1107 } | 1126 } |
1108 | 1127 |
| 1128 case kCommandSetWindowAppName: { |
| 1129 SessionID::id_type window_id; |
| 1130 std::string app_name; |
| 1131 if (!RestoreSetWindowAppNameCommand(*command, &window_id, &app_name)) |
| 1132 return true; |
| 1133 |
| 1134 GetWindow(window_id, windows)->app_name.swap(app_name); |
| 1135 break; |
| 1136 } |
| 1137 |
1109 case kCommandSetExtensionAppID: { | 1138 case kCommandSetExtensionAppID: { |
1110 SessionID::id_type tab_id; | 1139 SessionID::id_type tab_id; |
1111 std::string extension_app_id; | 1140 std::string extension_app_id; |
1112 if (!RestoreSetTabExtensionAppIDCommand( | 1141 if (!RestoreSetTabExtensionAppIDCommand( |
1113 *command, &tab_id, &extension_app_id)) { | 1142 *command, &tab_id, &extension_app_id)) { |
1114 return true; | 1143 return true; |
1115 } | 1144 } |
1116 | 1145 |
1117 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); | 1146 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); |
1118 break; | 1147 break; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 show_state = ui::SHOW_STATE_MINIMIZED; | 1223 show_state = ui::SHOW_STATE_MINIMIZED; |
1195 | 1224 |
1196 commands->push_back( | 1225 commands->push_back( |
1197 CreateSetWindowBoundsCommand(browser->session_id(), | 1226 CreateSetWindowBoundsCommand(browser->session_id(), |
1198 browser->window()->GetRestoredBounds(), | 1227 browser->window()->GetRestoredBounds(), |
1199 show_state)); | 1228 show_state)); |
1200 | 1229 |
1201 commands->push_back(CreateSetWindowTypeCommand( | 1230 commands->push_back(CreateSetWindowTypeCommand( |
1202 browser->session_id(), WindowTypeForBrowserType(browser->type()))); | 1231 browser->session_id(), WindowTypeForBrowserType(browser->type()))); |
1203 | 1232 |
| 1233 if (!browser->app_name().empty()) { |
| 1234 commands->push_back(CreateSetWindowAppNameCommand( |
| 1235 kCommandSetWindowAppName, |
| 1236 browser->session_id().id(), |
| 1237 browser->app_name())); |
| 1238 } |
| 1239 |
1204 bool added_to_windows_to_track = false; | 1240 bool added_to_windows_to_track = false; |
1205 for (int i = 0; i < browser->tab_count(); ++i) { | 1241 for (int i = 0; i < browser->tab_count(); ++i) { |
1206 TabContentsWrapper* tab = browser->GetTabContentsWrapperAt(i); | 1242 TabContentsWrapper* tab = browser->GetTabContentsWrapperAt(i); |
1207 DCHECK(tab); | 1243 DCHECK(tab); |
1208 if (tab->profile() == profile() || profile() == NULL) { | 1244 if (tab->profile() == profile() || profile() == NULL) { |
1209 BuildCommandsForTab(browser->session_id(), tab, i, | 1245 BuildCommandsForTab(browser->session_id(), tab, i, |
1210 browser->IsTabPinned(i), | 1246 browser->IsTabPinned(i), |
1211 commands, tab_to_available_range); | 1247 commands, tab_to_available_range); |
1212 if (windows_to_track && !added_to_windows_to_track) { | 1248 if (windows_to_track && !added_to_windows_to_track) { |
1213 windows_to_track->insert(browser->session_id().id()); | 1249 windows_to_track->insert(browser->session_id().id()); |
1214 added_to_windows_to_track = true; | 1250 added_to_windows_to_track = true; |
1215 } | 1251 } |
1216 } | 1252 } |
1217 } | 1253 } |
1218 commands->push_back( | 1254 commands->push_back( |
1219 CreateSetSelectedTabInWindow(browser->session_id(), | 1255 CreateSetSelectedTabInWindow(browser->session_id(), |
1220 browser->active_index())); | 1256 browser->active_index())); |
1221 } | 1257 } |
1222 | 1258 |
1223 void SessionService::BuildCommandsFromBrowsers( | 1259 void SessionService::BuildCommandsFromBrowsers( |
1224 std::vector<SessionCommand*>* commands, | 1260 std::vector<SessionCommand*>* commands, |
1225 IdToRange* tab_to_available_range, | 1261 IdToRange* tab_to_available_range, |
1226 std::set<SessionID::id_type>* windows_to_track) { | 1262 std::set<SessionID::id_type>* windows_to_track) { |
1227 DCHECK(commands); | 1263 DCHECK(commands); |
1228 for (BrowserList::const_iterator i = BrowserList::begin(); | 1264 for (BrowserList::const_iterator i = BrowserList::begin(); |
1229 i != BrowserList::end(); ++i) { | 1265 i != BrowserList::end(); ++i) { |
| 1266 Browser* browser = *i; |
1230 // Make sure the browser has tabs and a window. Browsers destructor | 1267 // Make sure the browser has tabs and a window. Browsers destructor |
1231 // removes itself from the BrowserList. When a browser is closed the | 1268 // removes itself from the BrowserList. When a browser is closed the |
1232 // destructor is not necessarily run immediately. This means its possible | 1269 // destructor is not necessarily run immediately. This means its possible |
1233 // for us to get a handle to a browser that is about to be removed. If | 1270 // for us to get a handle to a browser that is about to be removed. If |
1234 // the tab count is 0 or the window is NULL, the browser is about to be | 1271 // the tab count is 0 or the window is NULL, the browser is about to be |
1235 // deleted, so we ignore it. | 1272 // deleted, so we ignore it. |
1236 if (should_track_changes_for_browser_type((*i)->type()) && | 1273 AppType app_type = browser->is_app() ? TYPE_APP : TYPE_NORMAL; |
1237 (*i)->tab_count() && (*i)->window()) { | 1274 if (should_track_changes_for_browser_type(browser->type(), app_type) && |
1238 BuildCommandsForBrowser(*i, commands, tab_to_available_range, | 1275 browser->tab_count() && |
| 1276 browser->window()) { |
| 1277 BuildCommandsForBrowser(browser, commands, tab_to_available_range, |
1239 windows_to_track); | 1278 windows_to_track); |
1240 } | 1279 } |
1241 } | 1280 } |
1242 } | 1281 } |
1243 | 1282 |
1244 void SessionService::ScheduleReset() { | 1283 void SessionService::ScheduleReset() { |
1245 set_pending_reset(true); | 1284 set_pending_reset(true); |
1246 STLDeleteElements(&pending_commands()); | 1285 STLDeleteElements(&pending_commands()); |
1247 tab_to_available_range_.clear(); | 1286 tab_to_available_range_.clear(); |
1248 windows_tracking_.clear(); | 1287 windows_tracking_.clear(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 | 1374 |
1336 bool SessionService::IsOnlyOneTabLeft() { | 1375 bool SessionService::IsOnlyOneTabLeft() { |
1337 if (!profile()) { | 1376 if (!profile()) { |
1338 // We're testing, always return false. | 1377 // We're testing, always return false. |
1339 return false; | 1378 return false; |
1340 } | 1379 } |
1341 | 1380 |
1342 int window_count = 0; | 1381 int window_count = 0; |
1343 for (BrowserList::const_iterator i = BrowserList::begin(); | 1382 for (BrowserList::const_iterator i = BrowserList::begin(); |
1344 i != BrowserList::end(); ++i) { | 1383 i != BrowserList::end(); ++i) { |
1345 const SessionID::id_type window_id = (*i)->session_id().id(); | 1384 Browser* browser = *i; |
1346 if (should_track_changes_for_browser_type((*i)->type()) && | 1385 const SessionID::id_type window_id = browser->session_id().id(); |
1347 (*i)->profile() == profile() && | 1386 AppType app_type = browser->is_app() ? TYPE_APP : TYPE_NORMAL; |
| 1387 if (should_track_changes_for_browser_type(browser->type(), app_type) && |
| 1388 browser->profile() == profile() && |
1348 window_closing_ids_.find(window_id) == window_closing_ids_.end()) { | 1389 window_closing_ids_.find(window_id) == window_closing_ids_.end()) { |
1349 if (++window_count > 1) | 1390 if (++window_count > 1) |
1350 return false; | 1391 return false; |
1351 // By the time this is invoked the tab has been removed. As such, we use | 1392 // By the time this is invoked the tab has been removed. As such, we use |
1352 // > 0 here rather than > 1. | 1393 // > 0 here rather than > 1. |
1353 if ((*i)->tab_count() > 0) | 1394 if ((*i)->tab_count() > 0) |
1354 return false; | 1395 return false; |
1355 } | 1396 } |
1356 } | 1397 } |
1357 return true; | 1398 return true; |
1358 } | 1399 } |
1359 | 1400 |
1360 bool SessionService::HasOpenTrackableBrowsers(const SessionID& window_id) { | 1401 bool SessionService::HasOpenTrackableBrowsers(const SessionID& window_id) { |
1361 if (!profile()) { | 1402 if (!profile()) { |
1362 // We're testing, always return false. | 1403 // We're testing, always return false. |
1363 return true; | 1404 return true; |
1364 } | 1405 } |
1365 | 1406 |
1366 for (BrowserList::const_iterator i = BrowserList::begin(); | 1407 for (BrowserList::const_iterator i = BrowserList::begin(); |
1367 i != BrowserList::end(); ++i) { | 1408 i != BrowserList::end(); ++i) { |
1368 Browser* browser = *i; | 1409 Browser* browser = *i; |
1369 const SessionID::id_type browser_id = browser->session_id().id(); | 1410 const SessionID::id_type browser_id = browser->session_id().id(); |
| 1411 AppType app_type = browser->is_app() ? TYPE_APP : TYPE_NORMAL; |
1370 if (browser_id != window_id.id() && | 1412 if (browser_id != window_id.id() && |
1371 window_closing_ids_.find(browser_id) == window_closing_ids_.end() && | 1413 window_closing_ids_.find(browser_id) == window_closing_ids_.end() && |
1372 should_track_changes_for_browser_type(browser->type()) && | 1414 should_track_changes_for_browser_type(browser->type(), app_type) && |
1373 browser->profile() == profile()) { | 1415 browser->profile() == profile()) { |
1374 return true; | 1416 return true; |
1375 } | 1417 } |
1376 } | 1418 } |
1377 return false; | 1419 return false; |
1378 } | 1420 } |
1379 | 1421 |
1380 bool SessionService::ShouldTrackChangesToWindow(const SessionID& window_id) { | 1422 bool SessionService::ShouldTrackChangesToWindow(const SessionID& window_id) { |
1381 return windows_tracking_.find(window_id.id()) != windows_tracking_.end(); | 1423 return windows_tracking_.find(window_id.id()) != windows_tracking_.end(); |
1382 } | 1424 } |
1383 | 1425 |
1384 | 1426 |
1385 bool SessionService::should_track_changes_for_browser_type(Browser::Type type) { | 1427 bool SessionService::should_track_changes_for_browser_type(Browser::Type type, |
| 1428 AppType app_type) { |
| 1429 #if defined(USE_AURA) |
| 1430 // Restore app popups for aura alone. |
| 1431 if (type == Browser::TYPE_POPUP && app_type == TYPE_APP) |
| 1432 return true; |
| 1433 #endif |
| 1434 |
1386 return type == Browser::TYPE_TABBED || | 1435 return type == Browser::TYPE_TABBED || |
1387 (type == Browser::TYPE_POPUP && browser_defaults::kRestorePopups); | 1436 (type == Browser::TYPE_POPUP && browser_defaults::kRestorePopups); |
1388 } | 1437 } |
1389 | 1438 |
1390 SessionService::WindowType SessionService::WindowTypeForBrowserType( | 1439 SessionService::WindowType SessionService::WindowTypeForBrowserType( |
1391 Browser::Type type) { | 1440 Browser::Type type) { |
1392 switch (type) { | 1441 switch (type) { |
1393 case Browser::TYPE_POPUP: | 1442 case Browser::TYPE_POPUP: |
1394 return TYPE_POPUP; | 1443 return TYPE_POPUP; |
1395 case Browser::TYPE_TABBED: | 1444 case Browser::TYPE_TABBED: |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 50); | 1581 50); |
1533 if (use_long_period) { | 1582 if (use_long_period) { |
1534 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1583 std::string long_name_("SessionRestore.SaveLongPeriod"); |
1535 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1584 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
1536 delta, | 1585 delta, |
1537 save_delay_in_mins_, | 1586 save_delay_in_mins_, |
1538 save_delay_in_hrs_, | 1587 save_delay_in_hrs_, |
1539 50); | 1588 50); |
1540 } | 1589 } |
1541 } | 1590 } |
OLD | NEW |