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

Side by Side Diff: chrome/app/chrome_main.cc

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

Powered by Google App Engine
This is Rietveld 408576698