| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "content/public/browser/utility_process_host.h" | 38 #include "content/public/browser/utility_process_host.h" |
| 39 #include "content/public/common/content_client.h" | 39 #include "content/public/common/content_client.h" |
| 40 #include "content/public/common/content_constants.h" | 40 #include "content/public/common/content_constants.h" |
| 41 #include "content/public/common/content_paths.h" | 41 #include "content/public/common/content_paths.h" |
| 42 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
| 43 #include "content/public/common/main_function_params.h" | 43 #include "content/public/common/main_function_params.h" |
| 44 #include "content/public/common/sandbox_init.h" | 44 #include "content/public/common/sandbox_init.h" |
| 45 #include "content/renderer/in_process_renderer_thread.h" | 45 #include "content/renderer/in_process_renderer_thread.h" |
| 46 #include "content/utility/in_process_utility_thread.h" | 46 #include "content/utility/in_process_utility_thread.h" |
| 47 #include "crypto/nss_util.h" | 47 #include "crypto/nss_util.h" |
| 48 #include "ipc/ipc_descriptors.h" |
| 48 #include "ipc/ipc_switches.h" | 49 #include "ipc/ipc_switches.h" |
| 49 #include "media/base/media.h" | 50 #include "media/base/media.h" |
| 50 #include "sandbox/win/src/sandbox_types.h" | 51 #include "sandbox/win/src/sandbox_types.h" |
| 51 #include "ui/base/ui_base_paths.h" | 52 #include "ui/base/ui_base_paths.h" |
| 52 #include "ui/base/ui_base_switches.h" | 53 #include "ui/base/ui_base_switches.h" |
| 53 #include "ui/gfx/win/dpi.h" | 54 #include "ui/gfx/win/dpi.h" |
| 54 | 55 |
| 55 #if defined(USE_TCMALLOC) | 56 #if defined(USE_TCMALLOC) |
| 56 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" | 57 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" |
| 57 #if defined(TYPE_PROFILING) | 58 #if defined(TYPE_PROFILING) |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 // all processes except the browser process (where we call system | 233 // all processes except the browser process (where we call system |
| 233 // APIs that may rely on the correct locale for formatting numbers | 234 // APIs that may rely on the correct locale for formatting numbers |
| 234 // when presenting them to the user), reset the locale for numeric | 235 // when presenting them to the user), reset the locale for numeric |
| 235 // formatting. | 236 // formatting. |
| 236 // Note that this is not correct for plugin processes -- they can | 237 // Note that this is not correct for plugin processes -- they can |
| 237 // surface UI -- but it's likely they get this wrong too so why not. | 238 // surface UI -- but it's likely they get this wrong too so why not. |
| 238 setlocale(LC_NUMERIC, "C"); | 239 setlocale(LC_NUMERIC, "C"); |
| 239 #endif | 240 #endif |
| 240 } | 241 } |
| 241 | 242 |
| 243 // Only needed on Windows for creating stats tables. |
| 244 #if defined(OS_WIN) |
| 242 static base::ProcessId GetBrowserPid(const CommandLine& command_line) { | 245 static base::ProcessId GetBrowserPid(const CommandLine& command_line) { |
| 243 base::ProcessId browser_pid = base::GetCurrentProcId(); | 246 base::ProcessId browser_pid = base::GetCurrentProcId(); |
| 244 #if !defined(OS_IOS) | |
| 245 if (command_line.HasSwitch(switches::kProcessChannelID)) { | 247 if (command_line.HasSwitch(switches::kProcessChannelID)) { |
| 246 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 247 std::string channel_name = | 248 std::string channel_name = |
| 248 command_line.GetSwitchValueASCII(switches::kProcessChannelID); | 249 command_line.GetSwitchValueASCII(switches::kProcessChannelID); |
| 249 | 250 |
| 250 int browser_pid_int; | 251 int browser_pid_int; |
| 251 base::StringToInt(channel_name, &browser_pid_int); | 252 base::StringToInt(channel_name, &browser_pid_int); |
| 252 browser_pid = static_cast<base::ProcessId>(browser_pid_int); | 253 browser_pid = static_cast<base::ProcessId>(browser_pid_int); |
| 253 DCHECK_NE(browser_pid_int, 0); | 254 DCHECK_NE(browser_pid_int, 0); |
| 254 #elif defined(OS_ANDROID) | |
| 255 // On Android, the browser process isn't the parent. A bunch | |
| 256 // of work will be required before callers of this routine will | |
| 257 // get what they want. | |
| 258 // | |
| 259 // Note: On Linux, base::GetParentProcessId() is defined in | |
| 260 // process_util_linux.cc. Note that *_linux.cc is excluded from | |
| 261 // Android builds but a special exception is made in base.gypi | |
| 262 // for a few files including process_util_linux.cc. | |
| 263 LOG(ERROR) << "GetBrowserPid() not implemented for Android()."; | |
| 264 #elif defined(OS_POSIX) | |
| 265 // On linux, we're in a process forked from the zygote here; so we need the | |
| 266 // parent's parent process' id. | |
| 267 browser_pid = | |
| 268 base::GetParentProcessId( | |
| 269 base::GetParentProcessId(base::GetCurrentProcId())); | |
| 270 #endif | |
| 271 } | 255 } |
| 272 #endif // !OS_IOS | |
| 273 return browser_pid; | 256 return browser_pid; |
| 274 } | 257 } |
| 258 #endif |
| 275 | 259 |
| 276 static void InitializeStatsTable(const CommandLine& command_line) { | 260 static void InitializeStatsTable(const CommandLine& command_line) { |
| 277 // Initialize the Stats Counters table. With this initialized, | 261 // Initialize the Stats Counters table. With this initialized, |
| 278 // the StatsViewer can be utilized to read counters outside of | 262 // the StatsViewer can be utilized to read counters outside of |
| 279 // Chrome. These lines can be commented out to effectively turn | 263 // Chrome. These lines can be commented out to effectively turn |
| 280 // counters 'off'. The table is created and exists for the life | 264 // counters 'off'. The table is created and exists for the life |
| 281 // of the process. It is not cleaned up. | 265 // of the process. It is not cleaned up. |
| 282 if (command_line.HasSwitch(switches::kEnableStatsTable)) { | 266 if (command_line.HasSwitch(switches::kEnableStatsTable)) { |
| 283 // NOTIMPLEMENTED: we probably need to shut this down correctly to avoid | 267 // NOTIMPLEMENTED: we probably need to shut this down correctly to avoid |
| 284 // leaking shared memory regions on posix platforms. | 268 // leaking shared memory regions on posix platforms. |
| 285 std::string statsfile = | 269 #if defined(OS_POSIX) |
| 270 // Stats table is in the global file descriptors table on Posix. |
| 271 base::GlobalDescriptors* global_descriptors = |
| 272 base::GlobalDescriptors::GetInstance(); |
| 273 base::FileDescriptor table_ident; |
| 274 if (global_descriptors->MaybeGet(kStatsTableSharedMemFd) != -1) { |
| 275 // Open the shared memory file descriptor passed by the browser process. |
| 276 table_ident = base::FileDescriptor( |
| 277 global_descriptors->Get(kStatsTableSharedMemFd), false); |
| 278 } |
| 279 #elif defined(OS_WIN) |
| 280 // Stats table is in a named segment on Windows. Use the PID to make this |
| 281 // unique on the system. |
| 282 std::string table_ident = |
| 286 base::StringPrintf("%s-%u", kStatsFilename, | 283 base::StringPrintf("%s-%u", kStatsFilename, |
| 287 static_cast<unsigned int>(GetBrowserPid(command_line))); | 284 static_cast<unsigned int>(GetBrowserPid(command_line))); |
| 288 base::StatsTable* stats_table = new base::StatsTable(statsfile, | 285 #endif |
| 289 kStatsMaxThreads, kStatsMaxCounters); | 286 base::StatsTable* stats_table = |
| 287 new base::StatsTable(table_ident, kStatsMaxThreads, kStatsMaxCounters); |
| 290 base::StatsTable::set_current(stats_table); | 288 base::StatsTable::set_current(stats_table); |
| 291 } | 289 } |
| 292 } | 290 } |
| 293 | 291 |
| 294 class ContentClientInitializer { | 292 class ContentClientInitializer { |
| 295 public: | 293 public: |
| 296 static void Set(const std::string& process_type, | 294 static void Set(const std::string& process_type, |
| 297 ContentMainDelegate* delegate) { | 295 ContentMainDelegate* delegate) { |
| 298 ContentClient* content_client = GetContentClient(); | 296 ContentClient* content_client = GetContentClient(); |
| 299 if (process_type.empty()) { | 297 if (process_type.empty()) { |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 | 856 |
| 859 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 857 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 860 }; | 858 }; |
| 861 | 859 |
| 862 // static | 860 // static |
| 863 ContentMainRunner* ContentMainRunner::Create() { | 861 ContentMainRunner* ContentMainRunner::Create() { |
| 864 return new ContentMainRunnerImpl(); | 862 return new ContentMainRunnerImpl(); |
| 865 } | 863 } |
| 866 | 864 |
| 867 } // namespace content | 865 } // namespace content |
| OLD | NEW |