Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: chrome/browser/sessions/session_restore.cc

Issue 10875027: Restart running apps when chrome restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 DCHECK(session_service); 519 DCHECK(session_service);
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_, &apps_);
527 delete this; 530 delete this;
528 return browser; 531 return browser;
529 } 532 }
530 533
531 if (browser_) { 534 if (browser_) {
532 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, 535 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED,
533 content::Source<Browser>(browser_)); 536 content::Source<Browser>(browser_));
534 } 537 }
535 538
536 return browser_; 539 return browser_;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 700 }
698 701
699 #if defined(OS_CHROMEOS) 702 #if defined(OS_CHROMEOS)
700 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( 703 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(
701 "SessionRestore-End", false); 704 "SessionRestore-End", false);
702 #endif 705 #endif
703 return browser; 706 return browser;
704 } 707 }
705 708
706 void OnGotSession(SessionService::Handle handle, 709 void OnGotSession(SessionService::Handle handle,
707 std::vector<SessionWindow*>* windows) { 710 std::vector<SessionWindow*>* windows,
711 std::set<std::string>* apps) {
708 base::TimeDelta time_to_got_sessions = 712 base::TimeDelta time_to_got_sessions =
709 base::TimeTicks::Now() - restore_started_; 713 base::TimeTicks::Now() - restore_started_;
710 UMA_HISTOGRAM_CUSTOM_TIMES( 714 UMA_HISTOGRAM_CUSTOM_TIMES(
711 "SessionRestore.TimeToGotSessions", 715 "SessionRestore.TimeToGotSessions",
712 time_to_got_sessions, 716 time_to_got_sessions,
713 base::TimeDelta::FromMilliseconds(10), 717 base::TimeDelta::FromMilliseconds(10),
714 base::TimeDelta::FromSeconds(1000), 718 base::TimeDelta::FromSeconds(1000),
715 100); 719 100);
716 #if defined(OS_CHROMEOS) 720 #if defined(OS_CHROMEOS)
717 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( 721 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(
718 "SessionRestore-GotSession", false); 722 "SessionRestore-GotSession", false);
719 #endif 723 #endif
720 if (synchronous_) { 724 if (synchronous_) {
721 // See comment above windows_ as to why we don't process immediately. 725 // See comment above windows_ as to why we don't process immediately.
722 windows_.swap(*windows); 726 windows_.swap(*windows);
727 apps_.swap(*apps);
723 MessageLoop::current()->QuitNow(); 728 MessageLoop::current()->QuitNow();
724 return; 729 return;
725 } 730 }
726 731
727 ProcessSessionWindows(windows); 732 ProcessSessionWindows(windows, apps);
728 } 733 }
729 734
730 Browser* ProcessSessionWindows(std::vector<SessionWindow*>* windows) { 735 Browser* ProcessSessionWindows(std::vector<SessionWindow*>* windows,
736 std::set<std::string>* apps) {
737
738 for (std::set<std::string>::const_iterator it = apps->begin();
marja 2012/08/23 07:31:18 Is there a specific reason why this is done first,
koz (OOO until 15th September) 2012/08/23 07:59:04 That's a good question. In fact, this doesn't need
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);
benwells 2012/08/23 06:54:53 Indenting of this block and empty line at top.
koz (OOO until 15th September) 2012/08/23 07:30:12 Done.
744 }
731 VLOG(1) << "ProcessSessionWindows " << windows->size(); 745 VLOG(1) << "ProcessSessionWindows " << windows->size();
732 base::TimeDelta time_to_process_sessions = 746 base::TimeDelta time_to_process_sessions =
733 base::TimeTicks::Now() - restore_started_; 747 base::TimeTicks::Now() - restore_started_;
734 UMA_HISTOGRAM_CUSTOM_TIMES( 748 UMA_HISTOGRAM_CUSTOM_TIMES(
735 "SessionRestore.TimeToProcessSessions", 749 "SessionRestore.TimeToProcessSessions",
736 time_to_process_sessions, 750 time_to_process_sessions,
737 base::TimeDelta::FromMilliseconds(10), 751 base::TimeDelta::FromMilliseconds(10),
738 base::TimeDelta::FromSeconds(1000), 752 base::TimeDelta::FromSeconds(1000),
739 100); 753 100);
740 754
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 CancelableRequestConsumer request_consumer_; 1043 CancelableRequestConsumer request_consumer_;
1030 1044
1031 // Responsible for loading the tabs. 1045 // Responsible for loading the tabs.
1032 scoped_refptr<TabLoader> tab_loader_; 1046 scoped_refptr<TabLoader> tab_loader_;
1033 1047
1034 // When synchronous we run a nested message loop. To avoid creating windows 1048 // 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 1049 // 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 1050 // loop take a while) we cache the SessionWindows here and create the actual
1037 // windows when the nested message loop exits. 1051 // windows when the nested message loop exits.
1038 std::vector<SessionWindow*> windows_; 1052 std::vector<SessionWindow*> windows_;
1053 std::set<std::string> apps_;
1039 1054
1040 content::NotificationRegistrar registrar_; 1055 content::NotificationRegistrar registrar_;
1041 1056
1042 // The time we started the restore. 1057 // The time we started the restore.
1043 base::TimeTicks restore_started_; 1058 base::TimeTicks restore_started_;
1044 1059
1045 // Set to true after the first browser is shown. 1060 // Set to true after the first browser is shown.
1046 bool browser_shown_; 1061 bool browser_shown_;
1047 1062
1048 DISALLOW_COPY_AND_ASSIGN(SessionRestoreImpl); 1063 DISALLOW_COPY_AND_ASSIGN(SessionRestoreImpl);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 if (active_session_restorers == NULL) 1122 if (active_session_restorers == NULL)
1108 return false; 1123 return false;
1109 for (std::set<SessionRestoreImpl*>::const_iterator it = 1124 for (std::set<SessionRestoreImpl*>::const_iterator it =
1110 active_session_restorers->begin(); 1125 active_session_restorers->begin();
1111 it != active_session_restorers->end(); ++it) { 1126 it != active_session_restorers->end(); ++it) {
1112 if ((*it)->profile() == profile) 1127 if ((*it)->profile() == profile)
1113 return true; 1128 return true;
1114 } 1129 }
1115 return false; 1130 return false;
1116 } 1131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698