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() : is_initialized_(false), is_shutdown_(false) {} | 32 BrowserMainRunnerImpl() |
| 33 : initialization_started_(false), is_shutdown_(false) {} |
33 | 34 |
34 virtual ~BrowserMainRunnerImpl() { | 35 virtual ~BrowserMainRunnerImpl() { |
35 if (is_initialized_ && !is_shutdown_) | 36 if (initialization_started_ && !is_shutdown_) |
36 Shutdown(); | 37 Shutdown(); |
37 } | 38 } |
38 | 39 |
39 virtual int Initialize(const MainFunctionParams& parameters) | 40 virtual int Initialize(const MainFunctionParams& parameters) OVERRIDE { |
40 OVERRIDE { | 41 TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize"); |
41 TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize") | 42 // On Android we normally initialize the browser in a series of UI thread |
42 is_initialized_ = true; | 43 // tasks. While this is happening a second request can come from the OS or |
| 44 // another application to start the browser. If this happens then we must |
| 45 // not run these parts of initialization twice. |
| 46 if (!initialization_started_) { |
| 47 initialization_started_ = true; |
43 | 48 |
44 #if !defined(OS_IOS) | 49 #if !defined(OS_IOS) |
45 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) | 50 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) |
46 base::debug::WaitForDebugger(60, true); | 51 base::debug::WaitForDebugger(60, true); |
47 #endif | 52 #endif |
48 | 53 |
49 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
50 if (parameters.command_line.HasSwitch( | 55 if (parameters.command_line.HasSwitch( |
51 switches::kEnableTextServicesFramework)) { | 56 switches::kEnableTextServicesFramework)) { |
52 base::win::SetForceToUseTSF(); | 57 base::win::SetForceToUseTSF(); |
53 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 58 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
54 // When "Extend support of advanced text services to all programs" | 59 // When "Extend support of advanced text services to all programs" |
55 // (a.k.a. Cicero Unaware Application Support; CUAS) is enabled on | 60 // (a.k.a. Cicero Unaware Application Support; CUAS) is enabled on |
56 // Windows XP and handwriting modules shipped with Office 2003 are | 61 // Windows XP and handwriting modules shipped with Office 2003 are |
57 // installed, "penjpn.dll" and "skchui.dll" will be loaded and then crash | 62 // installed, "penjpn.dll" and "skchui.dll" will be loaded and then |
58 // unless a user installs Office 2003 SP3. To prevent these modules from | 63 // crash |
59 // being loaded, disable TSF entirely. crbug/160914. | 64 // unless a user installs Office 2003 SP3. To prevent these modules from |
60 // TODO(yukawa): Add a high-level wrapper for this instead of calling | 65 // being loaded, disable TSF entirely. crbug/160914. |
61 // Win32 API here directly. | 66 // TODO(yukawa): Add a high-level wrapper for this instead of calling |
62 ImmDisableTextFrameService(static_cast<DWORD>(-1)); | 67 // Win32 API here directly. |
63 } | 68 ImmDisableTextFrameService(static_cast<DWORD>(-1)); |
| 69 } |
64 #endif // OS_WIN | 70 #endif // OS_WIN |
65 | 71 |
66 base::StatisticsRecorder::Initialize(); | 72 base::StatisticsRecorder::Initialize(); |
67 | 73 |
68 notification_service_.reset(new NotificationServiceImpl); | 74 notification_service_.reset(new NotificationServiceImpl); |
69 | 75 |
70 #if defined(OS_WIN) | 76 #if defined(OS_WIN) |
71 // Ole must be initialized before starting message pump, so that TSF | 77 // Ole must be initialized before starting message pump, so that TSF |
72 // (Text Services Framework) module can interact with the message pump | 78 // (Text Services Framework) module can interact with the message pump |
73 // on Windows 8 Metro mode. | 79 // on Windows 8 Metro mode. |
74 ole_initializer_.reset(new ui::ScopedOleInitializer); | 80 ole_initializer_.reset(new ui::ScopedOleInitializer); |
75 #endif // OS_WIN | 81 #endif // OS_WIN |
76 | 82 |
77 main_loop_.reset(new BrowserMainLoop(parameters)); | 83 main_loop_.reset(new BrowserMainLoop(parameters)); |
78 | 84 |
79 main_loop_->Init(); | 85 main_loop_->Init(); |
80 | 86 |
81 main_loop_->EarlyInitialization(); | 87 main_loop_->EarlyInitialization(); |
82 | 88 |
83 // Must happen before we try to use a message loop or display any UI. | 89 // Must happen before we try to use a message loop or display any UI. |
84 main_loop_->InitializeToolkit(); | 90 main_loop_->InitializeToolkit(); |
85 | 91 |
86 main_loop_->MainMessageLoopStart(); | 92 main_loop_->MainMessageLoopStart(); |
87 | 93 |
88 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here | 94 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here |
89 // are NOT deleted. If you need something to run during WM_ENDSESSION add it | 95 // are NOT deleted. If you need something to run during WM_ENDSESSION add it |
90 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. | 96 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. |
91 | 97 |
92 #if defined(OS_WIN) && !defined(NO_TCMALLOC) | 98 #if defined(OS_WIN) && !defined(NO_TCMALLOC) |
93 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic | 99 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic |
94 // allocator selection is not supported. | 100 // allocator selection is not supported. |
95 | 101 |
96 // Make this call before going multithreaded, or spawning any subprocesses. | 102 // Make this call before going multithreaded, or spawning any |
97 base::allocator::SetupSubprocessAllocator(); | 103 // subprocesses. |
| 104 base::allocator::SetupSubprocessAllocator(); |
98 #endif | 105 #endif |
99 ui::InitializeInputMethod(); | 106 ui::InitializeInputMethod(); |
100 | 107 } |
101 main_loop_->CreateStartupTasks(); | 108 main_loop_->CreateStartupTasks(); |
102 int result_code = main_loop_->GetResultCode(); | 109 int result_code = main_loop_->GetResultCode(); |
103 if (result_code > 0) | 110 if (result_code > 0) |
104 return result_code; | 111 return result_code; |
105 | 112 |
106 // Return -1 to indicate no early termination. | 113 // Return -1 to indicate no early termination. |
107 return -1; | 114 return -1; |
108 } | 115 } |
109 | 116 |
110 virtual int Run() OVERRIDE { | 117 virtual int Run() OVERRIDE { |
111 DCHECK(is_initialized_); | 118 DCHECK(initialization_started_); |
112 DCHECK(!is_shutdown_); | 119 DCHECK(!is_shutdown_); |
113 main_loop_->RunMainMessageLoopParts(); | 120 main_loop_->RunMainMessageLoopParts(); |
114 return main_loop_->GetResultCode(); | 121 return main_loop_->GetResultCode(); |
115 } | 122 } |
116 | 123 |
117 virtual void Shutdown() OVERRIDE { | 124 virtual void Shutdown() OVERRIDE { |
118 DCHECK(is_initialized_); | 125 DCHECK(initialization_started_); |
119 DCHECK(!is_shutdown_); | 126 DCHECK(!is_shutdown_); |
120 g_exited_main_message_loop = true; | 127 g_exited_main_message_loop = true; |
121 | 128 |
122 main_loop_->ShutdownThreadsAndCleanUp(); | 129 main_loop_->ShutdownThreadsAndCleanUp(); |
123 | 130 |
124 ui::ShutdownInputMethod(); | 131 ui::ShutdownInputMethod(); |
125 #if defined(OS_WIN) | 132 #if defined(OS_WIN) |
126 ole_initializer_.reset(NULL); | 133 ole_initializer_.reset(NULL); |
127 #endif | 134 #endif |
128 | 135 |
129 main_loop_.reset(NULL); | 136 main_loop_.reset(NULL); |
130 | 137 |
131 notification_service_.reset(NULL); | 138 notification_service_.reset(NULL); |
132 | 139 |
133 is_shutdown_ = true; | 140 is_shutdown_ = true; |
134 } | 141 } |
135 | 142 |
136 protected: | 143 protected: |
137 // True if the runner has been initialized. | 144 // True if we have started to initialize the runner. |
138 bool is_initialized_; | 145 bool initialization_started_; |
139 | 146 |
140 // True if the runner has been shut down. | 147 // True if the runner has been shut down. |
141 bool is_shutdown_; | 148 bool is_shutdown_; |
142 | 149 |
143 scoped_ptr<NotificationServiceImpl> notification_service_; | 150 scoped_ptr<NotificationServiceImpl> notification_service_; |
144 scoped_ptr<BrowserMainLoop> main_loop_; | 151 scoped_ptr<BrowserMainLoop> main_loop_; |
145 #if defined(OS_WIN) | 152 #if defined(OS_WIN) |
146 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; | 153 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; |
147 #endif | 154 #endif |
148 | 155 |
149 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 156 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
150 }; | 157 }; |
151 | 158 |
152 // static | 159 // static |
153 BrowserMainRunner* BrowserMainRunner::Create() { | 160 BrowserMainRunner* BrowserMainRunner::Create() { |
154 return new BrowserMainRunnerImpl(); | 161 return new BrowserMainRunnerImpl(); |
155 } | 162 } |
156 | 163 |
157 } // namespace content | 164 } // namespace content |
OLD | NEW |