• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "base/debug/debugger.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/metrics/statistics_recorder.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/service_process_util.h"
10 #include "chrome/service/service_process.h"
11 #include "content/public/common/main_function_params.h"
12 #include "net/url_request/url_request.h"
13 
14 #if defined(OS_WIN)
15 #include "content/public/common/sandbox_init.h"
16 #include "sandbox/win/src/sandbox_types.h"
17 #elif defined(OS_MACOSX)
18 #include "chrome/service/chrome_service_application_mac.h"
19 #endif  // defined(OS_WIN)
20 
21 // Mainline routine for running as the service process.
ServiceProcessMain(const content::MainFunctionParams & parameters)22 int ServiceProcessMain(const content::MainFunctionParams& parameters) {
23   // Chrome disallows cookies by default. All code paths that want to use
24   // cookies should go through the browser process.
25   net::URLRequest::SetDefaultCookiePolicyToBlock();
26 
27 #if defined(OS_MACOSX)
28   chrome_service_mac::RegisterServiceEventHandler();
29 #endif
30 
31   base::MessageLoopForUI main_message_loop;
32   main_message_loop.set_thread_name("MainThread");
33   if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) {
34     base::debug::WaitForDebugger(60, true);
35   }
36 
37   VLOG(1) << "Service process launched: "
38           << parameters.command_line.GetCommandLineString();
39 
40   base::PlatformThread::SetName("CrServiceMain");
41   base::StatisticsRecorder::Initialize();
42 
43   // If there is already a service process running, quit now.
44   scoped_ptr<ServiceProcessState> state(new ServiceProcessState);
45   if (!state->Initialize())
46     return 0;
47 
48   ServiceProcess service_process;
49   if (service_process.Initialize(&main_message_loop,
50                                  parameters.command_line,
51                                  state.release())) {
52     base::MessageLoop::current()->Run();
53   } else {
54     LOG(ERROR) << "Service process failed to initialize";
55   }
56   service_process.Teardown();
57   return 0;
58 }
59