OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_restore.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 30 matching lines...) Expand all Loading... | |
41 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
42 #include "components/sessions/session_types.h" | 42 #include "components/sessions/session_types.h" |
43 #include "content/public/browser/child_process_security_policy.h" | 43 #include "content/public/browser/child_process_security_policy.h" |
44 #include "content/public/browser/dom_storage_context.h" | 44 #include "content/public/browser/dom_storage_context.h" |
45 #include "content/public/browser/navigation_controller.h" | 45 #include "content/public/browser/navigation_controller.h" |
46 #include "content/public/browser/notification_registrar.h" | 46 #include "content/public/browser/notification_registrar.h" |
47 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
48 #include "content/public/browser/render_process_host.h" | 48 #include "content/public/browser/render_process_host.h" |
49 #include "content/public/browser/render_widget_host.h" | 49 #include "content/public/browser/render_widget_host.h" |
50 #include "content/public/browser/render_widget_host_view.h" | 50 #include "content/public/browser/render_widget_host_view.h" |
51 #include "content/public/browser/session_restore_uma.h" | |
51 #include "content/public/browser/session_storage_namespace.h" | 52 #include "content/public/browser/session_storage_namespace.h" |
52 #include "content/public/browser/storage_partition.h" | 53 #include "content/public/browser/storage_partition.h" |
53 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
54 #include "content/public/common/page_state.h" | 55 #include "content/public/common/page_state.h" |
55 #include "extensions/browser/extension_registry.h" | 56 #include "extensions/browser/extension_registry.h" |
56 #include "extensions/common/extension_set.h" | 57 #include "extensions/common/extension_set.h" |
57 | 58 |
58 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
59 #include "chrome/browser/chromeos/boot_times_recorder.h" | 60 #include "chrome/browser/chromeos/boot_times_recorder.h" |
60 #endif | 61 #endif |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 std::max(0, std::min((*i)->selected_tab_index, | 175 std::max(0, std::min((*i)->selected_tab_index, |
175 static_cast<int>((*i)->tabs.size()) - 1)); | 176 static_cast<int>((*i)->tabs.size()) - 1)); |
176 RestoreTabsToBrowser(*(*i), browser, initial_tab_count, | 177 RestoreTabsToBrowser(*(*i), browser, initial_tab_count, |
177 selected_tab_index, &created_contents); | 178 selected_tab_index, &created_contents); |
178 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); | 179 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); |
179 } | 180 } |
180 | 181 |
181 // Always create in a new window. | 182 // Always create in a new window. |
182 FinishedTabCreation(true, true, created_contents); | 183 FinishedTabCreation(true, true, created_contents); |
183 | 184 |
185 // Record the number of tabs associated with this session restore. | |
186 UMA_HISTOGRAM_COUNTS_100(content::kSessionRestoreTabCount, | |
sky
2015/05/07 20:23:45
Please try to keep all stats collection in Session
| |
187 created_contents.size()); | |
188 | |
184 on_session_restored_callbacks_->Notify( | 189 on_session_restored_callbacks_->Notify( |
185 static_cast<int>(created_contents.size())); | 190 static_cast<int>(created_contents.size())); |
186 | 191 |
187 return browsers; | 192 return browsers; |
188 } | 193 } |
189 | 194 |
190 // Restore a single tab from a foreign session. | 195 // Restore a single tab from a foreign session. |
191 // Opens in the tab in the last active browser, unless disposition is | 196 // Opens in the tab in the last active browser, unless disposition is |
192 // NEW_WINDOW, in which case the tab will be opened in a new browser. Returns | 197 // NEW_WINDOW, in which case the tab will be opened in a new browser. Returns |
193 // the WebContents of the restored tab. | 198 // the WebContents of the restored tab. |
(...skipping 23 matching lines...) Expand all Loading... | |
217 } else { | 222 } else { |
218 int tab_index = | 223 int tab_index = |
219 use_new_window ? 0 : browser->tab_strip_model()->active_index() + 1; | 224 use_new_window ? 0 : browser->tab_strip_model()->active_index() + 1; |
220 web_contents = chrome::AddRestoredTab( | 225 web_contents = chrome::AddRestoredTab( |
221 browser, tab.navigations, tab_index, selected_index, | 226 browser, tab.navigations, tab_index, selected_index, |
222 tab.extension_app_id, | 227 tab.extension_app_id, |
223 disposition == NEW_FOREGROUND_TAB, // selected | 228 disposition == NEW_FOREGROUND_TAB, // selected |
224 tab.pinned, true, nullptr, tab.user_agent_override); | 229 tab.pinned, true, nullptr, tab.user_agent_override); |
225 // Start loading the tab immediately. | 230 // Start loading the tab immediately. |
226 web_contents->GetController().LoadIfNecessary(); | 231 web_contents->GetController().LoadIfNecessary(); |
232 UMA_HISTOGRAM_ENUMERATION( | |
233 content::kSessionRestoreTabActions, | |
234 content::kSessionRestoreTabActionsUma_ForegroundTabLoaded, | |
235 content::kSessionRestoreTabActionsUma_Max); | |
227 } | 236 } |
228 | 237 |
229 if (use_new_window) { | 238 if (use_new_window) { |
230 browser->tab_strip_model()->ActivateTabAt(0, true); | 239 browser->tab_strip_model()->ActivateTabAt(0, true); |
231 browser->window()->Show(); | 240 browser->window()->Show(); |
232 } | 241 } |
233 NotifySessionServiceOfRestoredTabs(browser, | 242 NotifySessionServiceOfRestoredTabs(browser, |
234 browser->tab_strip_model()->count()); | 243 browser->tab_strip_model()->count()); |
235 | 244 |
236 // Since FinishedTabCreation() is not called here, |this| will leak if we | 245 // Since FinishedTabCreation() is not called here, |this| will leak if we |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 WebContents* contents = RestoreTab(tab, i, browser, is_selected_tab); | 524 WebContents* contents = RestoreTab(tab, i, browser, is_selected_tab); |
516 | 525 |
517 // RestoreTab can return nullptr if |tab| doesn't have valid data. | 526 // RestoreTab can return nullptr if |tab| doesn't have valid data. |
518 if (!contents) | 527 if (!contents) |
519 continue; | 528 continue; |
520 | 529 |
521 RestoredTab restored_tab; | 530 RestoredTab restored_tab; |
522 restored_tab.contents = contents; | 531 restored_tab.contents = contents; |
523 restored_tab.is_active = is_selected_tab; | 532 restored_tab.is_active = is_selected_tab; |
524 created_contents->push_back(restored_tab); | 533 created_contents->push_back(restored_tab); |
534 UMA_HISTOGRAM_ENUMERATION( | |
535 content::kSessionRestoreTabActions, | |
536 content::kSessionRestoreTabActionsUma_TabCreated, | |
537 content::kSessionRestoreTabActionsUma_Max); | |
525 | 538 |
526 // If this isn't the selected tab, there's nothing else to do. | 539 // If this isn't the selected tab, there's nothing else to do. |
527 if (!is_selected_tab) | 540 if (!is_selected_tab) |
528 continue; | 541 continue; |
529 | 542 |
530 ShowBrowser(browser, browser->tab_strip_model()->GetIndexOfWebContents( | 543 ShowBrowser(browser, browser->tab_strip_model()->GetIndexOfWebContents( |
531 contents)); | 544 contents)); |
532 // TODO(sky): remove. For debugging 368236. | 545 // TODO(sky): remove. For debugging 368236. |
533 CHECK_EQ(browser->tab_strip_model()->GetActiveWebContents(), contents); | 546 CHECK_EQ(browser->tab_strip_model()->GetActiveWebContents(), contents); |
534 } | 547 } |
535 } else { | 548 } else { |
536 // If the browser already has tabs, we want to restore the new ones after | 549 // If the browser already has tabs, we want to restore the new ones after |
537 // the existing ones. E.g. this happens in Win8 Metro where we merge | 550 // the existing ones. E.g. this happens in Win8 Metro where we merge |
538 // windows or when launching a hosted app from the app launcher. | 551 // windows or when launching a hosted app from the app launcher. |
539 int tab_index_offset = initial_tab_count; | 552 int tab_index_offset = initial_tab_count; |
540 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { | 553 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { |
541 const sessions::SessionTab& tab = *(window.tabs[i]); | 554 const sessions::SessionTab& tab = *(window.tabs[i]); |
542 // Always schedule loads as we will not be calling ShowBrowser(). | 555 // Always schedule loads as we will not be calling ShowBrowser(). |
543 WebContents* contents = | 556 WebContents* contents = |
544 RestoreTab(tab, tab_index_offset + i, browser, false); | 557 RestoreTab(tab, tab_index_offset + i, browser, false); |
545 if (contents) { | 558 if (contents) { |
546 RestoredTab restored_tab; | 559 RestoredTab restored_tab; |
547 restored_tab.contents = contents; | 560 restored_tab.contents = contents; |
548 restored_tab.is_active = false; | 561 restored_tab.is_active = false; |
549 created_contents->push_back(restored_tab); | 562 created_contents->push_back(restored_tab); |
563 UMA_HISTOGRAM_ENUMERATION( | |
564 content::kSessionRestoreTabActions, | |
565 content::kSessionRestoreTabActionsUma_TabCreated, | |
566 content::kSessionRestoreTabActionsUma_Max); | |
550 } | 567 } |
551 } | 568 } |
552 } | 569 } |
553 } | 570 } |
554 | 571 |
555 // |tab_index| is ignored for pinned tabs which will always be pushed behind | 572 // |tab_index| is ignored for pinned tabs which will always be pushed behind |
556 // the last existing pinned tab. | 573 // the last existing pinned tab. |
557 // |tab_loader_| will schedule this tab for loading if |is_selected_tab| is | 574 // |tab_loader_| will schedule this tab for loading if |is_selected_tab| is |
558 // false. | 575 // false. |
559 WebContents* RestoreTab(const sessions::SessionTab& tab, | 576 WebContents* RestoreTab(const sessions::SessionTab& tab, |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 Browser* SessionRestore::RestoreSession( | 731 Browser* SessionRestore::RestoreSession( |
715 Profile* profile, | 732 Profile* profile, |
716 Browser* browser, | 733 Browser* browser, |
717 chrome::HostDesktopType host_desktop_type, | 734 chrome::HostDesktopType host_desktop_type, |
718 uint32 behavior, | 735 uint32 behavior, |
719 const std::vector<GURL>& urls_to_open) { | 736 const std::vector<GURL>& urls_to_open) { |
720 #if defined(OS_CHROMEOS) | 737 #if defined(OS_CHROMEOS) |
721 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( | 738 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( |
722 "SessionRestore-Start", false); | 739 "SessionRestore-Start", false); |
723 #endif | 740 #endif |
741 UMA_HISTOGRAM_ENUMERATION( | |
742 content::kSessionRestoreActions, | |
743 content::kSessionRestoreActionsUma_Initiated, | |
744 content::kSessionRestoreActionsUma_Max); | |
724 DCHECK(profile); | 745 DCHECK(profile); |
725 // Always restore from the original profile (incognito profiles have no | 746 // Always restore from the original profile (incognito profiles have no |
726 // session service). | 747 // session service). |
727 profile = profile->GetOriginalProfile(); | 748 profile = profile->GetOriginalProfile(); |
728 if (!SessionServiceFactory::GetForProfile(profile)) { | 749 if (!SessionServiceFactory::GetForProfile(profile)) { |
729 NOTREACHED(); | 750 NOTREACHED(); |
730 return nullptr; | 751 return nullptr; |
731 } | 752 } |
732 profile->set_restored_last_session(true); | 753 profile->set_restored_last_session(true); |
733 // SessionRestoreImpl takes care of deleting itself when done. | 754 // SessionRestoreImpl takes care of deleting itself when done. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 // static | 835 // static |
815 SessionRestore::CallbackSubscription | 836 SessionRestore::CallbackSubscription |
816 SessionRestore::RegisterOnSessionRestoredCallback( | 837 SessionRestore::RegisterOnSessionRestoredCallback( |
817 const base::Callback<void(int)>& callback) { | 838 const base::Callback<void(int)>& callback) { |
818 return on_session_restored_callbacks()->Add(callback); | 839 return on_session_restored_callbacks()->Add(callback); |
819 } | 840 } |
820 | 841 |
821 // static | 842 // static |
822 base::CallbackList<void(int)>* | 843 base::CallbackList<void(int)>* |
823 SessionRestore::on_session_restored_callbacks_ = nullptr; | 844 SessionRestore::on_session_restored_callbacks_ = nullptr; |
OLD | NEW |