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 "content/browser/browser_main.h"
6 
7 #include <memory>
8 
9 #include "base/trace_event/trace_event.h"
10 #include "content/browser/browser_main_runner_impl.h"
11 #include "content/common/content_constants_internal.h"
12 
13 namespace content {
14 
15 namespace {
16 
17 // Generates a pair of BrowserMain async events. We don't use the TRACE_EVENT0
18 // macro because the tracing infrastructure doesn't expect synchronous events
19 // around the main loop of a thread.
20 class ScopedBrowserMainEvent {
21  public:
ScopedBrowserMainEvent()22   ScopedBrowserMainEvent() {
23     TRACE_EVENT_ASYNC_BEGIN0("startup", "BrowserMain", 0);
24   }
~ScopedBrowserMainEvent()25   ~ScopedBrowserMainEvent() {
26     TRACE_EVENT_ASYNC_END0("startup", "BrowserMain", 0);
27   }
28 };
29 
30 }  // namespace
31 
32 // Main routine for running as the Browser process.
BrowserMain(const MainFunctionParams & parameters)33 int BrowserMain(const MainFunctionParams& parameters) {
34   ScopedBrowserMainEvent scoped_browser_main_event;
35 
36   base::trace_event::TraceLog::GetInstance()->set_process_name("Browser");
37   base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
38       kTraceEventBrowserProcessSortIndex);
39 
40   std::unique_ptr<BrowserMainRunnerImpl> main_runner(
41       BrowserMainRunnerImpl::Create());
42 
43   int exit_code = main_runner->Initialize(parameters);
44   if (exit_code >= 0)
45     return exit_code;
46 
47   exit_code = main_runner->Run();
48 
49   main_runner->Shutdown();
50 
51   return exit_code;
52 }
53 
54 }  // namespace content
55