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/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/platform_file.h" | 18 #include "base/platform_file.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" | |
23 #include "chrome/browser/extensions/event_router.h" | |
22 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
25 #include "chrome/browser/extensions/extension_system.h" | |
23 #include "chrome/browser/performance_monitor/startup_timer.h" | 26 #include "chrome/browser/performance_monitor/startup_timer.h" |
24 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/sessions/session_service.h" | 28 #include "chrome/browser/sessions/session_service.h" |
26 #include "chrome/browser/sessions/session_service_factory.h" | 29 #include "chrome/browser/sessions/session_service_factory.h" |
27 #include "chrome/browser/sessions/session_types.h" | 30 #include "chrome/browser/sessions/session_types.h" |
28 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
30 #include "chrome/browser/ui/browser_navigator.h" | 33 #include "chrome/browser/ui/browser_navigator.h" |
31 #include "chrome/browser/ui/browser_tabrestore.h" | 34 #include "chrome/browser/ui/browser_tabrestore.h" |
32 #include "chrome/browser/ui/browser_tabstrip.h" | 35 #include "chrome/browser/ui/browser_tabstrip.h" |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 session_service->GetLastSession( | 520 session_service->GetLastSession( |
518 &request_consumer_, | 521 &request_consumer_, |
519 base::Bind(&SessionRestoreImpl::OnGotSession, base::Unretained(this))); | 522 base::Bind(&SessionRestoreImpl::OnGotSession, base::Unretained(this))); |
520 | 523 |
521 if (synchronous_) { | 524 if (synchronous_) { |
522 { | 525 { |
523 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 526 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
524 MessageLoop::current()->Run(); | 527 MessageLoop::current()->Run(); |
525 } | 528 } |
526 Browser* browser = ProcessSessionWindows(&windows_); | 529 Browser* browser = ProcessSessionWindows(&windows_); |
530 ProcessSessionApps(&apps_); | |
527 delete this; | 531 delete this; |
528 return browser; | 532 return browser; |
529 } | 533 } |
530 | 534 |
531 if (browser_) { | 535 if (browser_) { |
532 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, | 536 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, |
533 content::Source<Browser>(browser_)); | 537 content::Source<Browser>(browser_)); |
534 } | 538 } |
535 | 539 |
536 return browser_; | 540 return browser_; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 } | 701 } |
698 | 702 |
699 #if defined(OS_CHROMEOS) | 703 #if defined(OS_CHROMEOS) |
700 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 704 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
701 "SessionRestore-End", false); | 705 "SessionRestore-End", false); |
702 #endif | 706 #endif |
703 return browser; | 707 return browser; |
704 } | 708 } |
705 | 709 |
706 void OnGotSession(SessionService::Handle handle, | 710 void OnGotSession(SessionService::Handle handle, |
707 std::vector<SessionWindow*>* windows) { | 711 std::vector<SessionWindow*>* windows, |
712 std::set<std::string>* apps) { | |
708 base::TimeDelta time_to_got_sessions = | 713 base::TimeDelta time_to_got_sessions = |
709 base::TimeTicks::Now() - restore_started_; | 714 base::TimeTicks::Now() - restore_started_; |
710 UMA_HISTOGRAM_CUSTOM_TIMES( | 715 UMA_HISTOGRAM_CUSTOM_TIMES( |
711 "SessionRestore.TimeToGotSessions", | 716 "SessionRestore.TimeToGotSessions", |
712 time_to_got_sessions, | 717 time_to_got_sessions, |
713 base::TimeDelta::FromMilliseconds(10), | 718 base::TimeDelta::FromMilliseconds(10), |
714 base::TimeDelta::FromSeconds(1000), | 719 base::TimeDelta::FromSeconds(1000), |
715 100); | 720 100); |
716 #if defined(OS_CHROMEOS) | 721 #if defined(OS_CHROMEOS) |
717 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( | 722 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( |
718 "SessionRestore-GotSession", false); | 723 "SessionRestore-GotSession", false); |
719 #endif | 724 #endif |
720 if (synchronous_) { | 725 if (synchronous_) { |
721 // See comment above windows_ as to why we don't process immediately. | 726 // See comment above windows_ as to why we don't process immediately. |
722 windows_.swap(*windows); | 727 windows_.swap(*windows); |
728 apps_.swap(*apps); | |
723 MessageLoop::current()->QuitNow(); | 729 MessageLoop::current()->QuitNow(); |
724 return; | 730 return; |
725 } | 731 } |
726 | 732 |
727 ProcessSessionWindows(windows); | 733 ProcessSessionWindows(windows); |
734 ProcessSessionApps(apps); | |
735 } | |
736 | |
737 void ProcessSessionApps(std::set<std::string>* apps) { | |
738 for (std::set<std::string>::const_iterator it = apps->begin(); | |
739 it != apps->end(); it++) { | |
740 const extensions::Extension* extension = | |
741 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | |
742 extensions()->GetByID(*it); | |
743 extensions::AppEventRouter::DispatchOnRestartEvent(profile_, extension); | |
744 } | |
728 } | 745 } |
729 | 746 |
730 Browser* ProcessSessionWindows(std::vector<SessionWindow*>* windows) { | 747 Browser* ProcessSessionWindows(std::vector<SessionWindow*>* windows) { |
731 VLOG(1) << "ProcessSessionWindows " << windows->size(); | 748 VLOG(1) << "ProcessSessionWindows " << windows->size(); |
732 base::TimeDelta time_to_process_sessions = | 749 base::TimeDelta time_to_process_sessions = |
733 base::TimeTicks::Now() - restore_started_; | 750 base::TimeTicks::Now() - restore_started_; |
734 UMA_HISTOGRAM_CUSTOM_TIMES( | 751 UMA_HISTOGRAM_CUSTOM_TIMES( |
735 "SessionRestore.TimeToProcessSessions", | 752 "SessionRestore.TimeToProcessSessions", |
736 time_to_process_sessions, | 753 time_to_process_sessions, |
737 base::TimeDelta::FromMilliseconds(10), | 754 base::TimeDelta::FromMilliseconds(10), |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 CancelableRequestConsumer request_consumer_; | 1046 CancelableRequestConsumer request_consumer_; |
1030 | 1047 |
1031 // Responsible for loading the tabs. | 1048 // Responsible for loading the tabs. |
1032 scoped_refptr<TabLoader> tab_loader_; | 1049 scoped_refptr<TabLoader> tab_loader_; |
1033 | 1050 |
1034 // When synchronous we run a nested message loop. To avoid creating windows | 1051 // When synchronous we run a nested message loop. To avoid creating windows |
1035 // from the nested message loop (which can make exiting the nested message | 1052 // from the nested message loop (which can make exiting the nested message |
1036 // loop take a while) we cache the SessionWindows here and create the actual | 1053 // loop take a while) we cache the SessionWindows here and create the actual |
1037 // windows when the nested message loop exits. | 1054 // windows when the nested message loop exits. |
1038 std::vector<SessionWindow*> windows_; | 1055 std::vector<SessionWindow*> windows_; |
1056 std::set<std::string> apps_; | |
sky
2012/08/23 16:23:52
newline between 1056/1057 and document what apps_
koz (OOO until 15th September)
2012/08/24 02:08:57
Done.
| |
1039 | 1057 |
1040 content::NotificationRegistrar registrar_; | 1058 content::NotificationRegistrar registrar_; |
1041 | 1059 |
1042 // The time we started the restore. | 1060 // The time we started the restore. |
1043 base::TimeTicks restore_started_; | 1061 base::TimeTicks restore_started_; |
1044 | 1062 |
1045 // Set to true after the first browser is shown. | 1063 // Set to true after the first browser is shown. |
1046 bool browser_shown_; | 1064 bool browser_shown_; |
1047 | 1065 |
1048 DISALLOW_COPY_AND_ASSIGN(SessionRestoreImpl); | 1066 DISALLOW_COPY_AND_ASSIGN(SessionRestoreImpl); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 if (active_session_restorers == NULL) | 1125 if (active_session_restorers == NULL) |
1108 return false; | 1126 return false; |
1109 for (std::set<SessionRestoreImpl*>::const_iterator it = | 1127 for (std::set<SessionRestoreImpl*>::const_iterator it = |
1110 active_session_restorers->begin(); | 1128 active_session_restorers->begin(); |
1111 it != active_session_restorers->end(); ++it) { | 1129 it != active_session_restorers->end(); ++it) { |
1112 if ((*it)->profile() == profile) | 1130 if ((*it)->profile() == profile) |
1113 return true; | 1131 return true; |
1114 } | 1132 } |
1115 return false; | 1133 return false; |
1116 } | 1134 } |
OLD | NEW |