OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/app/chrome_main.h" | |
6 | |
7 #include "base/command_line.h" | 5 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 6 #include "base/lazy_instance.h" |
9 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
10 #include "base/metrics/stats_counters.h" | 8 #include "base/metrics/stats_counters.h" |
11 #include "base/metrics/stats_table.h" | 9 #include "base/metrics/stats_table.h" |
12 #include "base/path_service.h" | 10 #include "base/path_service.h" |
13 #include "base/process_util.h" | 11 #include "base/process_util.h" |
14 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
15 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
16 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
(...skipping 22 matching lines...) Expand all Loading... |
39 #include "media/base/media.h" | 37 #include "media/base/media.h" |
40 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
41 #include "ui/base/ui_base_switches.h" | 39 #include "ui/base/ui_base_switches.h" |
42 | 40 |
43 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
44 #include <algorithm> | 42 #include <algorithm> |
45 #include <atlbase.h> | 43 #include <atlbase.h> |
46 #include <malloc.h> | 44 #include <malloc.h> |
47 #include "base/string_util.h" | 45 #include "base/string_util.h" |
48 #include "base/win/registry.h" | 46 #include "base/win/registry.h" |
| 47 #include "chrome/browser/policy/policy_path_parser.h" |
| 48 #include "policy/policy_constants.h" |
49 #include "sandbox/src/sandbox.h" | 49 #include "sandbox/src/sandbox.h" |
50 #include "tools/memory_watcher/memory_watcher.h" | 50 #include "tools/memory_watcher/memory_watcher.h" |
51 #endif | 51 #endif |
52 | 52 |
53 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
54 #include "base/mac/mac_util.h" | 54 #include "base/mac/mac_util.h" |
55 #include "base/mac/os_crash_dumps.h" | 55 #include "base/mac/os_crash_dumps.h" |
56 #include "chrome/app/breakpad_mac.h" | 56 #include "chrome/app/breakpad_mac.h" |
| 57 #include "chrome/app/chrome_main_mac.h" |
57 #include "chrome/browser/mac/relauncher.h" | 58 #include "chrome/browser/mac/relauncher.h" |
58 #include "chrome/common/chrome_paths_internal.h" | 59 #include "chrome/common/chrome_paths_internal.h" |
59 #include "chrome/common/mac/cfbundle_blocker.h" | 60 #include "chrome/common/mac/cfbundle_blocker.h" |
60 #include "grit/chromium_strings.h" | 61 #include "grit/chromium_strings.h" |
61 #include "third_party/WebKit/Source/WebKit/mac/WebCoreSupport/WebSystemInterface
.h" | 62 #include "third_party/WebKit/Source/WebKit/mac/WebCoreSupport/WebSystemInterface
.h" |
62 #include "ui/base/l10n/l10n_util_mac.h" | 63 #include "ui/base/l10n/l10n_util_mac.h" |
63 #endif | 64 #endif |
64 | 65 |
65 #if defined(OS_POSIX) | 66 #if defined(OS_POSIX) |
66 #include <locale.h> | 67 #include <locale.h> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // some apps fail to properly escape arguments. | 142 // some apps fail to properly escape arguments. |
142 bool HasDeprecatedArguments(const std::wstring& command_line) { | 143 bool HasDeprecatedArguments(const std::wstring& command_line) { |
143 const wchar_t kChromeHtml[] = L"chromehtml:"; | 144 const wchar_t kChromeHtml[] = L"chromehtml:"; |
144 std::wstring command_line_lower = command_line; | 145 std::wstring command_line_lower = command_line; |
145 // We are only searching for ASCII characters so this is OK. | 146 // We are only searching for ASCII characters so this is OK. |
146 StringToLowerASCII(&command_line_lower); | 147 StringToLowerASCII(&command_line_lower); |
147 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); | 148 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); |
148 return (pos != std::wstring::npos); | 149 return (pos != std::wstring::npos); |
149 } | 150 } |
150 | 151 |
| 152 // Checks if the registry key exists in the given hive and expands any |
| 153 // variables in the string. |
| 154 bool LoadUserDataDirPolicyFromRegistry(HKEY hive, |
| 155 const std::wstring& key_name, |
| 156 FilePath* user_data_dir) { |
| 157 std::wstring value; |
| 158 |
| 159 base::win::RegKey hklm_policy_key(hive, policy::kRegistrySubKey, KEY_READ); |
| 160 if (hklm_policy_key.ReadValue(key_name.c_str(), &value) == ERROR_SUCCESS) { |
| 161 *user_data_dir = FilePath(policy::path_parser::ExpandPathVariables(value)); |
| 162 return true; |
| 163 } |
| 164 return false; |
| 165 } |
| 166 |
| 167 void CheckUserDataDirPolicy(FilePath* user_data_dir) { |
| 168 DCHECK(user_data_dir); |
| 169 // We are running as Chrome Frame if we were invoked with user-data-dir, |
| 170 // chrome-frame, and automation-channel switches. |
| 171 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 172 const bool is_chrome_frame = |
| 173 !user_data_dir->empty() && |
| 174 command_line->HasSwitch(switches::kChromeFrame) && |
| 175 command_line->HasSwitch(switches::kAutomationClientChannelID); |
| 176 |
| 177 // In the case of Chrome Frame, the last path component of the user-data-dir |
| 178 // provided on the command line must be preserved since it is specific to |
| 179 // CF's host. |
| 180 FilePath cf_host_dir; |
| 181 if (is_chrome_frame) |
| 182 cf_host_dir = user_data_dir->BaseName(); |
| 183 |
| 184 // Policy from the HKLM hive has precedence over HKCU so if we have one here |
| 185 // we don't have to try to load HKCU. |
| 186 const char* key_name_ascii = (is_chrome_frame ? policy::key::kGCFUserDataDir : |
| 187 policy::key::kUserDataDir); |
| 188 std::wstring key_name(ASCIIToWide(key_name_ascii)); |
| 189 if (LoadUserDataDirPolicyFromRegistry(HKEY_LOCAL_MACHINE, key_name, |
| 190 user_data_dir) || |
| 191 LoadUserDataDirPolicyFromRegistry(HKEY_CURRENT_USER, key_name, |
| 192 user_data_dir)) { |
| 193 // A Group Policy value was loaded. Append the Chrome Frame host directory |
| 194 // if relevant. |
| 195 if (is_chrome_frame) |
| 196 *user_data_dir = user_data_dir->Append(cf_host_dir); |
| 197 } |
| 198 } |
| 199 |
151 #endif // defined(OS_WIN) | 200 #endif // defined(OS_WIN) |
152 | 201 |
153 #if defined(OS_LINUX) | 202 #if defined(OS_LINUX) |
154 static void AdjustLinuxOOMScore(const std::string& process_type) { | 203 static void AdjustLinuxOOMScore(const std::string& process_type) { |
155 // Browsers and zygotes should still be killable, but killed last. | 204 // Browsers and zygotes should still be killable, but killed last. |
156 const int kZygoteScore = 0; | 205 const int kZygoteScore = 0; |
157 // The minimum amount to bump a score by. This is large enough that | 206 // The minimum amount to bump a score by. This is large enough that |
158 // even if it's translated into the old values, it will still go up | 207 // even if it's translated into the old values, it will still go up |
159 // by at least one. | 208 // by at least one. |
160 const int kScoreBump = 100; | 209 const int kScoreBump = 100; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 }; | 403 }; |
355 | 404 |
356 class ChromeMainDelegate : public content::ContentMainDelegate { | 405 class ChromeMainDelegate : public content::ContentMainDelegate { |
357 public: | 406 public: |
358 virtual bool BasicStartupComplete(int* exit_code) OVERRIDE { | 407 virtual bool BasicStartupComplete(int* exit_code) OVERRIDE { |
359 #if defined(OS_CHROMEOS) | 408 #if defined(OS_CHROMEOS) |
360 chromeos::BootTimesLoader::Get()->SaveChromeMainStats(); | 409 chromeos::BootTimesLoader::Get()->SaveChromeMainStats(); |
361 #endif | 410 #endif |
362 | 411 |
363 #if defined(OS_MACOSX) | 412 #if defined(OS_MACOSX) |
364 chrome_main::SetUpBundleOverrides(); | 413 SetUpBundleOverrides(); |
365 chrome::common::mac::EnableCFBundleBlocker(); | 414 chrome::common::mac::EnableCFBundleBlocker(); |
366 #endif | 415 #endif |
367 | 416 |
368 Profiling::ProcessStarted(); | 417 Profiling::ProcessStarted(); |
369 | 418 |
370 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 419 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
371 std::string process_type = | 420 std::string process_type = |
372 command_line.GetSwitchValueASCII(switches::kProcessType); | 421 command_line.GetSwitchValueASCII(switches::kProcessType); |
373 | 422 |
374 #if defined(OS_POSIX) | 423 #if defined(OS_POSIX) |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 PathService::Override(content::CHILD_PROCESS_EXE, | 554 PathService::Override(content::CHILD_PROCESS_EXE, |
506 chrome::GetVersionedDirectory(). | 555 chrome::GetVersionedDirectory(). |
507 Append(chrome::kHelperProcessExecutablePath)); | 556 Append(chrome::kHelperProcessExecutablePath)); |
508 | 557 |
509 InitMacCrashReporter(command_line, process_type); | 558 InitMacCrashReporter(command_line, process_type); |
510 #endif | 559 #endif |
511 | 560 |
512 // Notice a user data directory override if any | 561 // Notice a user data directory override if any |
513 FilePath user_data_dir = | 562 FilePath user_data_dir = |
514 command_line.GetSwitchValuePath(switches::kUserDataDir); | 563 command_line.GetSwitchValuePath(switches::kUserDataDir); |
515 chrome_main::CheckUserDataDirPolicy(&user_data_dir); | 564 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 565 CheckUserDataDirPolicy(&user_data_dir); |
| 566 #endif |
516 if (!user_data_dir.empty()) | 567 if (!user_data_dir.empty()) |
517 CHECK(PathService::Override(chrome::DIR_USER_DATA, user_data_dir)); | 568 CHECK(PathService::Override(chrome::DIR_USER_DATA, user_data_dir)); |
518 | 569 |
519 base::ProcessId browser_pid = base::GetCurrentProcId(); | 570 base::ProcessId browser_pid = base::GetCurrentProcId(); |
520 if (!process_type.empty() && | 571 if (!process_type.empty() && |
521 #if defined(OS_MACOSX) | 572 #if defined(OS_MACOSX) |
522 process_type != switches::kRelauncherProcess && | 573 process_type != switches::kRelauncherProcess && |
523 #endif | 574 #endif |
524 process_type != switches::kServiceProcess) { | 575 process_type != switches::kServiceProcess) { |
525 #if defined(OS_WIN) || defined(OS_MACOSX) | 576 #if defined(OS_WIN) || defined(OS_MACOSX) |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, | 800 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, |
750 sandbox::SandboxInterfaceInfo* sandbox_info) { | 801 sandbox::SandboxInterfaceInfo* sandbox_info) { |
751 ChromeMainDelegate chrome_main_delegate; | 802 ChromeMainDelegate chrome_main_delegate; |
752 return content::ContentMain(instance, sandbox_info, &chrome_main_delegate); | 803 return content::ContentMain(instance, sandbox_info, &chrome_main_delegate); |
753 #elif defined(OS_POSIX) | 804 #elif defined(OS_POSIX) |
754 int ChromeMain(int argc, char** argv) { | 805 int ChromeMain(int argc, char** argv) { |
755 ChromeMainDelegate chrome_main_delegate; | 806 ChromeMainDelegate chrome_main_delegate; |
756 return content::ContentMain(argc, argv, &chrome_main_delegate); | 807 return content::ContentMain(argc, argv, &chrome_main_delegate); |
757 #endif | 808 #endif |
758 } | 809 } |
OLD | NEW |