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

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: Code review. 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 615
635 } // namespace 616 } // namespace
636 617
637 618
638 // BrowserInit ---------------------------------------------------------------- 619 // BrowserInit ----------------------------------------------------------------
639 620
640 BrowserInit::BrowserInit() {} 621 BrowserInit::BrowserInit() {}
641 622
642 BrowserInit::~BrowserInit() {} 623 BrowserInit::~BrowserInit() {}
643 624
625 // static
626 bool BrowserInit::was_restarted_read_ = false;
627
644 void BrowserInit::AddFirstRunTab(const GURL& url) { 628 void BrowserInit::AddFirstRunTab(const GURL& url) {
645 first_run_tabs_.push_back(url); 629 first_run_tabs_.push_back(url);
646 } 630 }
647 631
648 // static 632 // static
649 bool BrowserInit::InProcessStartup() { 633 bool BrowserInit::InProcessStartup() {
650 return in_startup; 634 return in_startup;
651 } 635 }
652 636
653 // static 637 // static
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 } 712 }
729 #endif 713 #endif
730 return true; 714 return true;
731 } 715 }
732 716
733 // static 717 // static
734 bool BrowserInit::WasRestarted() { 718 bool BrowserInit::WasRestarted() {
735 // Stores the value of the preference kWasRestarted had when it was read. 719 // Stores the value of the preference kWasRestarted had when it was read.
736 static bool was_restarted = false; 720 static bool was_restarted = false;
737 721
738 // True if we have already read and reset the preference kWasRestarted. 722 if (!was_restarted_read_) {
739 static bool was_restarted_read = false;
740
741 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 (!browser_init->LaunchBrowser((*it == last_used_profile) ?
1697 !browser_init->LaunchBrowser(command_line_without_urls, *it, 1695 command_line : command_line_without_urls, *it, cur_dir,
1698 cur_dir, is_process_startup, is_first_run, return_code)) 1696 is_process_startup, is_first_run, return_code))
1697 return false;
1698 // We've launched at least one browser.
1699 is_process_startup = BrowserInit::IS_NOT_PROCESS_STARTUP;
1700 }
1701 // If this is the first launch, there are no last used or last opened
1702 // profiles. In that case, |last_used_profile| will be the initial profile
1703 // and |last_opened_profiles| will be empty. Launch the initial profile in
1704 // that case.
1705 if (last_opened_profiles.empty()) {
Peter Kasting 2012/01/18 18:04:30 Nit: We might also want to DCHECK(is_first_run) in
marja 2012/01/19 08:38:23 Done.
marja 2012/01/19 10:27:02 Oops, I was wrong. The "first run" is not the only
1706 if (!browser_init->LaunchBrowser(command_line, last_used_profile, cur_dir,
1707 is_process_startup, is_first_run, return_code))
1699 return false; 1708 return false;
1700 } 1709 }
1701 } 1710 }
1702 return true; 1711 return true;
1703 } 1712 }
1704 1713
1705 template <class AutomationProviderClass> 1714 template <class AutomationProviderClass>
1706 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, 1715 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id,
1707 Profile* profile, 1716 Profile* profile,
1708 size_t expected_tabs) { 1717 size_t expected_tabs) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 1755
1747 Profile* profile = ProfileManager::GetLastUsedProfile(); 1756 Profile* profile = ProfileManager::GetLastUsedProfile();
1748 if (!profile) { 1757 if (!profile) {
1749 // We should only be able to get here if the profile already exists and 1758 // We should only be able to get here if the profile already exists and
1750 // has been created. 1759 // has been created.
1751 NOTREACHED(); 1760 NOTREACHED();
1752 return; 1761 return;
1753 } 1762 }
1754 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); 1763 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL);
1755 } 1764 }
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