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 bool is_app) { |
325 if (!should_track_changes_for_browser_type(type, is_app)) | |
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 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
sky
2012/02/24 20:56:04
Can you add a comment that we can't use OPENED as
DaveMoore
2012/02/25 16:54:42
Done.
| |
474 content::NotificationService::AllBrowserContextsAndSources()); | 488 content::NotificationService::AllBrowserContextsAndSources()); |
475 registrar_.Add( | 489 registrar_.Add( |
476 this, chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 490 this, chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
477 content::NotificationService::AllSources()); | 491 content::NotificationService::AllSources()); |
478 } | 492 } |
479 | 493 |
480 bool SessionService::ShouldNewWindowStartSession() { | 494 bool SessionService::ShouldNewWindowStartSession() { |
481 if (!has_open_trackable_browsers_ && | 495 if (!has_open_trackable_browsers_ && |
482 !BrowserInit::InSynchronousProfileLaunch() && | 496 !BrowserInit::InSynchronousProfileLaunch() && |
483 !SessionRestore::IsRestoring(profile()) | 497 !SessionRestore::IsRestoring(profile()) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 } | 529 } |
516 } | 530 } |
517 return false; | 531 return false; |
518 } | 532 } |
519 | 533 |
520 void SessionService::Observe(int type, | 534 void SessionService::Observe(int type, |
521 const content::NotificationSource& source, | 535 const content::NotificationSource& source, |
522 const content::NotificationDetails& details) { | 536 const content::NotificationDetails& details) { |
523 // All of our messages have the NavigationController as the source. | 537 // All of our messages have the NavigationController as the source. |
524 switch (type) { | 538 switch (type) { |
525 case chrome::NOTIFICATION_BROWSER_OPENED: { | 539 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { |
526 Browser* browser = content::Source<Browser>(source).ptr(); | 540 Browser* browser = content::Source<Browser>(source).ptr(); |
527 if (browser->profile() != profile() || | 541 if (browser->profile() != profile() || |
528 !should_track_changes_for_browser_type(browser->type())) { | 542 !should_track_changes_for_browser_type(browser->type(), |
543 browser->is_app())) { | |
529 return; | 544 return; |
530 } | 545 } |
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(), browser->is_app()); |
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 if (window->tabs.empty() || window->is_constrained || | |
890 !should_track_changes_for_browser_type( | 907 !should_track_changes_for_browser_type( |
891 static_cast<Browser::Type>(i->second->type))) { | 908 static_cast<Browser::Type>(window->type), |
892 delete i->second; | 909 !window->app_name.empty())) { |
910 delete window; | |
893 windows->erase(i++); | 911 windows->erase(i++); |
894 } else { | 912 } else { |
895 // Valid window; sort the tabs and add it to the list of valid windows. | 913 // 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(), | 914 std::sort(window->tabs.begin(), window->tabs.end(), |
897 &TabVisualIndexSortFunction); | 915 &TabVisualIndexSortFunction); |
898 // Add the window such that older windows appear first. | 916 // Add the window such that older windows appear first. |
899 if (valid_windows->empty()) { | 917 if (valid_windows->empty()) { |
900 valid_windows->push_back(i->second); | 918 valid_windows->push_back(window); |
901 } else { | 919 } else { |
902 valid_windows->insert( | 920 valid_windows->insert( |
903 std::upper_bound(valid_windows->begin(), valid_windows->end(), | 921 std::upper_bound(valid_windows->begin(), valid_windows->end(), |
904 i->second, &WindowOrderSortFunction), | 922 window, &WindowOrderSortFunction), |
905 i->second); | 923 window); |
906 } | 924 } |
907 ++i; | 925 ++i; |
908 } | 926 } |
909 } | 927 } |
910 } | 928 } |
911 | 929 |
912 void SessionService::AddTabsToWindows(std::map<int, SessionTab*>* tabs, | 930 void SessionService::AddTabsToWindows(std::map<int, SessionTab*>* tabs, |
913 std::map<int, SessionWindow*>* windows) { | 931 std::map<int, SessionWindow*>* windows) { |
914 std::map<int, SessionTab*>::iterator i = tabs->begin(); | 932 std::map<int, SessionTab*>::iterator i = tabs->begin(); |
915 while (i != tabs->end()) { | 933 while (i != tabs->end()) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 } | 1117 } |
1100 | 1118 |
1101 case kCommandSetPinnedState: { | 1119 case kCommandSetPinnedState: { |
1102 PinnedStatePayload payload; | 1120 PinnedStatePayload payload; |
1103 if (!command->GetPayload(&payload, sizeof(payload))) | 1121 if (!command->GetPayload(&payload, sizeof(payload))) |
1104 return true; | 1122 return true; |
1105 GetTab(payload.tab_id, tabs)->pinned = payload.pinned_state; | 1123 GetTab(payload.tab_id, tabs)->pinned = payload.pinned_state; |
1106 break; | 1124 break; |
1107 } | 1125 } |
1108 | 1126 |
1127 case kCommandSetWindowAppName: { | |
1128 SessionID::id_type window_id; | |
1129 std::string app_name; | |
1130 if (!RestoreSetWindowAppNameCommand(*command, &window_id, &app_name)) | |
1131 return true; | |
1132 | |
1133 GetWindow(window_id, windows)->app_name.swap(app_name); | |
1134 break; | |
1135 } | |
1136 | |
1109 case kCommandSetExtensionAppID: { | 1137 case kCommandSetExtensionAppID: { |
1110 SessionID::id_type tab_id; | 1138 SessionID::id_type tab_id; |
1111 std::string extension_app_id; | 1139 std::string extension_app_id; |
1112 if (!RestoreSetTabExtensionAppIDCommand( | 1140 if (!RestoreSetTabExtensionAppIDCommand( |
1113 *command, &tab_id, &extension_app_id)) { | 1141 *command, &tab_id, &extension_app_id)) { |
1114 return true; | 1142 return true; |
1115 } | 1143 } |
1116 | 1144 |
1117 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); | 1145 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); |
1118 break; | 1146 break; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1194 show_state = ui::SHOW_STATE_MINIMIZED; | 1222 show_state = ui::SHOW_STATE_MINIMIZED; |
1195 | 1223 |
1196 commands->push_back( | 1224 commands->push_back( |
1197 CreateSetWindowBoundsCommand(browser->session_id(), | 1225 CreateSetWindowBoundsCommand(browser->session_id(), |
1198 browser->window()->GetRestoredBounds(), | 1226 browser->window()->GetRestoredBounds(), |
1199 show_state)); | 1227 show_state)); |
1200 | 1228 |
1201 commands->push_back(CreateSetWindowTypeCommand( | 1229 commands->push_back(CreateSetWindowTypeCommand( |
1202 browser->session_id(), WindowTypeForBrowserType(browser->type()))); | 1230 browser->session_id(), WindowTypeForBrowserType(browser->type()))); |
1203 | 1231 |
1232 if (!browser->app_name().empty()) { | |
1233 commands->push_back(CreateSetWindowAppNameCommand( | |
1234 kCommandSetWindowAppName, | |
1235 browser->session_id().id(), | |
1236 browser->app_name())); | |
1237 } | |
1238 | |
1204 bool added_to_windows_to_track = false; | 1239 bool added_to_windows_to_track = false; |
1205 for (int i = 0; i < browser->tab_count(); ++i) { | 1240 for (int i = 0; i < browser->tab_count(); ++i) { |
1206 TabContentsWrapper* tab = browser->GetTabContentsWrapperAt(i); | 1241 TabContentsWrapper* tab = browser->GetTabContentsWrapperAt(i); |
1207 DCHECK(tab); | 1242 DCHECK(tab); |
1208 if (tab->profile() == profile() || profile() == NULL) { | 1243 if (tab->profile() == profile() || profile() == NULL) { |
1209 BuildCommandsForTab(browser->session_id(), tab, i, | 1244 BuildCommandsForTab(browser->session_id(), tab, i, |
1210 browser->IsTabPinned(i), | 1245 browser->IsTabPinned(i), |
1211 commands, tab_to_available_range); | 1246 commands, tab_to_available_range); |
1212 if (windows_to_track && !added_to_windows_to_track) { | 1247 if (windows_to_track && !added_to_windows_to_track) { |
1213 windows_to_track->insert(browser->session_id().id()); | 1248 windows_to_track->insert(browser->session_id().id()); |
1214 added_to_windows_to_track = true; | 1249 added_to_windows_to_track = true; |
1215 } | 1250 } |
1216 } | 1251 } |
1217 } | 1252 } |
1218 commands->push_back( | 1253 commands->push_back( |
1219 CreateSetSelectedTabInWindow(browser->session_id(), | 1254 CreateSetSelectedTabInWindow(browser->session_id(), |
1220 browser->active_index())); | 1255 browser->active_index())); |
1221 } | 1256 } |
1222 | 1257 |
1223 void SessionService::BuildCommandsFromBrowsers( | 1258 void SessionService::BuildCommandsFromBrowsers( |
1224 std::vector<SessionCommand*>* commands, | 1259 std::vector<SessionCommand*>* commands, |
1225 IdToRange* tab_to_available_range, | 1260 IdToRange* tab_to_available_range, |
1226 std::set<SessionID::id_type>* windows_to_track) { | 1261 std::set<SessionID::id_type>* windows_to_track) { |
1227 DCHECK(commands); | 1262 DCHECK(commands); |
1228 for (BrowserList::const_iterator i = BrowserList::begin(); | 1263 for (BrowserList::const_iterator i = BrowserList::begin(); |
1229 i != BrowserList::end(); ++i) { | 1264 i != BrowserList::end(); ++i) { |
1265 Browser* browser = *i; | |
1230 // Make sure the browser has tabs and a window. Browsers destructor | 1266 // Make sure the browser has tabs and a window. Browsers destructor |
1231 // removes itself from the BrowserList. When a browser is closed the | 1267 // removes itself from the BrowserList. When a browser is closed the |
1232 // destructor is not necessarily run immediately. This means its possible | 1268 // 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 | 1269 // 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 | 1270 // the tab count is 0 or the window is NULL, the browser is about to be |
1235 // deleted, so we ignore it. | 1271 // deleted, so we ignore it. |
1236 if (should_track_changes_for_browser_type((*i)->type()) && | 1272 if (should_track_changes_for_browser_type(browser->type(), |
1237 (*i)->tab_count() && (*i)->window()) { | 1273 browser->is_app()) && |
1238 BuildCommandsForBrowser(*i, commands, tab_to_available_range, | 1274 browser->tab_count() && |
1275 browser->window()) { | |
1276 BuildCommandsForBrowser(browser, commands, tab_to_available_range, | |
1239 windows_to_track); | 1277 windows_to_track); |
1240 } | 1278 } |
1241 } | 1279 } |
1242 } | 1280 } |
1243 | 1281 |
1244 void SessionService::ScheduleReset() { | 1282 void SessionService::ScheduleReset() { |
1245 set_pending_reset(true); | 1283 set_pending_reset(true); |
1246 STLDeleteElements(&pending_commands()); | 1284 STLDeleteElements(&pending_commands()); |
1247 tab_to_available_range_.clear(); | 1285 tab_to_available_range_.clear(); |
1248 windows_tracking_.clear(); | 1286 windows_tracking_.clear(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1335 | 1373 |
1336 bool SessionService::IsOnlyOneTabLeft() { | 1374 bool SessionService::IsOnlyOneTabLeft() { |
1337 if (!profile()) { | 1375 if (!profile()) { |
1338 // We're testing, always return false. | 1376 // We're testing, always return false. |
1339 return false; | 1377 return false; |
1340 } | 1378 } |
1341 | 1379 |
1342 int window_count = 0; | 1380 int window_count = 0; |
1343 for (BrowserList::const_iterator i = BrowserList::begin(); | 1381 for (BrowserList::const_iterator i = BrowserList::begin(); |
1344 i != BrowserList::end(); ++i) { | 1382 i != BrowserList::end(); ++i) { |
1345 const SessionID::id_type window_id = (*i)->session_id().id(); | 1383 Browser* browser = *i; |
sky
2012/02/24 20:56:04
nit: " " -> " "
DaveMoore
2012/02/25 16:54:42
Done.
| |
1346 if (should_track_changes_for_browser_type((*i)->type()) && | 1384 const SessionID::id_type window_id = browser->session_id().id(); |
1347 (*i)->profile() == profile() && | 1385 if (should_track_changes_for_browser_type(browser->type(), |
1386 browser->is_app()) && | |
1387 browser->profile() == profile() && | |
1348 window_closing_ids_.find(window_id) == window_closing_ids_.end()) { | 1388 window_closing_ids_.find(window_id) == window_closing_ids_.end()) { |
1349 if (++window_count > 1) | 1389 if (++window_count > 1) |
1350 return false; | 1390 return false; |
1351 // By the time this is invoked the tab has been removed. As such, we use | 1391 // By the time this is invoked the tab has been removed. As such, we use |
1352 // > 0 here rather than > 1. | 1392 // > 0 here rather than > 1. |
1353 if ((*i)->tab_count() > 0) | 1393 if ((*i)->tab_count() > 0) |
1354 return false; | 1394 return false; |
1355 } | 1395 } |
1356 } | 1396 } |
1357 return true; | 1397 return true; |
1358 } | 1398 } |
1359 | 1399 |
1360 bool SessionService::HasOpenTrackableBrowsers(const SessionID& window_id) { | 1400 bool SessionService::HasOpenTrackableBrowsers(const SessionID& window_id) { |
1361 if (!profile()) { | 1401 if (!profile()) { |
1362 // We're testing, always return false. | 1402 // We're testing, always return false. |
1363 return true; | 1403 return true; |
1364 } | 1404 } |
1365 | 1405 |
1366 for (BrowserList::const_iterator i = BrowserList::begin(); | 1406 for (BrowserList::const_iterator i = BrowserList::begin(); |
1367 i != BrowserList::end(); ++i) { | 1407 i != BrowserList::end(); ++i) { |
1368 Browser* browser = *i; | 1408 Browser* browser = *i; |
1369 const SessionID::id_type browser_id = browser->session_id().id(); | 1409 const SessionID::id_type browser_id = browser->session_id().id(); |
1370 if (browser_id != window_id.id() && | 1410 if (browser_id != window_id.id() && |
1371 window_closing_ids_.find(browser_id) == window_closing_ids_.end() && | 1411 window_closing_ids_.find(browser_id) == window_closing_ids_.end() && |
1372 should_track_changes_for_browser_type(browser->type()) && | 1412 should_track_changes_for_browser_type(browser->type(), |
1413 browser->is_app()) && | |
1373 browser->profile() == profile()) { | 1414 browser->profile() == profile()) { |
1374 return true; | 1415 return true; |
1375 } | 1416 } |
1376 } | 1417 } |
1377 return false; | 1418 return false; |
1378 } | 1419 } |
1379 | 1420 |
1380 bool SessionService::ShouldTrackChangesToWindow(const SessionID& window_id) { | 1421 bool SessionService::ShouldTrackChangesToWindow(const SessionID& window_id) { |
1381 return windows_tracking_.find(window_id.id()) != windows_tracking_.end(); | 1422 return windows_tracking_.find(window_id.id()) != windows_tracking_.end(); |
1382 } | 1423 } |
1383 | 1424 |
1384 | 1425 |
1385 bool SessionService::should_track_changes_for_browser_type(Browser::Type type) { | 1426 bool SessionService::should_track_changes_for_browser_type(Browser::Type type, |
1427 bool is_app) { | |
1428 #if defined(USE_AURA) | |
1429 // Restore app popups for aura alone. | |
1430 if (type == Browser::TYPE_POPUP && is_app) | |
1431 return true; | |
1432 #endif | |
1433 | |
1386 return type == Browser::TYPE_TABBED || | 1434 return type == Browser::TYPE_TABBED || |
1387 (type == Browser::TYPE_POPUP && browser_defaults::kRestorePopups); | 1435 (type == Browser::TYPE_POPUP && browser_defaults::kRestorePopups); |
1388 } | 1436 } |
1389 | 1437 |
1390 SessionService::WindowType SessionService::WindowTypeForBrowserType( | 1438 SessionService::WindowType SessionService::WindowTypeForBrowserType( |
1391 Browser::Type type) { | 1439 Browser::Type type) { |
1392 switch (type) { | 1440 switch (type) { |
1393 case Browser::TYPE_POPUP: | 1441 case Browser::TYPE_POPUP: |
1394 return TYPE_POPUP; | 1442 return TYPE_POPUP; |
1395 case Browser::TYPE_TABBED: | 1443 case Browser::TYPE_TABBED: |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1532 50); | 1580 50); |
1533 if (use_long_period) { | 1581 if (use_long_period) { |
1534 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1582 std::string long_name_("SessionRestore.SaveLongPeriod"); |
1535 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1583 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
1536 delta, | 1584 delta, |
1537 save_delay_in_mins_, | 1585 save_delay_in_mins_, |
1538 save_delay_in_hrs_, | 1586 save_delay_in_hrs_, |
1539 50); | 1587 50); |
1540 } | 1588 } |
1541 } | 1589 } |
OLD | NEW |