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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_impl.cc

Issue 10690060: startup: Put it in chrome namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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/startup/startup_browser_creator_impl.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 extension_misc::APP_LAUNCH_AUTOLAUNCH); 222 extension_misc::APP_LAUNCH_AUTOLAUNCH);
223 } 223 }
224 } 224 }
225 } 225 }
226 226
227 } // namespace 227 } // namespace
228 228
229 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( 229 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl(
230 const FilePath& cur_dir, 230 const FilePath& cur_dir,
231 const CommandLine& command_line, 231 const CommandLine& command_line,
232 browser::startup::IsFirstRun is_first_run) 232 chrome::startup::IsFirstRun is_first_run)
233 : cur_dir_(cur_dir), 233 : cur_dir_(cur_dir),
234 command_line_(command_line), 234 command_line_(command_line),
235 profile_(NULL), 235 profile_(NULL),
236 browser_creator_(NULL), 236 browser_creator_(NULL),
237 is_first_run_(is_first_run == browser::startup::IS_FIRST_RUN) { 237 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) {
238 } 238 }
239 239
240 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( 240 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl(
241 const FilePath& cur_dir, 241 const FilePath& cur_dir,
242 const CommandLine& command_line, 242 const CommandLine& command_line,
243 StartupBrowserCreator* browser_creator, 243 StartupBrowserCreator* browser_creator,
244 browser::startup::IsFirstRun is_first_run) 244 chrome::startup::IsFirstRun is_first_run)
245 : cur_dir_(cur_dir), 245 : cur_dir_(cur_dir),
246 command_line_(command_line), 246 command_line_(command_line),
247 profile_(NULL), 247 profile_(NULL),
248 browser_creator_(browser_creator), 248 browser_creator_(browser_creator),
249 is_first_run_(is_first_run == browser::startup::IS_FIRST_RUN) { 249 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) {
250 } 250 }
251 251
252 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { 252 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() {
253 } 253 }
254 254
255 bool StartupBrowserCreatorImpl::Launch(Profile* profile, 255 bool StartupBrowserCreatorImpl::Launch(Profile* profile,
256 const std::vector<GURL>& urls_to_open, 256 const std::vector<GURL>& urls_to_open,
257 bool process_startup) { 257 bool process_startup) {
258 DCHECK(profile); 258 DCHECK(profile);
259 profile_ = profile; 259 profile_ = profile;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // opened an app shortcut. Don't restore tabs or open initial 293 // opened an app shortcut. Don't restore tabs or open initial
294 // URLs in that case. The user should see the window as an app, 294 // URLs in that case. The user should see the window as an app,
295 // not as chrome. 295 // not as chrome.
296 // Special case is when app switches are passed but we do want to restore 296 // Special case is when app switches are passed but we do want to restore
297 // session. In that case open app window + focus it after session is restored. 297 // session. In that case open app window + focus it after session is restored.
298 content::WebContents* app_contents = NULL; 298 content::WebContents* app_contents = NULL;
299 if (OpenApplicationWindow(profile, &app_contents) && 299 if (OpenApplicationWindow(profile, &app_contents) &&
300 !browser_defaults::kAppRestoreSession) { 300 !browser_defaults::kAppRestoreSession) {
301 RecordLaunchModeHistogram(LM_AS_WEBAPP); 301 RecordLaunchModeHistogram(LM_AS_WEBAPP);
302 } else { 302 } else {
303 RecordLaunchModeHistogram(urls_to_open.empty()? 303 RecordLaunchModeHistogram(urls_to_open.empty() ?
304 LM_TO_BE_DECIDED : LM_WITH_URLS); 304 LM_TO_BE_DECIDED : LM_WITH_URLS);
305 305
306 // Notify user if the Preferences backup is invalid or changes to settings 306 // Notify user if the Preferences backup is invalid or changes to settings
307 // affecting browser startup have been detected. 307 // affecting browser startup have been detected.
308 CheckPreferencesBackup(profile); 308 CheckPreferencesBackup(profile);
309 309
310 ProcessLaunchURLs(process_startup, urls_to_open); 310 ProcessLaunchURLs(process_startup, urls_to_open);
311 311
312 // If this is an app launch, but we didn't open an app window, it may 312 // If this is an app launch, but we didn't open an app window, it may
313 // be an app tab. 313 // be an app tab.
314 OpenApplicationTab(profile); 314 OpenApplicationTab(profile);
315 315
316 // In case of app mode + session restore we want to focus that app. 316 // In case of app mode + session restore we want to focus that app.
317 if (browser_defaults::kAppRestoreSession && app_contents) 317 if (browser_defaults::kAppRestoreSession && app_contents)
318 app_contents->GetView()->SetInitialFocus(); 318 app_contents->GetView()->SetInitialFocus();
319 319
320 if (process_startup) { 320 if (process_startup) {
321 if (browser_defaults::kOSSupportsOtherBrowsers && 321 if (browser_defaults::kOSSupportsOtherBrowsers &&
322 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { 322 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) {
323 if (!browser::ShowAutolaunchPrompt(profile)) 323 if (!chrome::ShowAutolaunchPrompt(profile))
324 browser::ShowDefaultBrowserPrompt(profile); 324 chrome::ShowDefaultBrowserPrompt(profile);
325 } 325 }
326 #if defined(OS_MACOSX) 326 #if defined(OS_MACOSX)
327 // Check whether the auto-update system needs to be promoted from user 327 // Check whether the auto-update system needs to be promoted from user
328 // to system. 328 // to system.
329 KeystoneInfoBar::PromotionInfoBar(profile); 329 KeystoneInfoBar::PromotionInfoBar(profile);
330 #endif 330 #endif
331 } 331 }
332 } 332 }
333 333
334 // If we're recording or playing back, startup the EventRecorder now 334 // If we're recording or playing back, startup the EventRecorder now
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 command_line_.HasSwitch(switches::kNoStartupWindow) && 482 command_line_.HasSwitch(switches::kNoStartupWindow) &&
483 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) { 483 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) {
484 return; 484 return;
485 } 485 }
486 486
487 if (process_startup && ProcessStartupURLs(urls_to_open)) { 487 if (process_startup && ProcessStartupURLs(urls_to_open)) {
488 // ProcessStartupURLs processed the urls, nothing else to do. 488 // ProcessStartupURLs processed the urls, nothing else to do.
489 return; 489 return;
490 } 490 }
491 491
492 browser::startup::IsProcessStartup is_process_startup = process_startup ? 492 chrome::startup::IsProcessStartup is_process_startup = process_startup ?
493 browser::startup::IS_PROCESS_STARTUP : 493 chrome::startup::IS_PROCESS_STARTUP :
494 browser::startup::IS_NOT_PROCESS_STARTUP; 494 chrome::startup::IS_NOT_PROCESS_STARTUP;
495 if (!process_startup) { 495 if (!process_startup) {
496 // Even if we're not starting a new process, this may conceptually be 496 // Even if we're not starting a new process, this may conceptually be
497 // "startup" for the user and so should be handled in a similar way. Eg., 497 // "startup" for the user and so should be handled in a similar way. Eg.,
498 // Chrome may have been running in the background due to an app with a 498 // Chrome may have been running in the background due to an app with a
499 // background page being installed, or running with only an app window 499 // background page being installed, or running with only an app window
500 // displayed. 500 // displayed.
501 SessionService* service = SessionServiceFactory::GetForProfile(profile_); 501 SessionService* service = SessionServiceFactory::GetForProfile(profile_);
502 if (service && service->ShouldNewWindowStartSession()) { 502 if (service && service->ShouldNewWindowStartSession()) {
503 // Restore the last session if any. 503 // Restore the last session if any.
504 if (!HasPendingUncleanExit(profile_) && 504 if (!HasPendingUncleanExit(profile_) &&
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { 562 if (base::mac::WasLaunchedAsLoginOrResumeItem()) {
563 restore_behavior = restore_behavior & 563 restore_behavior = restore_behavior &
564 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; 564 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER;
565 } 565 }
566 #endif 566 #endif
567 567
568 Browser* browser = SessionRestore::RestoreSession(profile_, 568 Browser* browser = SessionRestore::RestoreSession(profile_,
569 NULL, 569 NULL,
570 restore_behavior, 570 restore_behavior,
571 urls_to_open); 571 urls_to_open);
572 AddInfoBarsIfNecessary(browser, browser::startup::IS_PROCESS_STARTUP); 572 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP);
573 return true; 573 return true;
574 } 574 }
575 575
576 Browser* browser = ProcessSpecifiedURLs(urls_to_open); 576 Browser* browser = ProcessSpecifiedURLs(urls_to_open);
577 if (!browser) 577 if (!browser)
578 return false; 578 return false;
579 579
580 AddInfoBarsIfNecessary(browser, browser::startup::IS_PROCESS_STARTUP); 580 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP);
581 return true; 581 return true;
582 } 582 }
583 583
584 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( 584 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs(
585 const std::vector<GURL>& urls_to_open) { 585 const std::vector<GURL>& urls_to_open) {
586 SessionStartupPref pref = 586 SessionStartupPref pref =
587 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); 587 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_);
588 StartupTabs tabs; 588 StartupTabs tabs;
589 // Pinned tabs should not be displayed when chrome is launched in incognito 589 // Pinned tabs should not be displayed when chrome is launched in incognito
590 // mode. Also, no pages should be opened automatically if the session 590 // mode. Also, no pages should be opened automatically if the session
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 browser->window()->Show(); 722 browser->window()->Show();
723 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial 723 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial
724 // focus explicitly. 724 // focus explicitly.
725 chrome::GetActiveWebContents(browser)->GetView()->SetInitialFocus(); 725 chrome::GetActiveWebContents(browser)->GetView()->SetInitialFocus();
726 726
727 return browser; 727 return browser;
728 } 728 }
729 729
730 void StartupBrowserCreatorImpl::AddInfoBarsIfNecessary( 730 void StartupBrowserCreatorImpl::AddInfoBarsIfNecessary(
731 Browser* browser, 731 Browser* browser,
732 browser::startup::IsProcessStartup is_process_startup) { 732 chrome::startup::IsProcessStartup is_process_startup) {
733 if (!browser || !profile_ || browser->tab_count() == 0) 733 if (!browser || !profile_ || browser->tab_count() == 0)
734 return; 734 return;
735 735
736 if (HasPendingUncleanExit(browser->profile())) 736 if (HasPendingUncleanExit(browser->profile()))
737 browser::ShowSessionCrashedPrompt(browser); 737 chrome::ShowSessionCrashedPrompt(browser);
738 738
739 // The bad flags info bar and the obsolete system info bar are only added to 739 // The bad flags info bar and the obsolete system info bar are only added to
740 // the first profile which is launched. Other profiles might be restoring the 740 // the first profile which is launched. Other profiles might be restoring the
741 // browsing sessions asynchronously, so we cannot add the info bars to the 741 // browsing sessions asynchronously, so we cannot add the info bars to the
742 // focused tabs here. 742 // focused tabs here.
743 if (is_process_startup == browser::startup::IS_PROCESS_STARTUP) { 743 if (is_process_startup == chrome::startup::IS_PROCESS_STARTUP) {
744 browser::ShowBadFlagsPrompt(browser); 744 chrome::ShowBadFlagsPrompt(browser);
745 browser::ShowObsoleteOSPrompt(browser); 745 chrome::ShowObsoleteOSPrompt(browser);
746 } 746 }
747 } 747 }
748 748
749 749
750 void StartupBrowserCreatorImpl::AddStartupURLs( 750 void StartupBrowserCreatorImpl::AddStartupURLs(
751 std::vector<GURL>* startup_urls) const { 751 std::vector<GURL>* startup_urls) const {
752 // If we have urls specified by the first run master preferences use them 752 // If we have urls specified by the first run master preferences use them
753 // and nothing else. 753 // and nothing else.
754 if (browser_creator_ && startup_urls->empty()) { 754 if (browser_creator_ && startup_urls->empty()) {
755 if (!browser_creator_->first_run_tabs_.empty()) { 755 if (!browser_creator_->first_run_tabs_.empty()) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 // New: 861 // New:
862 prefs->GetString(prefs::kHomePage), 862 prefs->GetString(prefs::kHomePage),
863 prefs->GetBoolean(prefs::kHomePageIsNewTabPage), 863 prefs->GetBoolean(prefs::kHomePageIsNewTabPage),
864 prefs->GetBoolean(prefs::kShowHomeButton), 864 prefs->GetBoolean(prefs::kShowHomeButton),
865 // Backup: 865 // Backup:
866 backup_homepage, 866 backup_homepage,
867 backup_homepage_is_ntp, 867 backup_homepage_is_ntp,
868 backup_show_home_button)); 868 backup_show_home_button));
869 } 869 }
870 } 870 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.h ('k') | chrome/browser/ui/startup/startup_browser_creator_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698