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

Side by Side Diff: chrome/browser/ui/browser_init.cc

Issue 9232007: Fix: after updating, restore tabs from all profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test fixes + better tests. Created 8 years, 11 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
« no previous file with comments | « chrome/browser/ui/browser_init.h ('k') | chrome/browser/ui/browser_init_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ui/browser_init.h" 5 #include "chrome/browser/ui/browser_init.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 27 matching lines...) Expand all
38 #include "chrome/browser/extensions/pack_extension_job.h" 38 #include "chrome/browser/extensions/pack_extension_job.h"
39 #include "chrome/browser/first_run/first_run.h" 39 #include "chrome/browser/first_run/first_run.h"
40 #include "chrome/browser/google/google_util.h" 40 #include "chrome/browser/google/google_util.h"
41 #include "chrome/browser/infobars/infobar_tab_helper.h" 41 #include "chrome/browser/infobars/infobar_tab_helper.h"
42 #include "chrome/browser/net/crl_set_fetcher.h" 42 #include "chrome/browser/net/crl_set_fetcher.h"
43 #include "chrome/browser/net/predictor.h" 43 #include "chrome/browser/net/predictor.h"
44 #include "chrome/browser/net/url_fixer_upper.h" 44 #include "chrome/browser/net/url_fixer_upper.h"
45 #include "chrome/browser/notifications/desktop_notification_service.h" 45 #include "chrome/browser/notifications/desktop_notification_service.h"
46 #include "chrome/browser/prefs/incognito_mode_prefs.h" 46 #include "chrome/browser/prefs/incognito_mode_prefs.h"
47 #include "chrome/browser/prefs/pref_service.h" 47 #include "chrome/browser/prefs/pref_service.h"
48 #include "chrome/browser/prefs/session_startup_pref.h"
49 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 48 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
50 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 49 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
51 #include "chrome/browser/printing/print_dialog_cloud.h" 50 #include "chrome/browser/printing/print_dialog_cloud.h"
52 #include "chrome/browser/profiles/profile.h" 51 #include "chrome/browser/profiles/profile.h"
53 #include "chrome/browser/profiles/profile_io_data.h" 52 #include "chrome/browser/profiles/profile_io_data.h"
54 #include "chrome/browser/profiles/profile_manager.h" 53 #include "chrome/browser/profiles/profile_manager.h"
55 #include "chrome/browser/search_engines/template_url.h" 54 #include "chrome/browser/search_engines/template_url.h"
56 #include "chrome/browser/search_engines/template_url_service.h" 55 #include "chrome/browser/search_engines/template_url_service.h"
57 #include "chrome/browser/search_engines/template_url_service_factory.h" 56 #include "chrome/browser/search_engines/template_url_service_factory.h"
58 #include "chrome/browser/sessions/session_restore.h" 57 #include "chrome/browser/sessions/session_restore.h"
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 behavior = SessionRestore::CLOBBER_CURRENT_TAB; 457 behavior = SessionRestore::CLOBBER_CURRENT_TAB;
459 } 458 }
460 SessionRestore::RestoreSession( 459 SessionRestore::RestoreSession(
461 profile_, browser, behavior, std::vector<GURL>()); 460 profile_, browser, behavior, std::vector<GURL>());
462 return true; 461 return true;
463 } 462 }
464 463
465 464
466 // Utility functions ---------------------------------------------------------- 465 // Utility functions ----------------------------------------------------------
467 466
468 SessionStartupPref GetSessionStartupPref(const CommandLine& command_line,
469 Profile* profile) {
470 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile);
471 if (command_line.HasSwitch(switches::kRestoreLastSession) ||
472 BrowserInit::WasRestarted()) {
473 pref.type = SessionStartupPref::LAST;
474 }
475 if (pref.type == SessionStartupPref::LAST &&
476 IncognitoModePrefs::ShouldLaunchIncognito(command_line,
477 profile->GetPrefs())) {
478 // We don't store session information when incognito. If the user has
479 // chosen to restore last session and launched incognito, fallback to
480 // default launch behavior.
481 pref.type = SessionStartupPref::DEFAULT;
482 }
483 return pref;
484 }
485
486 enum LaunchMode { 467 enum LaunchMode {
487 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut. 468 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut.
488 LM_AS_WEBAPP, // Launched as a installed web application. 469 LM_AS_WEBAPP, // Launched as a installed web application.
489 LM_WITH_URLS, // Launched with urls in the cmd line. 470 LM_WITH_URLS, // Launched with urls in the cmd line.
490 LM_SHORTCUT_NONE, // Not launched from a shortcut. 471 LM_SHORTCUT_NONE, // Not launched from a shortcut.
491 LM_SHORTCUT_NONAME, // Launched from shortcut but no name available. 472 LM_SHORTCUT_NONAME, // Launched from shortcut but no name available.
492 LM_SHORTCUT_UNKNOWN, // Launched from user-defined shortcut. 473 LM_SHORTCUT_UNKNOWN, // Launched from user-defined shortcut.
493 LM_SHORTCUT_QUICKLAUNCH, // Launched from the quick launch bar. 474 LM_SHORTCUT_QUICKLAUNCH, // Launched from the quick launch bar.
494 LM_SHORTCUT_DESKTOP, // Launched from a desktop shortcut. 475 LM_SHORTCUT_DESKTOP, // Launched from a desktop shortcut.
495 LM_SHORTCUT_STARTMENU, // Launched from start menu. 476 LM_SHORTCUT_STARTMENU, // Launched from start menu.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 721
741 if (!was_restarted_read) { 722 if (!was_restarted_read) {
742 PrefService* pref_service = g_browser_process->local_state(); 723 PrefService* pref_service = g_browser_process->local_state();
743 was_restarted = pref_service->GetBoolean(prefs::kWasRestarted); 724 was_restarted = pref_service->GetBoolean(prefs::kWasRestarted);
744 pref_service->SetBoolean(prefs::kWasRestarted, false); 725 pref_service->SetBoolean(prefs::kWasRestarted, false);
745 was_restarted_read = true; 726 was_restarted_read = true;
746 } 727 }
747 return was_restarted; 728 return was_restarted;
748 } 729 }
749 730
731 // static
732 SessionStartupPref BrowserInit::GetSessionStartupPref(
733 const CommandLine& command_line,
734 Profile* profile) {
735 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile);
736 if (command_line.HasSwitch(switches::kRestoreLastSession) ||
737 BrowserInit::WasRestarted()) {
738 pref.type = SessionStartupPref::LAST;
739 }
740 if (pref.type == SessionStartupPref::LAST &&
741 IncognitoModePrefs::ShouldLaunchIncognito(command_line,
742 profile->GetPrefs())) {
743 // We don't store session information when incognito. If the user has
744 // chosen to restore last session and launched incognito, fallback to
745 // default launch behavior.
746 pref.type = SessionStartupPref::DEFAULT;
747 }
748 return pref;
749 }
750
751
750 // BrowserInit::LaunchWithProfile::Tab ---------------------------------------- 752 // BrowserInit::LaunchWithProfile::Tab ----------------------------------------
751 753
752 BrowserInit::LaunchWithProfile::Tab::Tab() : is_app(false), is_pinned(true) {} 754 BrowserInit::LaunchWithProfile::Tab::Tab() : is_app(false), is_pinned(true) {}
753 755
754 BrowserInit::LaunchWithProfile::Tab::~Tab() {} 756 BrowserInit::LaunchWithProfile::Tab::~Tab() {}
755 757
756 758
757 // BrowserInit::LaunchWithProfile --------------------------------------------- 759 // BrowserInit::LaunchWithProfile ---------------------------------------------
758 760
759 BrowserInit::LaunchWithProfile::LaunchWithProfile( 761 BrowserInit::LaunchWithProfile::LaunchWithProfile(
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 IS_FIRST_RUN : IS_NOT_FIRST_RUN; 1681 IS_FIRST_RUN : IS_NOT_FIRST_RUN;
1680 // Launch the last used profile with the full command line, and the other 1682 // Launch the last used profile with the full command line, and the other
1681 // opened profiles without the URLs to launch. 1683 // opened profiles without the URLs to launch.
1682 CommandLine command_line_without_urls(command_line.GetProgram()); 1684 CommandLine command_line_without_urls(command_line.GetProgram());
1683 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); 1685 const CommandLine::SwitchMap& switches = command_line.GetSwitches();
1684 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); 1686 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin();
1685 switch_it != switches.end(); ++switch_it) { 1687 switch_it != switches.end(); ++switch_it) {
1686 command_line_without_urls.AppendSwitchNative(switch_it->first, 1688 command_line_without_urls.AppendSwitchNative(switch_it->first,
1687 switch_it->second); 1689 switch_it->second);
1688 } 1690 }
1689 if (!browser_init->LaunchBrowser(command_line, last_used_profile, cur_dir, 1691 // Launch the profiles in the order they became active.
1690 is_process_startup, is_first_run, return_code))
1691 return false;
1692 is_process_startup = BrowserInit::IS_NOT_PROCESS_STARTUP;
1693
1694 for (Profiles::const_iterator it = last_opened_profiles.begin(); 1692 for (Profiles::const_iterator it = last_opened_profiles.begin();
1695 it != last_opened_profiles.end(); ++it) { 1693 it != last_opened_profiles.end(); ++it) {
1696 if (*it != last_used_profile && 1694 if (*it == last_used_profile) {
Peter Kasting 2012/01/16 20:13:05 Nit: Shorter and (IMO) clearer: if (!browse
marja 2012/01/18 17:08:17 Done.
1697 !browser_init->LaunchBrowser(command_line_without_urls, *it, 1695 if (!browser_init->LaunchBrowser(command_line, *it, cur_dir,
1698 cur_dir, is_process_startup, is_first_run, return_code)) 1696 is_process_startup, is_first_run, return_code))
1699 return false; 1697 return false;
1698 } else {
1699 if (!browser_init->LaunchBrowser(command_line_without_urls, *it,
1700 cur_dir, is_process_startup, is_first_run, return_code))
1701 return false;
1702 }
1703 // We've started at least one browser.
1704 is_process_startup = BrowserInit::IS_NOT_PROCESS_STARTUP;
1700 } 1705 }
1701 } 1706 }
1702 return true; 1707 return true;
1703 } 1708 }
1704 1709
1705 template <class AutomationProviderClass> 1710 template <class AutomationProviderClass>
1706 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, 1711 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id,
1707 Profile* profile, 1712 Profile* profile,
1708 size_t expected_tabs) { 1713 size_t expected_tabs) {
1709 scoped_refptr<AutomationProviderClass> automation = 1714 scoped_refptr<AutomationProviderClass> automation =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 1751
1747 Profile* profile = ProfileManager::GetLastUsedProfile(); 1752 Profile* profile = ProfileManager::GetLastUsedProfile();
1748 if (!profile) { 1753 if (!profile) {
1749 // We should only be able to get here if the profile already exists and 1754 // We should only be able to get here if the profile already exists and
1750 // has been created. 1755 // has been created.
1751 NOTREACHED(); 1756 NOTREACHED();
1752 return; 1757 return;
1753 } 1758 }
1754 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); 1759 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL);
1755 } 1760 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_init.h ('k') | chrome/browser/ui/browser_init_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698