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

Side by Side Diff: chrome/browser/browser_main.cc

Issue 1368001: Move a few more things out of BrowserMain into helper functions.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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 | « no previous file | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser_main.h" 5 #include "chrome/browser/browser_main.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/hi_res_timer_manager.h" 9 #include "app/hi_res_timer_manager.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); 475 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled);
476 metrics->SetUserPermitsUpload(enabled); 476 metrics->SetUserPermitsUpload(enabled);
477 if (enabled) 477 if (enabled)
478 metrics->Start(); 478 metrics->Start();
479 #endif 479 #endif
480 } 480 }
481 481
482 return metrics; 482 return metrics;
483 } 483 }
484 484
485 // Initializes the profile, possibly doing some user prompting to pick a
486 // fallback profile. Returns the newly created profile, or NULL if startup
487 // should not continue.
488 Profile* CreateProfile(const MainFunctionParams& parameters,
489 const FilePath& user_data_dir) {
490 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(
491 user_data_dir);
492 if (profile)
493 return profile;
494
495 #if defined(OS_WIN)
496 // Ideally, we should be able to run w/o access to disk. For now, we
497 // prompt the user to pick a different user-data-dir and restart chrome
498 // with the new dir.
499 // http://code.google.com/p/chromium/issues/detail?id=11510
500 FilePath new_user_data_dir = UserDataDirDialog::RunUserDataDirDialog(
501 user_data_dir);
502 if (!parameters.ui_task && browser_shutdown::delete_resources_on_shutdown) {
503 // Only delete the resources if we're not running tests. If we're running
504 // tests the resources need to be reused as many places in the UI cache
505 // SkBitmaps from the ResourceBundle.
506 ResourceBundle::CleanupSharedInstance();
507 }
508
509 if (!new_user_data_dir.empty()) {
510 // Because of the way CommandLine parses, it's sufficient to append a new
511 // --user-data-dir switch. The last flag of the same name wins.
512 // TODO(tc): It would be nice to remove the flag we don't want, but that
513 // sounds risky if we parse differently than CommandLineToArgvW.
514 CommandLine new_command_line = parameters.command_line_;
515 new_command_line.AppendSwitchWithValue(switches::kUserDataDir,
516 new_user_data_dir.ToWStringHack());
517 base::LaunchApp(new_command_line, false, false, NULL);
518 }
519 #else
520 // TODO(port): fix this. See comments near the definition of
521 // user_data_dir. It is better to CHECK-fail here than it is to
522 // silently exit because of missing code in the above test.
523 CHECK(profile) << "Cannot get default profile.";
524 #endif
525
526 return NULL;
527 }
528
485 #if defined(OS_WIN) 529 #if defined(OS_WIN)
486 530
487 // gfx::Font callbacks 531 // gfx::Font callbacks
488 void AdjustUIFont(LOGFONT* logfont) { 532 void AdjustUIFont(LOGFONT* logfont) {
489 l10n_util::AdjustUIFont(logfont); 533 l10n_util::AdjustUIFont(logfont);
490 } 534 }
491 535
492 int GetMinimumFontSize() { 536 int GetMinimumFontSize() {
493 return StringToInt(l10n_util::GetString(IDS_MINIMUM_UI_FONT_SIZE).c_str()); 537 return StringToInt(l10n_util::GetString(IDS_MINIMUM_UI_FONT_SIZE).c_str());
494 } 538 }
495 539
496 #endif 540 #endif
497 541
498 #if defined(TOOLKIT_GTK) 542 #if defined(TOOLKIT_GTK)
499 void InitializeToolkit() { 543 void InitializeToolkit() {
500 // It is important for this to happen before the first run dialog, as it 544 // It is important for this to happen before the first run dialog, as it
501 // styles the dialog as well. 545 // styles the dialog as well.
502 gtk_util::InitRCStyles(); 546 gtk_util::InitRCStyles();
503 } 547 }
504 #elif defined(TOOLKIT_VIEWS) 548 #elif defined(TOOLKIT_VIEWS)
505 void InitializeToolkit() { 549 void InitializeToolkit() {
506 // The delegate needs to be set before any UI is created so that windows 550 // The delegate needs to be set before any UI is created so that windows
507 // display the correct icon. 551 // display the correct icon.
508 if (!views::ViewsDelegate::views_delegate) 552 if (!views::ViewsDelegate::views_delegate)
509 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; 553 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate;
510 554
511 #if defined(OS_WIN) 555 #if defined(OS_WIN)
512 gfx::Font::adjust_font_callback = &AdjustUIFont; 556 gfx::Font::adjust_font_callback = &AdjustUIFont;
513 gfx::Font::get_minimum_font_size_callback = &GetMinimumFontSize; 557 gfx::Font::get_minimum_font_size_callback = &GetMinimumFontSize;
558
559 // Init common control sex.
560 INITCOMMONCONTROLSEX config;
561 config.dwSize = sizeof(config);
562 config.dwICC = ICC_WIN95_CLASSES;
563 InitCommonControlsEx(&config);
514 #endif 564 #endif
515 } 565 }
516 #else 566 #else
517 void InitializeToolkit() { 567 void InitializeToolkit() {
518 } 568 }
519 #endif 569 #endif
520 570
521 #if defined(OS_CHROMEOS) 571 #if defined(OS_CHROMEOS)
522 void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line) { 572 void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line) {
523 if (parsed_command_line.HasSwitch(switches::kLoginManager)) { 573 if (parsed_command_line.HasSwitch(switches::kLoginManager)) {
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 #endif 883 #endif
834 884
835 if (parsed_command_line.HasSwitch(switches::kHideIcons) || 885 if (parsed_command_line.HasSwitch(switches::kHideIcons) ||
836 parsed_command_line.HasSwitch(switches::kShowIcons)) 886 parsed_command_line.HasSwitch(switches::kShowIcons))
837 return HandleIconsCommands(parsed_command_line); 887 return HandleIconsCommands(parsed_command_line);
838 if (parsed_command_line.HasSwitch(switches::kMakeDefaultBrowser)) { 888 if (parsed_command_line.HasSwitch(switches::kMakeDefaultBrowser)) {
839 return ShellIntegration::SetAsDefaultBrowser() ? 889 return ShellIntegration::SetAsDefaultBrowser() ?
840 ResultCodes::NORMAL_EXIT : ResultCodes::SHELL_INTEGRATION_FAILED; 890 ResultCodes::NORMAL_EXIT : ResultCodes::SHELL_INTEGRATION_FAILED;
841 } 891 }
842 892
843 // Try to create/load the profile.
844 ProfileManager* profile_manager = browser_process->profile_manager();
845 #if defined(OS_CHROMEOS) 893 #if defined(OS_CHROMEOS)
846 if (parsed_command_line.HasSwitch(switches::kLoginUser)) { 894 if (parsed_command_line.HasSwitch(switches::kLoginUser)) {
847 std::string username = 895 std::string username =
848 parsed_command_line.GetSwitchValueASCII(switches::kLoginUser); 896 parsed_command_line.GetSwitchValueASCII(switches::kLoginUser);
849 LOG(INFO) << "Relaunching browser for user: " << username; 897 LOG(INFO) << "Relaunching browser for user: " << username;
850 chromeos::UserManager::Get()->UserLoggedIn(username); 898 chromeos::UserManager::Get()->UserLoggedIn(username);
851 } 899 }
852 #endif 900 #endif
853 901
854 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); 902 // Profile creation ----------------------------------------------------------
855 903
856 #if defined(OS_WIN) 904 Profile* profile = CreateProfile(parameters, user_data_dir);
857 if (!profile) { 905 if (!profile)
858 // Ideally, we should be able to run w/o access to disk. For now, we 906 return ResultCodes::NORMAL_EXIT;
859 // prompt the user to pick a different user-data-dir and restart chrome
860 // with the new dir.
861 // http://code.google.com/p/chromium/issues/detail?id=11510
862 user_data_dir = UserDataDirDialog::RunUserDataDirDialog(user_data_dir);
863 if (!parameters.ui_task && browser_shutdown::delete_resources_on_shutdown) {
864 // Only delete the resources if we're not running tests. If we're running
865 // tests the resources need to be reused as many places in the UI cache
866 // SkBitmaps from the ResourceBundle.
867 ResourceBundle::CleanupSharedInstance();
868 }
869 907
870 if (!user_data_dir.empty()) { 908 // Post-profile init ---------------------------------------------------------
871 // Because of the way CommandLine parses, it's sufficient to append a new
872 // --user-data-dir switch. The last flag of the same name wins.
873 // TODO(tc): It would be nice to remove the flag we don't want, but that
874 // sounds risky if we parse differently than CommandLineToArgvW.
875 CommandLine new_command_line = parsed_command_line;
876 new_command_line.AppendSwitchWithValue(switches::kUserDataDir,
877 user_data_dir.ToWStringHack());
878 base::LaunchApp(new_command_line, false, false, NULL);
879 }
880
881 return ResultCodes::NORMAL_EXIT;
882 }
883 #else
884 // TODO(port): fix this. See comments near the definition of
885 // user_data_dir. It is better to CHECK-fail here than it is to
886 // silently exit because of missing code in the above test.
887 CHECK(profile) << "Cannot get default profile.";
888 #endif
889 909
890 PrefService* user_prefs = profile->GetPrefs(); 910 PrefService* user_prefs = profile->GetPrefs();
891 DCHECK(user_prefs); 911 DCHECK(user_prefs);
892 912
893 OptionallyRunChromeOSLoginManager(parsed_command_line); 913 OptionallyRunChromeOSLoginManager(parsed_command_line);
894 914
895 // Importing other browser settings is done in a browser-like process 915 // Importing other browser settings is done in a browser-like process
896 // that exits when this task has finished. 916 // that exits when this task has finished.
897 #if defined(OS_WIN) 917 #if defined(OS_WIN)
898 if (parsed_command_line.HasSwitch(switches::kImport) || 918 if (parsed_command_line.HasSwitch(switches::kImport) ||
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 // Sets things up so that if we crash from this point on, a dialog will 993 // Sets things up so that if we crash from this point on, a dialog will
974 // popup asking the user to restart chrome. It is done this late to avoid 994 // popup asking the user to restart chrome. It is done this late to avoid
975 // testing against a bunch of special cases that are taken care early on. 995 // testing against a bunch of special cases that are taken care early on.
976 PrepareRestartOnCrashEnviroment(parsed_command_line); 996 PrepareRestartOnCrashEnviroment(parsed_command_line);
977 997
978 // Initialize and maintain DNS prefetcher module. Also registers an observer 998 // Initialize and maintain DNS prefetcher module. Also registers an observer
979 // to clear the host cache when closing incognito mode. 999 // to clear the host cache when closing incognito mode.
980 chrome_browser_net::DnsGlobalInit dns_prefetch(user_prefs, local_state); 1000 chrome_browser_net::DnsGlobalInit dns_prefetch(user_prefs, local_state);
981 1001
982 #if defined(OS_WIN) 1002 #if defined(OS_WIN)
983 // Init common control sex.
984 INITCOMMONCONTROLSEX config;
985 config.dwSize = sizeof(config);
986 config.dwICC = ICC_WIN95_CLASSES;
987 InitCommonControlsEx(&config);
988
989 win_util::ScopedCOMInitializer com_initializer; 1003 win_util::ScopedCOMInitializer com_initializer;
990 1004
991 // Init the RLZ library. This just binds the dll and schedules a task on the 1005 // Init the RLZ library. This just binds the dll and schedules a task on the
992 // file thread to be run sometime later. If this is the first run we record 1006 // file thread to be run sometime later. If this is the first run we record
993 // the installation event. 1007 // the installation event.
994 RLZTracker::InitRlzDelayed(base::DIR_MODULE, is_first_run, 1008 RLZTracker::InitRlzDelayed(base::DIR_MODULE, is_first_run,
995 master_prefs.ping_delay); 1009 master_prefs.ping_delay);
996 #endif 1010 #endif
997 1011
998 // Configure the network module so it has access to resources. 1012 // Configure the network module so it has access to resources.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 1112
1099 metrics->Stop(); 1113 metrics->Stop();
1100 1114
1101 // browser_shutdown takes care of deleting browser_process, so we need to 1115 // browser_shutdown takes care of deleting browser_process, so we need to
1102 // release it. 1116 // release it.
1103 browser_process.release(); 1117 browser_process.release();
1104 browser_shutdown::Shutdown(); 1118 browser_shutdown::Shutdown();
1105 1119
1106 return result_code; 1120 return result_code;
1107 } 1121 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698