OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "chrome/browser/sessions/session_command.h" | 25 #include "chrome/browser/sessions/session_command.h" |
26 #include "chrome/browser/sessions/session_restore.h" | 26 #include "chrome/browser/sessions/session_restore.h" |
27 #include "chrome/browser/sessions/session_types.h" | 27 #include "chrome/browser/sessions/session_types.h" |
28 #include "chrome/browser/tabs/tab_strip_model.h" | 28 #include "chrome/browser/tabs/tab_strip_model.h" |
29 #include "chrome/browser/ui/browser_init.h" | 29 #include "chrome/browser/ui/browser_init.h" |
30 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
31 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
33 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
34 #include "chrome/common/extensions/extension.h" | 34 #include "chrome/common/extensions/extension.h" |
35 #include "content/browser/in_process_webkit/dom_storage_namespace.h" | |
36 #include "content/browser/in_process_webkit/session_storage_namespace.h" | |
35 #include "content/browser/tab_contents/navigation_details.h" | 37 #include "content/browser/tab_contents/navigation_details.h" |
36 #include "content/browser/tab_contents/navigation_entry.h" | 38 #include "content/browser/tab_contents/navigation_entry.h" |
37 #include "content/browser/tab_contents/tab_contents.h" | 39 #include "content/browser/tab_contents/tab_contents.h" |
38 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
39 #include "content/public/browser/notification_details.h" | 41 #include "content/public/browser/notification_details.h" |
40 | 42 |
41 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
42 #include "chrome/browser/app_controller_cppsafe_mac.h" | 44 #include "chrome/browser/app_controller_cppsafe_mac.h" |
43 #endif | 45 #endif |
44 | 46 |
(...skipping 12 matching lines...) Expand all Loading... | |
57 static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = 7; | 59 static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = 7; |
58 static const SessionCommand::id_type kCommandSetSelectedTabInIndex = 8; | 60 static const SessionCommand::id_type kCommandSetSelectedTabInIndex = 8; |
59 static const SessionCommand::id_type kCommandSetWindowType = 9; | 61 static const SessionCommand::id_type kCommandSetWindowType = 9; |
60 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. | 62 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. |
61 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; | 63 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; |
62 static const SessionCommand::id_type | 64 static const SessionCommand::id_type |
63 kCommandTabNavigationPathPrunedFromFront = 11; | 65 kCommandTabNavigationPathPrunedFromFront = 11; |
64 static const SessionCommand::id_type kCommandSetPinnedState = 12; | 66 static const SessionCommand::id_type kCommandSetPinnedState = 12; |
65 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; | 67 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; |
66 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; | 68 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; |
69 static const SessionCommand::id_type kCommandSessionStorageCreated = 15; | |
67 | 70 |
68 // Every kWritesPerReset commands triggers recreating the file. | 71 // Every kWritesPerReset commands triggers recreating the file. |
69 static const int kWritesPerReset = 250; | 72 static const int kWritesPerReset = 250; |
70 | 73 |
71 namespace { | 74 namespace { |
72 | 75 |
73 // The callback from GetLastSession is internally routed to SessionService | 76 // The callback from GetLastSession is internally routed to SessionService |
74 // 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 |
75 // recreated from the SessionCommands and the SessionWindows passed to the | 78 // recreated from the SessionCommands and the SessionWindows passed to the |
76 // caller. The following class is used for this. | 79 // caller. The following class is used for this. |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 content::NotificationService::AllSources()); | 451 content::NotificationService::AllSources()); |
449 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, | 452 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, |
450 content::NotificationService::AllSources()); | 453 content::NotificationService::AllSources()); |
451 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 454 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
452 content::NotificationService::AllSources()); | 455 content::NotificationService::AllSources()); |
453 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 456 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
454 content::NotificationService::AllBrowserContextsAndSources()); | 457 content::NotificationService::AllBrowserContextsAndSources()); |
455 registrar_.Add( | 458 registrar_.Add( |
456 this, chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 459 this, chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
457 content::NotificationService::AllSources()); | 460 content::NotificationService::AllSources()); |
461 registrar_.Add(this, content::NOTIFICATION_DOM_STORAGE_NAMESPACE_CREATED, | |
462 content::NotificationService::AllSources()); | |
458 } | 463 } |
459 | 464 |
460 bool SessionService::ShouldNewWindowStartSession() { | 465 bool SessionService::ShouldNewWindowStartSession() { |
461 if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup() && | 466 if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup() && |
462 !SessionRestore::IsRestoring() | 467 !SessionRestore::IsRestoring() |
463 #if defined(OS_MACOSX) | 468 #if defined(OS_MACOSX) |
464 // OSX has a fairly different idea of application lifetime than the | 469 // OSX has a fairly different idea of application lifetime than the |
465 // other platforms. We need to check that we aren't opening a window | 470 // other platforms. We need to check that we aren't opening a window |
466 // from the dock or the menubar. | 471 // from the dock or the menubar. |
467 && !app_controller_mac::IsOpeningNewWindow() | 472 && !app_controller_mac::IsOpeningNewWindow() |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 RestoreIfNecessary(std::vector<GURL>(), browser); | 515 RestoreIfNecessary(std::vector<GURL>(), browser); |
511 SetWindowType(browser->session_id(), browser->type()); | 516 SetWindowType(browser->session_id(), browser->type()); |
512 break; | 517 break; |
513 } | 518 } |
514 | 519 |
515 case content::NOTIFICATION_TAB_PARENTED: { | 520 case content::NOTIFICATION_TAB_PARENTED: { |
516 TabContentsWrapper* tab = | 521 TabContentsWrapper* tab = |
517 content::Source<TabContentsWrapper>(source).ptr(); | 522 content::Source<TabContentsWrapper>(source).ptr(); |
518 if (tab->profile() != profile()) | 523 if (tab->profile() != profile()) |
519 return; | 524 return; |
525 | |
526 // Record the association between the sessionStorage namespace and the | |
527 // tab. | |
528 SessionStorageNamespace* session_storage_namespace = | |
529 tab->tab_contents()->controller().session_storage_namespace(); | |
530 session_storage_namespace_map_[session_storage_namespace->id()] = | |
531 std::make_pair(tab->restore_tab_helper()->window_id(), | |
532 tab->restore_tab_helper()->session_id()); | |
533 | |
520 SetTabWindow(tab->restore_tab_helper()->window_id(), | 534 SetTabWindow(tab->restore_tab_helper()->window_id(), |
521 tab->restore_tab_helper()->session_id()); | 535 tab->restore_tab_helper()->session_id()); |
522 if (tab->extension_tab_helper()->extension_app()) { | 536 if (tab->extension_tab_helper()->extension_app()) { |
523 SetTabExtensionAppID( | 537 SetTabExtensionAppID( |
524 tab->restore_tab_helper()->window_id(), | 538 tab->restore_tab_helper()->window_id(), |
525 tab->restore_tab_helper()->session_id(), | 539 tab->restore_tab_helper()->session_id(), |
526 tab->extension_tab_helper()->extension_app()->id()); | 540 tab->extension_tab_helper()->extension_app()->id()); |
527 } | 541 } |
528 break; | 542 break; |
529 } | 543 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 if (extension_tab_helper->extension_app()) { | 632 if (extension_tab_helper->extension_app()) { |
619 RestoreTabHelper* helper = | 633 RestoreTabHelper* helper = |
620 extension_tab_helper->tab_contents_wrapper()->restore_tab_helper(); | 634 extension_tab_helper->tab_contents_wrapper()->restore_tab_helper(); |
621 SetTabExtensionAppID(helper->window_id(), | 635 SetTabExtensionAppID(helper->window_id(), |
622 helper->session_id(), | 636 helper->session_id(), |
623 extension_tab_helper->extension_app()->id()); | 637 extension_tab_helper->extension_app()->id()); |
624 } | 638 } |
625 break; | 639 break; |
626 } | 640 } |
627 | 641 |
642 case content::NOTIFICATION_DOM_STORAGE_NAMESPACE_CREATED: { | |
643 content::Details<DOMStorageNamespaceCreatedDetails> | |
644 namespace_created_details(details); | |
645 | |
646 SessionStorageNamespaceMap::const_iterator it = | |
647 session_storage_namespace_map_.find(namespace_created_details->id); | |
648 if (it != session_storage_namespace_map_.end()) { | |
649 Pickle session_storage_created_pickle; | |
650 session_storage_created_pickle.WriteInt(it->second.first.id()); | |
651 session_storage_created_pickle.WriteInt(it->second.second.id()); | |
652 session_storage_created_pickle.WriteString( | |
653 namespace_created_details->session_storage_directory.value()); | |
654 ScheduleCommand(new SessionCommand(kCommandSessionStorageCreated, | |
michaeln
2011/12/13 20:40:03
I'm not at all familiar with this SessionService c
marja
2012/01/11 15:17:53
ScheduleCommand puts the command into a queue and
| |
655 session_storage_created_pickle)); | |
656 } | |
657 break; | |
658 } | |
659 | |
628 default: | 660 default: |
629 NOTREACHED(); | 661 NOTREACHED(); |
630 } | 662 } |
631 } | 663 } |
632 | 664 |
633 void SessionService::SetTabExtensionAppID( | 665 void SessionService::SetTabExtensionAppID( |
634 const SessionID& window_id, | 666 const SessionID& window_id, |
635 const SessionID& tab_id, | 667 const SessionID& tab_id, |
636 const std::string& extension_app_id) { | 668 const std::string& extension_app_id) { |
637 if (!ShouldTrackChangesToWindow(window_id)) | 669 if (!ShouldTrackChangesToWindow(window_id)) |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1088 SessionID::id_type tab_id; | 1120 SessionID::id_type tab_id; |
1089 std::string extension_app_id; | 1121 std::string extension_app_id; |
1090 if (!RestoreSetTabExtensionAppIDCommand( | 1122 if (!RestoreSetTabExtensionAppIDCommand( |
1091 *command, &tab_id, &extension_app_id)) { | 1123 *command, &tab_id, &extension_app_id)) { |
1092 return true; | 1124 return true; |
1093 } | 1125 } |
1094 | 1126 |
1095 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); | 1127 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); |
1096 break; | 1128 break; |
1097 } | 1129 } |
1130 case kCommandSessionStorageCreated: { | |
1131 scoped_ptr<Pickle> pickle(command->PayloadAsPickle()); | |
1132 SessionID::id_type window_id; | |
1133 SessionID::id_type tab_id; | |
1134 std::string session_storage_directory; | |
1135 void* iter = NULL; | |
1136 pickle->ReadInt(&iter, &window_id); | |
1137 pickle->ReadInt(&iter, &tab_id); | |
1138 pickle->ReadString(&iter, &session_storage_directory); | |
1139 GetTab(tab_id, tabs)->session_storage_directory = | |
1140 FilePath(session_storage_directory); | |
1141 break; | |
1142 } | |
1098 | 1143 |
1099 default: | 1144 default: |
1100 return true; | 1145 return true; |
1101 } | 1146 } |
1102 } | 1147 } |
1103 return true; | 1148 return true; |
1104 } | 1149 } |
1105 | 1150 |
1106 void SessionService::BuildCommandsForTab( | 1151 void SessionService::BuildCommandsForTab( |
1107 const SessionID& window_id, | 1152 const SessionID& window_id, |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1510 50); | 1555 50); |
1511 if (use_long_period) { | 1556 if (use_long_period) { |
1512 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1557 std::string long_name_("SessionRestore.SaveLongPeriod"); |
1513 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1558 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
1514 delta, | 1559 delta, |
1515 save_delay_in_mins_, | 1560 save_delay_in_mins_, |
1516 save_delay_in_hrs_, | 1561 save_delay_in_hrs_, |
1517 50); | 1562 50); |
1518 } | 1563 } |
1519 } | 1564 } |
OLD | NEW |