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 "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
23 #include "ui/base/win/scoped_ole_initializer.h" | 23 #include "ui/base/win/scoped_ole_initializer.h" |
24 #endif | 24 #endif |
25 | 25 |
26 bool g_exited_main_message_loop = false; | 26 bool g_exited_main_message_loop = false; |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 class BrowserMainRunnerImpl : public BrowserMainRunner { | 30 class BrowserMainRunnerImpl : public BrowserMainRunner { |
31 public: | 31 public: |
32 BrowserMainRunnerImpl() | 32 BrowserMainRunnerImpl() : is_initialized_(false), is_shutdown_(false) {} |
33 : is_initialized_(false), | |
34 is_shutdown_(false), | |
35 created_threads_(false) { | |
36 } | |
37 | 33 |
38 virtual ~BrowserMainRunnerImpl() { | 34 virtual ~BrowserMainRunnerImpl() { |
39 if (is_initialized_ && !is_shutdown_) | 35 if (is_initialized_ && !is_shutdown_) |
40 Shutdown(); | 36 Shutdown(); |
41 } | 37 } |
42 | 38 |
43 virtual int Initialize(const MainFunctionParams& parameters) | 39 virtual int Initialize(const MainFunctionParams& parameters) |
44 OVERRIDE { | 40 OVERRIDE { |
45 TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize") | 41 TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize") |
46 is_initialized_ = true; | 42 is_initialized_ = true; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 91 |
96 #if defined(OS_WIN) && !defined(NO_TCMALLOC) | 92 #if defined(OS_WIN) && !defined(NO_TCMALLOC) |
97 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic | 93 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic |
98 // allocator selection is not supported. | 94 // allocator selection is not supported. |
99 | 95 |
100 // Make this call before going multithreaded, or spawning any subprocesses. | 96 // Make this call before going multithreaded, or spawning any subprocesses. |
101 base::allocator::SetupSubprocessAllocator(); | 97 base::allocator::SetupSubprocessAllocator(); |
102 #endif | 98 #endif |
103 ui::InitializeInputMethod(); | 99 ui::InitializeInputMethod(); |
104 | 100 |
105 main_loop_->CreateThreads(); | 101 main_loop_->CreateStartupTasks(); |
106 int result_code = main_loop_->GetResultCode(); | 102 int result_code = main_loop_->GetResultCode(); |
107 if (result_code > 0) | 103 if (result_code > 0) |
108 return result_code; | 104 return result_code; |
109 created_threads_ = true; | |
110 | 105 |
111 // Return -1 to indicate no early termination. | 106 // Return -1 to indicate no early termination. |
112 return -1; | 107 return -1; |
113 } | 108 } |
114 | 109 |
115 virtual int Run() OVERRIDE { | 110 virtual int Run() OVERRIDE { |
116 DCHECK(is_initialized_); | 111 DCHECK(is_initialized_); |
117 DCHECK(!is_shutdown_); | 112 DCHECK(!is_shutdown_); |
118 main_loop_->RunMainMessageLoopParts(); | 113 main_loop_->RunMainMessageLoopParts(); |
119 return main_loop_->GetResultCode(); | 114 return main_loop_->GetResultCode(); |
120 } | 115 } |
121 | 116 |
122 virtual void Shutdown() OVERRIDE { | 117 virtual void Shutdown() OVERRIDE { |
123 DCHECK(is_initialized_); | 118 DCHECK(is_initialized_); |
124 DCHECK(!is_shutdown_); | 119 DCHECK(!is_shutdown_); |
125 g_exited_main_message_loop = true; | 120 g_exited_main_message_loop = true; |
126 | 121 |
127 if (created_threads_) | 122 main_loop_->ShutdownThreadsAndCleanUp(); |
128 main_loop_->ShutdownThreadsAndCleanUp(); | |
129 | 123 |
130 ui::ShutdownInputMethod(); | 124 ui::ShutdownInputMethod(); |
131 #if defined(OS_WIN) | 125 #if defined(OS_WIN) |
132 ole_initializer_.reset(NULL); | 126 ole_initializer_.reset(NULL); |
133 #endif | 127 #endif |
134 | 128 |
135 main_loop_.reset(NULL); | 129 main_loop_.reset(NULL); |
136 | 130 |
137 notification_service_.reset(NULL); | 131 notification_service_.reset(NULL); |
138 | 132 |
139 is_shutdown_ = true; | 133 is_shutdown_ = true; |
140 } | 134 } |
141 | 135 |
142 protected: | 136 protected: |
143 // True if the runner has been initialized. | 137 // True if the runner has been initialized. |
144 bool is_initialized_; | 138 bool is_initialized_; |
145 | 139 |
146 // True if the runner has been shut down. | 140 // True if the runner has been shut down. |
147 bool is_shutdown_; | 141 bool is_shutdown_; |
148 | 142 |
149 // True if the non-UI threads were created. | |
150 bool created_threads_; | |
151 | |
152 scoped_ptr<NotificationServiceImpl> notification_service_; | 143 scoped_ptr<NotificationServiceImpl> notification_service_; |
153 scoped_ptr<BrowserMainLoop> main_loop_; | 144 scoped_ptr<BrowserMainLoop> main_loop_; |
154 #if defined(OS_WIN) | 145 #if defined(OS_WIN) |
155 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; | 146 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; |
156 #endif | 147 #endif |
157 | 148 |
158 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 149 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
159 }; | 150 }; |
160 | 151 |
161 // static | 152 // static |
162 BrowserMainRunner* BrowserMainRunner::Create() { | 153 BrowserMainRunner* BrowserMainRunner::Create() { |
163 return new BrowserMainRunnerImpl(); | 154 return new BrowserMainRunnerImpl(); |
164 } | 155 } |
165 | 156 |
166 } // namespace content | 157 } // namespace content |
OLD | NEW |