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/browser/browser_main_runner.h" | 5 #include "content/public/browser/browser_main_runner.h" |
6 | 6 |
7 #include "base/allocator/allocator_shim.h" | 7 #include "base/allocator/allocator_shim.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/base/win/scoped_ole_initializer.h" | 22 #include "ui/base/win/scoped_ole_initializer.h" |
23 #include "ui/base/ime/win/tsf_bridge.h" | 23 #include "ui/base/ime/win/tsf_bridge.h" |
24 #endif | 24 #endif |
25 | 25 |
26 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
27 #include "content/browser/android/surface_texture_peer_browser_impl.h" | 27 #include "content/browser/android/surface_texture_peer_browser_impl.h" |
28 #endif | 28 #endif |
29 | 29 |
30 bool g_exited_main_message_loop = false; | 30 bool g_exited_main_message_loop = false; |
31 | 31 |
32 using content::ChildProcess; | 32 namespace content { |
33 using content::NotificationServiceImpl; | |
34 | 33 |
35 namespace { | 34 class BrowserMainRunnerImpl : public BrowserMainRunner { |
36 | |
37 class BrowserMainRunnerImpl : public content::BrowserMainRunner { | |
38 public: | 35 public: |
39 BrowserMainRunnerImpl() | 36 BrowserMainRunnerImpl() |
40 : is_initialized_(false), | 37 : is_initialized_(false), |
41 is_shutdown_(false), | 38 is_shutdown_(false), |
42 created_threads_(false) { | 39 created_threads_(false) { |
43 } | 40 } |
44 | 41 |
45 ~BrowserMainRunnerImpl() { | 42 ~BrowserMainRunnerImpl() { |
46 if (is_initialized_ && !is_shutdown_) | 43 if (is_initialized_ && !is_shutdown_) |
47 Shutdown(); | 44 Shutdown(); |
48 } | 45 } |
49 | 46 |
50 virtual int Initialize(const content::MainFunctionParams& parameters) | 47 virtual int Initialize(const MainFunctionParams& parameters) |
51 OVERRIDE { | 48 OVERRIDE { |
52 is_initialized_ = true; | 49 is_initialized_ = true; |
53 | 50 |
54 #if !defined(OS_IOS) | 51 #if !defined(OS_IOS) |
55 // ChildProcess:: is a misnomer unless you consider context. Use | 52 // ChildProcess:: is a misnomer unless you consider context. Use |
56 // of --wait-for-debugger only makes sense when Chrome itself is a | 53 // of --wait-for-debugger only makes sense when Chrome itself is a |
57 // child process (e.g. when launched by PyAuto). | 54 // child process (e.g. when launched by PyAuto). |
58 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) | 55 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) |
59 ChildProcess::WaitForDebugger("Browser"); | 56 ChildProcess::WaitForDebugger("Browser"); |
60 #endif // !defined(OS_IOS) | 57 #endif // !defined(OS_IOS) |
61 | 58 |
62 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
63 if (parameters.command_line.HasSwitch( | 60 if (parameters.command_line.HasSwitch( |
64 switches::kEnableTextServicesFramework)) { | 61 switches::kEnableTextServicesFramework)) { |
65 base::win::SetForceToUseTsf(); | 62 base::win::SetForceToUseTsf(); |
66 } | 63 } |
67 #endif // OS_WIN | 64 #endif // OS_WIN |
68 | 65 |
69 base::StatisticsRecorder::Initialize(); | 66 base::StatisticsRecorder::Initialize(); |
70 | 67 |
71 notification_service_.reset(new NotificationServiceImpl); | 68 notification_service_.reset(new NotificationServiceImpl); |
72 | 69 |
73 main_loop_.reset(new content::BrowserMainLoop(parameters)); | 70 main_loop_.reset(new BrowserMainLoop(parameters)); |
74 | 71 |
75 main_loop_->Init(); | 72 main_loop_->Init(); |
76 | 73 |
77 main_loop_->EarlyInitialization(); | 74 main_loop_->EarlyInitialization(); |
78 | 75 |
79 // Must happen before we try to use a message loop or display any UI. | 76 // Must happen before we try to use a message loop or display any UI. |
80 main_loop_->InitializeToolkit(); | 77 main_loop_->InitializeToolkit(); |
81 | 78 |
82 main_loop_->MainMessageLoopStart(); | 79 main_loop_->MainMessageLoopStart(); |
83 | 80 |
84 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here | 81 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here |
85 // are NOT deleted. If you need something to run during WM_ENDSESSION add it | 82 // are NOT deleted. If you need something to run during WM_ENDSESSION add it |
86 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. | 83 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. |
87 | 84 |
88 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
89 #if !defined(NO_TCMALLOC) | 86 #if !defined(NO_TCMALLOC) |
90 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic | 87 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic |
91 // allocator selection is not supported. | 88 // allocator selection is not supported. |
92 | 89 |
93 // Make this call before going multithreaded, or spawning any subprocesses. | 90 // Make this call before going multithreaded, or spawning any subprocesses. |
94 base::allocator::SetupSubprocessAllocator(); | 91 base::allocator::SetupSubprocessAllocator(); |
95 #endif | 92 #endif |
96 ole_initializer_.reset(new ui::ScopedOleInitializer); | 93 ole_initializer_.reset(new ui::ScopedOleInitializer); |
97 if (base::win::IsTsfAwareRequired()) | 94 if (base::win::IsTsfAwareRequired()) |
98 ui::TsfBridge::Initialize(); | 95 ui::TsfBridge::Initialize(); |
99 #endif // OS_WIN | 96 #endif // OS_WIN |
100 | 97 |
101 #if defined(OS_ANDROID) | 98 #if defined(OS_ANDROID) |
102 content::SurfaceTexturePeer::InitInstance( | 99 SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl( |
103 new content::SurfaceTexturePeerBrowserImpl( | 100 parameters.command_line.HasSwitch( |
104 parameters.command_line.HasSwitch( | 101 switches::kMediaPlayerInRenderProcess))); |
105 switches::kMediaPlayerInRenderProcess))); | |
106 #endif | 102 #endif |
107 | 103 |
108 main_loop_->CreateThreads(); | 104 main_loop_->CreateThreads(); |
109 int result_code = main_loop_->GetResultCode(); | 105 int result_code = main_loop_->GetResultCode(); |
110 if (result_code > 0) | 106 if (result_code > 0) |
111 return result_code; | 107 return result_code; |
112 created_threads_ = true; | 108 created_threads_ = true; |
113 | 109 |
114 // Return -1 to indicate no early termination. | 110 // Return -1 to indicate no early termination. |
115 return -1; | 111 return -1; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // True if the runner has been initialized. | 143 // True if the runner has been initialized. |
148 bool is_initialized_; | 144 bool is_initialized_; |
149 | 145 |
150 // True if the runner has been shut down. | 146 // True if the runner has been shut down. |
151 bool is_shutdown_; | 147 bool is_shutdown_; |
152 | 148 |
153 // True if the non-UI threads were created. | 149 // True if the non-UI threads were created. |
154 bool created_threads_; | 150 bool created_threads_; |
155 | 151 |
156 scoped_ptr<NotificationServiceImpl> notification_service_; | 152 scoped_ptr<NotificationServiceImpl> notification_service_; |
157 scoped_ptr<content::BrowserMainLoop> main_loop_; | 153 scoped_ptr<BrowserMainLoop> main_loop_; |
158 #if defined(OS_WIN) | 154 #if defined(OS_WIN) |
159 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; | 155 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; |
160 #endif | 156 #endif |
161 | 157 |
162 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 158 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
163 }; | 159 }; |
164 | 160 |
165 } // namespace | |
166 | |
167 namespace content { | |
168 | |
169 // static | 161 // static |
170 BrowserMainRunner* BrowserMainRunner::Create() { | 162 BrowserMainRunner* BrowserMainRunner::Create() { |
171 return new BrowserMainRunnerImpl(); | 163 return new BrowserMainRunnerImpl(); |
172 } | 164 } |
173 | 165 |
174 } // namespace content | 166 } // namespace content |
OLD | NEW |