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

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

Issue 9972012: Resolve the conflict that auto-launch has with the background mode feature (part 1). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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/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 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // Track infobar reponse. 251 // Track infobar reponse.
252 auto_launch_trial::UpdateInfobarResponseMetric( 252 auto_launch_trial::UpdateInfobarResponseMetric(
253 auto_launch_trial::INFOBAR_CUT_IT_OUT); 253 auto_launch_trial::INFOBAR_CUT_IT_OUT);
254 // Also make sure we keep track of how many disable and how many enable. 254 // Also make sure we keep track of how many disable and how many enable.
255 const bool auto_launch = false; 255 const bool auto_launch = false;
256 auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch); 256 auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch);
257 257
258 content::BrowserThread::PostTask( 258 content::BrowserThread::PostTask(
259 content::BrowserThread::FILE, FROM_HERE, 259 content::BrowserThread::FILE, FROM_HERE,
260 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, 260 base::Bind(&auto_launch_util::SetWillLaunchAtLogin,
261 auto_launch,
262 FilePath(), 261 FilePath(),
263 profile_->GetPath().BaseName().value())); 262 profile_->GetPath().BaseName().value(),
263 auto_launch ? auto_launch_util::FLAG_ENABLE : // Auto-launch.
264 auto_launch_util::FLAG_DISABLE,
265 auto_launch_util::FLAG_PRESERVE)); // Background mode.
264 return true; 266 return true;
265 } 267 }
266 268
267 // Metro driver export, this is how metro passes the initial navigated url 269 // Metro driver export, this is how metro passes the initial navigated url
268 // back to us. 270 // back to us.
269 extern "C" { 271 extern "C" {
270 typedef const wchar_t* (*GetInitialUrl)(); 272 typedef const wchar_t* (*GetInitialUrl)();
271 } 273 }
272 274
273 275
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 371
370 bool DefaultBrowserInfoBarDelegate::Cancel() { 372 bool DefaultBrowserInfoBarDelegate::Cancel() {
371 action_taken_ = true; 373 action_taken_ = true;
372 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); 374 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1);
373 // User clicked "Don't ask me again", remember that. 375 // User clicked "Don't ask me again", remember that.
374 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); 376 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false);
375 return true; 377 return true;
376 } 378 }
377 379
378 #if defined(OS_WIN) 380 #if defined(OS_WIN)
379 void CheckAutoLaunchCallback() { 381 void CheckAutoLaunchCallback(Profile* profile) {
380 if (!auto_launch_trial::IsInAutoLaunchGroup()) 382 if (!auto_launch_trial::IsInAutoLaunchGroup())
381 return; 383 return;
382 384
383 Browser* browser = BrowserList::GetLastActive(); 385 // We must not use GetLastActive here because this is at Chrome startup and
386 // no window might have been made active yet. We'll settle for any window.
387 Browser* browser = BrowserList::FindAnyBrowser(profile, true);
384 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); 388 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper();
385 389
386 // Don't show the info-bar if there are already info-bars showing. 390 // Don't show the info-bar if there are already info-bars showing.
387 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); 391 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
388 if (infobar_helper->infobar_count() > 0) 392 if (infobar_helper->infobar_count() > 0)
389 return; 393 return;
390 394
391 infobar_helper->AddInfoBar( 395 infobar_helper->AddInfoBar(
392 new AutolaunchInfoBarDelegate(infobar_helper, 396 new AutolaunchInfoBarDelegate(infobar_helper,
393 tab->profile()->GetPrefs(), tab->profile())); 397 tab->profile()->GetPrefs(), tab->profile()));
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 return (app_tab != NULL); 1070 return (app_tab != NULL);
1067 } 1071 }
1068 } 1072 }
1069 return false; 1073 return false;
1070 } 1074 }
1071 1075
1072 void BrowserInit::LaunchWithProfile::ProcessLaunchURLs( 1076 void BrowserInit::LaunchWithProfile::ProcessLaunchURLs(
1073 bool process_startup, 1077 bool process_startup,
1074 const std::vector<GURL>& urls_to_open) { 1078 const std::vector<GURL>& urls_to_open) {
1075 // If we're starting up in "background mode" (no open browser window) then 1079 // If we're starting up in "background mode" (no open browser window) then
1076 // don't open any browser windows. 1080 // don't open any browser windows, unless kAutoLaunchAtStartup is also
1077 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow)) 1081 // specified.
1082 if (process_startup &&
1083 command_line_.HasSwitch(switches::kNoStartupWindow) &&
1084 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) {
1078 return; 1085 return;
1086 }
1079 1087
1080 if (process_startup && ProcessStartupURLs(urls_to_open)) { 1088 if (process_startup && ProcessStartupURLs(urls_to_open)) {
1081 // ProcessStartupURLs processed the urls, nothing else to do. 1089 // ProcessStartupURLs processed the urls, nothing else to do.
1082 return; 1090 return;
1083 } 1091 }
1084 1092
1085 IsProcessStartup is_process_startup = process_startup ? 1093 IsProcessStartup is_process_startup = process_startup ?
1086 IS_PROCESS_STARTUP : IS_NOT_PROCESS_STARTUP; 1094 IS_PROCESS_STARTUP : IS_NOT_PROCESS_STARTUP;
1087 if (!process_startup) { 1095 if (!process_startup) {
1088 // Even if we're not starting a new process, this may conceptually be 1096 // Even if we're not starting a new process, this may conceptually be
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 if (infobar_shown >= kMaxInfobarShown) 1571 if (infobar_shown >= kMaxInfobarShown)
1564 return false; 1572 return false;
1565 1573
1566 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 1574 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1567 if (command_line.HasSwitch(switches::kChromeFrame)) 1575 if (command_line.HasSwitch(switches::kChromeFrame))
1568 return false; 1576 return false;
1569 1577
1570 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) || 1578 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) ||
1571 first_run::IsChromeFirstRun()) { 1579 first_run::IsChromeFirstRun()) {
1572 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1580 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1573 base::Bind(&CheckAutoLaunchCallback)); 1581 base::Bind(&CheckAutoLaunchCallback, profile));
1574 return true; 1582 return true;
1575 } 1583 }
1576 #endif 1584 #endif
1577 return false; 1585 return false;
1578 } 1586 }
1579 1587
1580 void BrowserInit::LaunchWithProfile::CheckPreferencesBackup(Profile* profile) { 1588 void BrowserInit::LaunchWithProfile::CheckPreferencesBackup(Profile* profile) {
1581 ProtectorService* protector_service = 1589 ProtectorService* protector_service =
1582 ProtectorServiceFactory::GetForProfile(profile); 1590 ProtectorServiceFactory::GetForProfile(profile);
1583 ProtectedPrefsWatcher* prefs_watcher = protector_service->GetPrefsWatcher(); 1591 ProtectedPrefsWatcher* prefs_watcher = protector_service->GetPrefsWatcher();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 // Look for the testing channel ID ONLY during process startup 1722 // Look for the testing channel ID ONLY during process startup
1715 if (process_startup && 1723 if (process_startup &&
1716 command_line.HasSwitch(switches::kTestingChannelID)) { 1724 command_line.HasSwitch(switches::kTestingChannelID)) {
1717 std::string testing_channel_id = command_line.GetSwitchValueASCII( 1725 std::string testing_channel_id = command_line.GetSwitchValueASCII(
1718 switches::kTestingChannelID); 1726 switches::kTestingChannelID);
1719 // TODO(sanjeevr) Check if we need to make this a singleton for 1727 // TODO(sanjeevr) Check if we need to make this a singleton for
1720 // compatibility with the old testing code 1728 // compatibility with the old testing code
1721 // If there are any extra parameters, we expect each one to generate a 1729 // If there are any extra parameters, we expect each one to generate a
1722 // new tab; if there are none then we get one homepage tab. 1730 // new tab; if there are none then we get one homepage tab.
1723 int expected_tab_count = 1; 1731 int expected_tab_count = 1;
1724 if (command_line.HasSwitch(switches::kNoStartupWindow)) { 1732 if (command_line.HasSwitch(switches::kNoStartupWindow) &&
1733 !command_line.HasSwitch(switches::kAutoLaunchAtStartup)) {
1725 expected_tab_count = 0; 1734 expected_tab_count = 0;
1726 #if defined(OS_CHROMEOS) 1735 #if defined(OS_CHROMEOS)
1727 // kLoginManager will cause Chrome to start up with the ChromeOS login 1736 // kLoginManager will cause Chrome to start up with the ChromeOS login
1728 // screen instead of a browser window, so it won't load any tabs. 1737 // screen instead of a browser window, so it won't load any tabs.
1729 } else if (command_line.HasSwitch(switches::kLoginManager)) { 1738 } else if (command_line.HasSwitch(switches::kLoginManager)) {
1730 expected_tab_count = 0; 1739 expected_tab_count = 0;
1731 #endif 1740 #endif
1732 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { 1741 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) {
1733 std::string restore_session_value( 1742 std::string restore_session_value(
1734 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); 1743 command_line.GetSwitchValueASCII(switches::kRestoreLastSession));
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 1941
1933 Profile* profile = ProfileManager::GetLastUsedProfile(); 1942 Profile* profile = ProfileManager::GetLastUsedProfile();
1934 if (!profile) { 1943 if (!profile) {
1935 // We should only be able to get here if the profile already exists and 1944 // We should only be able to get here if the profile already exists and
1936 // has been created. 1945 // has been created.
1937 NOTREACHED(); 1946 NOTREACHED();
1938 return; 1947 return;
1939 } 1948 }
1940 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); 1949 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL);
1941 } 1950 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698