OLD | NEW |
---|---|
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_init.h" | 5 #include "chrome/browser/browser_init.h" |
6 | 6 |
7 #include <algorithm> // For max(). | 7 #include <algorithm> // For max(). |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 if (command_line.HasSwitch(switches::kNoStartupWindow)) { | 954 if (command_line.HasSwitch(switches::kNoStartupWindow)) { |
955 expected_tab_count = 0; | 955 expected_tab_count = 0; |
956 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { | 956 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { |
957 std::string restore_session_value( | 957 std::string restore_session_value( |
958 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); | 958 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); |
959 base::StringToInt(restore_session_value, &expected_tab_count); | 959 base::StringToInt(restore_session_value, &expected_tab_count); |
960 } else { | 960 } else { |
961 expected_tab_count = | 961 expected_tab_count = |
962 std::max(1, static_cast<int>(command_line.args().size())); | 962 std::max(1, static_cast<int>(command_line.args().size())); |
963 } | 963 } |
964 CreateAutomationProvider<TestingAutomationProvider>( | 964 if (!CreateAutomationProvider<TestingAutomationProvider>( |
965 testing_channel_id, | 965 testing_channel_id, |
966 profile, | 966 profile, |
967 static_cast<size_t>(expected_tab_count)); | 967 static_cast<size_t>(expected_tab_count))) |
968 return false; | |
968 } | 969 } |
969 } | 970 } |
970 | 971 |
971 bool silent_launch = false; | 972 bool silent_launch = false; |
972 | 973 |
973 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { | 974 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { |
974 std::string automation_channel_id = command_line.GetSwitchValueASCII( | 975 std::string automation_channel_id = command_line.GetSwitchValueASCII( |
975 switches::kAutomationClientChannelID); | 976 switches::kAutomationClientChannelID); |
976 // If there are any extra parameters, we expect each one to generate a | 977 // If there are any extra parameters, we expect each one to generate a |
977 // new tab; if there are none then we have no tabs | 978 // new tab; if there are none then we have no tabs |
978 size_t expected_tabs = | 979 size_t expected_tabs = |
979 std::max(static_cast<int>(command_line.args().size()), 0); | 980 std::max(static_cast<int>(command_line.args().size()), 0); |
980 if (expected_tabs == 0) | 981 if (expected_tabs == 0) |
981 silent_launch = true; | 982 silent_launch = true; |
982 | 983 |
983 if (command_line.HasSwitch(switches::kChromeFrame)) { | 984 if (command_line.HasSwitch(switches::kChromeFrame)) { |
984 CreateAutomationProvider<ChromeFrameAutomationProvider>( | 985 if (!CreateAutomationProvider<ChromeFrameAutomationProvider>( |
985 automation_channel_id, profile, expected_tabs); | 986 automation_channel_id, profile, expected_tabs)) |
987 return false; | |
986 } else { | 988 } else { |
987 CreateAutomationProvider<AutomationProvider>(automation_channel_id, | 989 if (!CreateAutomationProvider<AutomationProvider>( |
988 profile, expected_tabs); | 990 automation_channel_id, profile, expected_tabs)) |
991 return false; | |
989 } | 992 } |
990 } | 993 } |
991 | 994 |
992 // If we have been invoked to display a desktop notification on behalf of | 995 // If we have been invoked to display a desktop notification on behalf of |
993 // the service process, we do not want to open any browser windows. | 996 // the service process, we do not want to open any browser windows. |
994 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { | 997 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { |
995 silent_launch = true; | 998 silent_launch = true; |
996 profile->GetCloudPrintProxyService()->ShowTokenExpiredNotification(); | 999 profile->GetCloudPrintProxyService()->ShowTokenExpiredNotification(); |
997 } | 1000 } |
998 | 1001 |
(...skipping 14 matching lines...) Expand all Loading... | |
1013 // If we don't want to launch a new browser window or tab (in the case | 1016 // If we don't want to launch a new browser window or tab (in the case |
1014 // of an automation request), we are done here. | 1017 // of an automation request), we are done here. |
1015 if (!silent_launch) { | 1018 if (!silent_launch) { |
1016 return browser_init->LaunchBrowser( | 1019 return browser_init->LaunchBrowser( |
1017 command_line, profile, cur_dir, process_startup, return_code); | 1020 command_line, profile, cur_dir, process_startup, return_code); |
1018 } | 1021 } |
1019 return true; | 1022 return true; |
1020 } | 1023 } |
1021 | 1024 |
1022 template <class AutomationProviderClass> | 1025 template <class AutomationProviderClass> |
1023 void BrowserInit::CreateAutomationProvider(const std::string& channel_id, | 1026 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, |
1024 Profile* profile, | 1027 Profile* profile, |
1025 size_t expected_tabs) { | 1028 size_t expected_tabs) { |
1026 scoped_refptr<AutomationProviderClass> automation = | 1029 scoped_refptr<AutomationProviderClass> automation = |
1027 new AutomationProviderClass(profile); | 1030 new AutomationProviderClass(profile); |
1028 automation->ConnectToChannel(channel_id); | 1031 |
1032 if (!automation->InitializeChannel(channel_id)) | |
1033 return false; | |
1029 automation->SetExpectedTabCount(expected_tabs); | 1034 automation->SetExpectedTabCount(expected_tabs); |
1030 | 1035 |
1031 AutomationProviderList* list = | 1036 AutomationProviderList* list = |
1032 g_browser_process->InitAutomationProviderList(); | 1037 g_browser_process->InitAutomationProviderList(); |
1033 DCHECK(list); | 1038 DCHECK(list); |
Paweł Hajdan Jr.
2010/11/10 11:15:44
nit: Remove pointless DCHECK. It was there before,
dtu
2010/11/11 00:10:54
Done.
| |
1034 list->AddProvider(automation); | 1039 list->AddProvider(automation); |
1040 | |
1041 return true; | |
1035 } | 1042 } |
OLD | NEW |