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

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

Issue 27240: Make startup_tests build and run on Linux (except reference tests). (Closed)
Patch Set: small bugfix in process_util Created 11 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
« no previous file with comments | « chrome/browser/browser_init.h ('k') | chrome/browser/browser_main.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_init.h" 5 #include "chrome/browser/browser_init.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/event_recorder.h" 9 #include "base/event_recorder.h"
10 #include "base/histogram.h" 10 #include "base/histogram.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/sys_info.h" 13 #include "base/sys_info.h"
14 #include "chrome/browser/autocomplete/autocomplete.h" 14 #include "chrome/browser/autocomplete/autocomplete.h"
15 #include "chrome/browser/automation/automation_provider.h"
16 #include "chrome/browser/automation/automation_provider_list.h"
15 #include "chrome/browser/browser_list.h" 17 #include "chrome/browser/browser_list.h"
16 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/extensions/extensions_service.h" 19 #include "chrome/browser/extensions/extensions_service.h"
18 #include "chrome/browser/net/dns_global.h" 20 #include "chrome/browser/net/dns_global.h"
19 #include "chrome/browser/profile.h" 21 #include "chrome/browser/profile.h"
20 #include "chrome/browser/renderer_host/render_process_host.h" 22 #include "chrome/browser/renderer_host/render_process_host.h"
21 #include "chrome/browser/search_engines/template_url_model.h" 23 #include "chrome/browser/search_engines/template_url_model.h"
22 #include "chrome/browser/session_startup_pref.h" 24 #include "chrome/browser/session_startup_pref.h"
23 #include "chrome/browser/sessions/session_restore.h" 25 #include "chrome/browser/sessions/session_restore.h"
24 #include "chrome/browser/tab_contents/infobar_delegate.h" 26 #include "chrome/browser/tab_contents/infobar_delegate.h"
25 #include "chrome/browser/tab_contents/navigation_controller.h" 27 #include "chrome/browser/tab_contents/navigation_controller.h"
26 #include "chrome/browser/net/url_fixer_upper.h" 28 #include "chrome/browser/net/url_fixer_upper.h"
27 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
28 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/l10n_util.h" 32 #include "chrome/common/l10n_util.h"
31 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
32 #include "chrome/common/pref_service.h" 34 #include "chrome/common/pref_service.h"
33 #include "chrome/common/result_codes.h" 35 #include "chrome/common/result_codes.h"
34 #include "net/base/cookie_monster.h" 36 #include "net/base/cookie_monster.h"
35 #include "webkit/glue/webkit_glue.h" 37 #include "webkit/glue/webkit_glue.h"
36 38
37 #if defined(OS_WIN) 39 #if defined(OS_WIN)
38 40
39 #include "base/win_util.h" 41 #include "base/win_util.h"
40 #include "chrome/browser/automation/automation_provider.h"
41 #include "chrome/browser/automation/automation_provider_list.h"
42 #include "chrome/common/resource_bundle.h" 42 #include "chrome/common/resource_bundle.h"
43 #include "grit/chromium_strings.h" 43 #include "grit/chromium_strings.h"
44 #include "grit/generated_resources.h" 44 #include "grit/generated_resources.h"
45 #include "grit/locale_settings.h" 45 #include "grit/locale_settings.h"
46 #include "grit/theme_resources.h" 46 #include "grit/theme_resources.h"
47 47
48 #endif 48 #endif
49 49
50 namespace { 50 namespace {
51 51
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 const std::wstring tab_count_string = 438 const std::wstring tab_count_string =
439 command_line.GetSwitchValue(switches::kTabCountToLoadOnSessionRestore); 439 command_line.GetSwitchValue(switches::kTabCountToLoadOnSessionRestore);
440 if (!tab_count_string.empty()) { 440 if (!tab_count_string.empty()) {
441 int count = 0; 441 int count = 0;
442 if (StringToInt(WideToUTF16Hack(tab_count_string), &count)) { 442 if (StringToInt(WideToUTF16Hack(tab_count_string), &count)) {
443 const int tab_count = std::max(0, count); 443 const int tab_count = std::max(0, count);
444 SessionRestore::num_tabs_to_load_ = static_cast<size_t>(tab_count); 444 SessionRestore::num_tabs_to_load_ = static_cast<size_t>(tab_count);
445 } 445 }
446 } 446 }
447 447
448 #if defined(OS_WIN)
449 // Look for the testing channel ID ONLY during process startup 448 // Look for the testing channel ID ONLY during process startup
450 if (command_line.HasSwitch(switches::kTestingChannelID)) { 449 if (command_line.HasSwitch(switches::kTestingChannelID)) {
451 std::wstring testing_channel_id = 450 std::wstring testing_channel_id =
452 command_line.GetSwitchValue(switches::kTestingChannelID); 451 command_line.GetSwitchValue(switches::kTestingChannelID);
453 // TODO(sanjeevr) Check if we need to make this a singleton for 452 // TODO(sanjeevr) Check if we need to make this a singleton for
454 // compatibility with the old testing code 453 // compatibility with the old testing code
455 // If there are any loose parameters, we expect each one to generate a 454 // If there are any loose parameters, we expect each one to generate a
456 // new tab; if there are none then we get one homepage tab. 455 // new tab; if there are none then we get one homepage tab.
457 int expected_tab_count = 1; 456 int expected_tab_count = 1;
458 if (command_line.HasSwitch(switches::kRestoreLastSession)) { 457 if (command_line.HasSwitch(switches::kRestoreLastSession)) {
459 StringToInt(command_line.GetSwitchValue(switches::kRestoreLastSession), 458 std::wstring restore_session_value(
459 command_line.GetSwitchValue(switches::kRestoreLastSession));
460 StringToInt(WideToUTF16Hack(restore_session_value),
460 &expected_tab_count); 461 &expected_tab_count);
461 } else { 462 } else {
462 expected_tab_count = 463 expected_tab_count =
463 std::max(1, static_cast<int>(command_line.GetLooseValues().size())); 464 std::max(1, static_cast<int>(command_line.GetLooseValues().size()));
464 } 465 }
465 CreateAutomationProvider<TestingAutomationProvider>( 466 CreateAutomationProvider<TestingAutomationProvider>(
466 testing_channel_id, 467 testing_channel_id,
467 profile, 468 profile,
468 static_cast<size_t>(expected_tab_count)); 469 static_cast<size_t>(expected_tab_count));
469 } 470 }
470 #endif
471 } 471 }
472 472
473 // Allow the command line to override the persisted setting of home page. 473 // Allow the command line to override the persisted setting of home page.
474 SetOverrideHomePage(command_line, profile->GetPrefs()); 474 SetOverrideHomePage(command_line, profile->GetPrefs());
475 475
476 if (command_line.HasSwitch(switches::kBrowserStartRenderersManually)) 476 if (command_line.HasSwitch(switches::kBrowserStartRenderersManually))
477 prefs->transient()->SetBoolean(prefs::kStartRenderersManually, true); 477 prefs->transient()->SetBoolean(prefs::kStartRenderersManually, true);
478 478
479 bool silent_launch = false; 479 bool silent_launch = false;
480 #if defined(OS_WIN)
481 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { 480 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) {
482 std::wstring automation_channel_id = 481 std::wstring automation_channel_id =
483 command_line.GetSwitchValue(switches::kAutomationClientChannelID); 482 command_line.GetSwitchValue(switches::kAutomationClientChannelID);
484 // If there are any loose parameters, we expect each one to generate a 483 // If there are any loose parameters, we expect each one to generate a
485 // new tab; if there are none then we have no tabs 484 // new tab; if there are none then we have no tabs
486 size_t expected_tabs = 485 size_t expected_tabs =
487 std::max(static_cast<int>(command_line.GetLooseValues().size()), 486 std::max(static_cast<int>(command_line.GetLooseValues().size()),
488 0); 487 0);
489 if (expected_tabs == 0) 488 if (expected_tabs == 0)
490 silent_launch = true; 489 silent_launch = true;
491 CreateAutomationProvider<AutomationProvider>(automation_channel_id, 490 CreateAutomationProvider<AutomationProvider>(automation_channel_id,
492 profile, expected_tabs); 491 profile, expected_tabs);
493 } 492 }
494 #endif
495 493
496 if (command_line.HasSwitch(switches::kLoadExtension)) { 494 if (command_line.HasSwitch(switches::kLoadExtension)) {
497 std::wstring path_string = 495 std::wstring path_string =
498 command_line.GetSwitchValue(switches::kLoadExtension); 496 command_line.GetSwitchValue(switches::kLoadExtension);
499 FilePath path = FilePath::FromWStringHack(path_string); 497 FilePath path = FilePath::FromWStringHack(path_string);
500 profile->GetExtensionsService()->LoadExtension(path); 498 profile->GetExtensionsService()->LoadExtension(path);
501 profile->GetUserScriptMaster()->AddWatchedPath(path); 499 profile->GetUserScriptMaster()->AddWatchedPath(path);
502 } 500 }
503 501
504 if (command_line.HasSwitch(switches::kInstallExtension)) { 502 if (command_line.HasSwitch(switches::kInstallExtension)) {
(...skipping 19 matching lines...) Expand all
524 bool BrowserInit::LaunchBrowser(const CommandLine& command_line, 522 bool BrowserInit::LaunchBrowser(const CommandLine& command_line,
525 Profile* profile, const std::wstring& cur_dir, 523 Profile* profile, const std::wstring& cur_dir,
526 bool process_startup, int* return_code) { 524 bool process_startup, int* return_code) {
527 in_startup = process_startup; 525 in_startup = process_startup;
528 bool result = LaunchBrowserImpl(command_line, profile, cur_dir, 526 bool result = LaunchBrowserImpl(command_line, profile, cur_dir,
529 process_startup, return_code); 527 process_startup, return_code);
530 in_startup = false; 528 in_startup = false;
531 return result; 529 return result;
532 } 530 }
533 531
534 #if defined(OS_WIN)
535 template <class AutomationProviderClass> 532 template <class AutomationProviderClass>
536 void BrowserInit::CreateAutomationProvider(const std::wstring& channel_id, 533 void BrowserInit::CreateAutomationProvider(const std::wstring& channel_id,
537 Profile* profile, 534 Profile* profile,
538 size_t expected_tabs) { 535 size_t expected_tabs) {
539 scoped_refptr<AutomationProviderClass> automation = 536 scoped_refptr<AutomationProviderClass> automation =
540 new AutomationProviderClass(profile); 537 new AutomationProviderClass(profile);
541 automation->ConnectToChannel(channel_id); 538 automation->ConnectToChannel(channel_id);
542 automation->SetExpectedTabCount(expected_tabs); 539 automation->SetExpectedTabCount(expected_tabs);
543 540
544 AutomationProviderList* list = 541 AutomationProviderList* list =
545 g_browser_process->InitAutomationProviderList(); DCHECK(list); 542 g_browser_process->InitAutomationProviderList();
543 DCHECK(list);
546 list->AddProvider(automation); 544 list->AddProvider(automation);
547 } 545 }
548 #endif
549 546
550 bool BrowserInit::LaunchBrowserImpl(const CommandLine& command_line, 547 bool BrowserInit::LaunchBrowserImpl(const CommandLine& command_line,
551 Profile* profile, 548 Profile* profile,
552 const std::wstring& cur_dir, 549 const std::wstring& cur_dir,
553 bool process_startup, 550 bool process_startup,
554 int* return_code) { 551 int* return_code) {
555 DCHECK(profile); 552 DCHECK(profile);
556 553
557 // Continue with the off-the-record profile from here on if --incognito 554 // Continue with the off-the-record profile from here on if --incognito
558 if (command_line.HasSwitch(switches::kIncognito)) 555 if (command_line.HasSwitch(switches::kIncognito))
559 profile = profile->GetOffTheRecordProfile(); 556 profile = profile->GetOffTheRecordProfile();
560 557
561 LaunchWithProfile lwp(cur_dir, command_line); 558 LaunchWithProfile lwp(cur_dir, command_line);
562 bool launched = lwp.Launch(profile, process_startup); 559 bool launched = lwp.Launch(profile, process_startup);
563 if (!launched) { 560 if (!launched) {
564 LOG(ERROR) << "launch error"; 561 LOG(ERROR) << "launch error";
565 if (return_code != NULL) 562 if (return_code != NULL)
566 *return_code = ResultCodes::INVALID_CMDLINE_URL; 563 *return_code = ResultCodes::INVALID_CMDLINE_URL;
567 return false; 564 return false;
568 } 565 }
569 566
570 return true; 567 return true;
571 } 568 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_init.h ('k') | chrome/browser/browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698