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_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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/scoped_vector.h" | |
17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
18 #include "base/platform_file.h" | 19 #include "base/platform_file.h" |
19 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
20 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/browser/performance_monitor/startup_timer.h" | 24 #include "chrome/browser/performance_monitor/startup_timer.h" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/sessions/session_service.h" | 26 #include "chrome/browser/sessions/session_service.h" |
26 #include "chrome/browser/sessions/session_service_factory.h" | 27 #include "chrome/browser/sessions/session_service_factory.h" |
27 #include "chrome/browser/sessions/session_types.h" | 28 #include "chrome/browser/sessions/session_types.h" |
28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
30 #include "chrome/browser/ui/browser_navigator.h" | 31 #include "chrome/browser/ui/browser_navigator.h" |
31 #include "chrome/browser/ui/browser_tabrestore.h" | 32 #include "chrome/browser/ui/browser_tabrestore.h" |
32 #include "chrome/browser/ui/browser_tabstrip.h" | 33 #include "chrome/browser/ui/browser_tabstrip.h" |
33 #include "chrome/browser/ui/browser_window.h" | 34 #include "chrome/browser/ui/browser_window.h" |
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
35 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 36 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
37 #include "chrome/common/cancelable_task_tracker.h" | |
36 #include "chrome/common/chrome_notification_types.h" | 38 #include "chrome/common/chrome_notification_types.h" |
37 #include "content/public/browser/child_process_security_policy.h" | 39 #include "content/public/browser/child_process_security_policy.h" |
38 #include "content/public/browser/dom_storage_context.h" | 40 #include "content/public/browser/dom_storage_context.h" |
39 #include "content/public/browser/navigation_controller.h" | 41 #include "content/public/browser/navigation_controller.h" |
40 #include "content/public/browser/notification_registrar.h" | 42 #include "content/public/browser/notification_registrar.h" |
41 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
42 #include "content/public/browser/render_process_host.h" | 44 #include "content/public/browser/render_process_host.h" |
43 #include "content/public/browser/render_widget_host.h" | 45 #include "content/public/browser/render_widget_host.h" |
44 #include "content/public/browser/render_widget_host_view.h" | 46 #include "content/public/browser/render_widget_host_view.h" |
45 #include "content/public/browser/session_storage_namespace.h" | 47 #include "content/public/browser/session_storage_namespace.h" |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 // Chrome doesn't prematurely exit AddRef the process. We'll release in the | 518 // Chrome doesn't prematurely exit AddRef the process. We'll release in the |
517 // destructor when restore is done. | 519 // destructor when restore is done. |
518 g_browser_process->AddRefModule(); | 520 g_browser_process->AddRefModule(); |
519 } | 521 } |
520 | 522 |
521 Browser* Restore() { | 523 Browser* Restore() { |
522 SessionService* session_service = | 524 SessionService* session_service = |
523 SessionServiceFactory::GetForProfile(profile_); | 525 SessionServiceFactory::GetForProfile(profile_); |
524 DCHECK(session_service); | 526 DCHECK(session_service); |
525 session_service->GetLastSession( | 527 session_service->GetLastSession( |
526 &request_consumer_, | 528 base::Bind(&SessionRestoreImpl::OnGotSession, base::Unretained(this)), |
527 base::Bind(&SessionRestoreImpl::OnGotSession, base::Unretained(this))); | 529 &cancelable_task_tracker_); |
528 | 530 |
529 if (synchronous_) { | 531 if (synchronous_) { |
530 { | 532 { |
531 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 533 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
532 MessageLoop::current()->Run(); | 534 MessageLoop::current()->Run(); |
533 } | 535 } |
534 Browser* browser = ProcessSessionWindows(&windows_, active_window_id_); | 536 Browser* browser = ProcessSessionWindows(&windows_, active_window_id_); |
535 delete this; | 537 delete this; |
536 return browser; | 538 return browser; |
537 } | 539 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
704 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 706 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
705 } | 707 } |
706 | 708 |
707 #if defined(OS_CHROMEOS) | 709 #if defined(OS_CHROMEOS) |
708 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 710 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
709 "SessionRestore-End", false); | 711 "SessionRestore-End", false); |
710 #endif | 712 #endif |
711 return browser; | 713 return browser; |
712 } | 714 } |
713 | 715 |
714 void OnGotSession(SessionService::Handle handle, | 716 void OnGotSession(ScopedVector<SessionWindow> windows, |
marja
2012/12/06 08:21:58
Is it possible to avoid copying the ScopedVector w
kaiwang
2012/12/06 18:07:52
no.. ScopedVector is a non-copyable type like scop
kaiwang
2012/12/06 18:29:31
Oh, I think I was wrong. It's possible to Bind a
marja
2012/12/10 18:22:56
Hmm, so this copy probably gets ScopedVector(RValu
| |
715 std::vector<SessionWindow*>* windows, | |
716 SessionID::id_type active_window_id) { | 717 SessionID::id_type active_window_id) { |
717 base::TimeDelta time_to_got_sessions = | 718 base::TimeDelta time_to_got_sessions = |
718 base::TimeTicks::Now() - restore_started_; | 719 base::TimeTicks::Now() - restore_started_; |
719 UMA_HISTOGRAM_CUSTOM_TIMES( | 720 UMA_HISTOGRAM_CUSTOM_TIMES( |
720 "SessionRestore.TimeToGotSessions", | 721 "SessionRestore.TimeToGotSessions", |
721 time_to_got_sessions, | 722 time_to_got_sessions, |
722 base::TimeDelta::FromMilliseconds(10), | 723 base::TimeDelta::FromMilliseconds(10), |
723 base::TimeDelta::FromSeconds(1000), | 724 base::TimeDelta::FromSeconds(1000), |
724 100); | 725 100); |
725 #if defined(OS_CHROMEOS) | 726 #if defined(OS_CHROMEOS) |
726 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 727 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
727 "SessionRestore-GotSession", false); | 728 "SessionRestore-GotSession", false); |
728 #endif | 729 #endif |
729 if (synchronous_) { | 730 if (synchronous_) { |
730 // See comment above windows_ as to why we don't process immediately. | 731 // See comment above windows_ as to why we don't process immediately. |
731 windows_.swap(*windows); | 732 windows_.swap(windows.get()); |
732 active_window_id_ = active_window_id; | 733 active_window_id_ = active_window_id; |
733 MessageLoop::current()->QuitNow(); | 734 MessageLoop::current()->QuitNow(); |
734 return; | 735 return; |
735 } | 736 } |
736 | 737 |
737 ProcessSessionWindows(windows, active_window_id); | 738 ProcessSessionWindows(&windows.get(), active_window_id); |
738 } | 739 } |
739 | 740 |
740 Browser* ProcessSessionWindows(std::vector<SessionWindow*>* windows, | 741 Browser* ProcessSessionWindows(std::vector<SessionWindow*>* windows, |
741 SessionID::id_type active_window_id) { | 742 SessionID::id_type active_window_id) { |
742 VLOG(1) << "ProcessSessionWindows " << windows->size(); | 743 VLOG(1) << "ProcessSessionWindows " << windows->size(); |
743 base::TimeDelta time_to_process_sessions = | 744 base::TimeDelta time_to_process_sessions = |
744 base::TimeTicks::Now() - restore_started_; | 745 base::TimeTicks::Now() - restore_started_; |
745 UMA_HISTOGRAM_CUSTOM_TIMES( | 746 UMA_HISTOGRAM_CUSTOM_TIMES( |
746 "SessionRestore.TimeToProcessSessions", | 747 "SessionRestore.TimeToProcessSessions", |
747 time_to_process_sessions, | 748 time_to_process_sessions, |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1096 | 1097 |
1097 // If true and there is an error or there are no windows to restore, we | 1098 // If true and there is an error or there are no windows to restore, we |
1098 // create a tabbed browser anyway. This is used on startup to make sure at | 1099 // create a tabbed browser anyway. This is used on startup to make sure at |
1099 // at least one window is created. | 1100 // at least one window is created. |
1100 const bool always_create_tabbed_browser_; | 1101 const bool always_create_tabbed_browser_; |
1101 | 1102 |
1102 // Set of URLs to open in addition to those restored from the session. | 1103 // Set of URLs to open in addition to those restored from the session. |
1103 std::vector<GURL> urls_to_open_; | 1104 std::vector<GURL> urls_to_open_; |
1104 | 1105 |
1105 // Used to get the session. | 1106 // Used to get the session. |
1106 CancelableRequestConsumer request_consumer_; | 1107 CancelableTaskTracker cancelable_task_tracker_; |
1107 | 1108 |
1108 // Responsible for loading the tabs. | 1109 // Responsible for loading the tabs. |
1109 scoped_refptr<TabLoader> tab_loader_; | 1110 scoped_refptr<TabLoader> tab_loader_; |
1110 | 1111 |
1111 // When synchronous we run a nested message loop. To avoid creating windows | 1112 // When synchronous we run a nested message loop. To avoid creating windows |
1112 // from the nested message loop (which can make exiting the nested message | 1113 // from the nested message loop (which can make exiting the nested message |
1113 // loop take a while) we cache the SessionWindows here and create the actual | 1114 // loop take a while) we cache the SessionWindows here and create the actual |
1114 // windows when the nested message loop exits. | 1115 // windows when the nested message loop exits. |
1115 std::vector<SessionWindow*> windows_; | 1116 std::vector<SessionWindow*> windows_; |
1116 SessionID::id_type active_window_id_; | 1117 SessionID::id_type active_window_id_; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 if (active_session_restorers == NULL) | 1186 if (active_session_restorers == NULL) |
1186 return false; | 1187 return false; |
1187 for (std::set<SessionRestoreImpl*>::const_iterator it = | 1188 for (std::set<SessionRestoreImpl*>::const_iterator it = |
1188 active_session_restorers->begin(); | 1189 active_session_restorers->begin(); |
1189 it != active_session_restorers->end(); ++it) { | 1190 it != active_session_restorers->end(); ++it) { |
1190 if ((*it)->profile() == profile) | 1191 if ((*it)->profile() == profile) |
1191 return true; | 1192 return true; |
1192 } | 1193 } |
1193 return false; | 1194 return false; |
1194 } | 1195 } |
OLD | NEW |