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 29 matching lines...) Expand all Loading... |
40 virtual int Initialize(const content::MainFunctionParams& parameters) | 40 virtual int Initialize(const content::MainFunctionParams& parameters) |
41 OVERRIDE { | 41 OVERRIDE { |
42 is_initialized_ = true; | 42 is_initialized_ = true; |
43 | 43 |
44 // ChildProcess:: is a misnomer unless you consider context. Use | 44 // ChildProcess:: is a misnomer unless you consider context. Use |
45 // of --wait-for-debugger only makes sense when Chrome itself is a | 45 // of --wait-for-debugger only makes sense when Chrome itself is a |
46 // child process (e.g. when launched by PyAuto). | 46 // child process (e.g. when launched by PyAuto). |
47 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) | 47 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) |
48 ChildProcess::WaitForDebugger("Browser"); | 48 ChildProcess::WaitForDebugger("Browser"); |
49 | 49 |
| 50 statistics_.reset(new base::StatisticsRecorder); |
| 51 |
50 notification_service_.reset(new NotificationServiceImpl); | 52 notification_service_.reset(new NotificationServiceImpl); |
51 | 53 |
52 main_loop_.reset(new content::BrowserMainLoop(parameters)); | 54 main_loop_.reset(new content::BrowserMainLoop(parameters)); |
53 | 55 |
54 main_loop_->Init(); | 56 main_loop_->Init(); |
55 | 57 |
56 main_loop_->EarlyInitialization(); | 58 main_loop_->EarlyInitialization(); |
57 | 59 |
58 // Must happen before we try to use a message loop or display any UI. | 60 // Must happen before we try to use a message loop or display any UI. |
59 main_loop_->InitializeToolkit(); | 61 main_loop_->InitializeToolkit(); |
60 | 62 |
61 main_loop_->MainMessageLoopStart(); | 63 main_loop_->MainMessageLoopStart(); |
62 | 64 |
63 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here | 65 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here |
64 // are NOT deleted. If you need something to run during WM_ENDSESSION add it | 66 // are NOT deleted. If you need something to run during WM_ENDSESSION add it |
65 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. | 67 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. |
66 | 68 |
67 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
68 #if !defined(NO_TCMALLOC) | 70 #if !defined(NO_TCMALLOC) |
69 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic | 71 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic |
70 // allocator selection is not supported. | 72 // allocator selection is not supported. |
71 | 73 |
72 // Make this call before going multithreaded, or spawning any subprocesses. | 74 // Make this call before going multithreaded, or spawning any subprocesses. |
73 base::allocator::SetupSubprocessAllocator(); | 75 base::allocator::SetupSubprocessAllocator(); |
74 #endif | 76 #endif |
75 | 77 |
76 com_initializer_.reset(new base::win::ScopedCOMInitializer); | 78 com_initializer_.reset(new base::win::ScopedCOMInitializer); |
77 #endif // OS_WIN | 79 #endif // OS_WIN |
78 | 80 |
79 statistics_.reset(new base::StatisticsRecorder); | |
80 | |
81 main_loop_->CreateThreads(); | 81 main_loop_->CreateThreads(); |
82 int result_code = main_loop_->GetResultCode(); | 82 int result_code = main_loop_->GetResultCode(); |
83 if (result_code > 0) | 83 if (result_code > 0) |
84 return result_code; | 84 return result_code; |
85 created_threads_ = true; | 85 created_threads_ = true; |
86 | 86 |
87 // Return -1 to indicate no early termination. | 87 // Return -1 to indicate no early termination. |
88 return -1; | 88 return -1; |
89 } | 89 } |
90 | 90 |
91 virtual int Run() OVERRIDE { | 91 virtual int Run() OVERRIDE { |
92 DCHECK(is_initialized_); | 92 DCHECK(is_initialized_); |
93 DCHECK(!is_shutdown_); | 93 DCHECK(!is_shutdown_); |
94 main_loop_->RunMainMessageLoopParts(); | 94 main_loop_->RunMainMessageLoopParts(); |
95 return main_loop_->GetResultCode(); | 95 return main_loop_->GetResultCode(); |
96 } | 96 } |
97 | 97 |
98 virtual void Shutdown() OVERRIDE { | 98 virtual void Shutdown() OVERRIDE { |
99 DCHECK(is_initialized_); | 99 DCHECK(is_initialized_); |
100 DCHECK(!is_shutdown_); | 100 DCHECK(!is_shutdown_); |
101 g_exited_main_message_loop = true; | 101 g_exited_main_message_loop = true; |
102 | 102 |
103 if (created_threads_) | 103 if (created_threads_) |
104 main_loop_->ShutdownThreadsAndCleanUp(); | 104 main_loop_->ShutdownThreadsAndCleanUp(); |
105 | 105 |
106 statistics_.reset(NULL); | |
107 | |
108 #if defined(OS_WIN) | 106 #if defined(OS_WIN) |
109 com_initializer_.reset(NULL); | 107 com_initializer_.reset(NULL); |
110 #endif | 108 #endif |
111 | 109 |
112 main_loop_.reset(NULL); | 110 main_loop_.reset(NULL); |
113 | 111 |
114 notification_service_.reset(NULL); | 112 notification_service_.reset(NULL); |
115 | 113 |
| 114 statistics_.reset(NULL); |
| 115 |
116 is_shutdown_ = true; | 116 is_shutdown_ = true; |
117 } | 117 } |
118 | 118 |
119 protected: | 119 protected: |
120 // True if the runner has been initialized. | 120 // True if the runner has been initialized. |
121 bool is_initialized_; | 121 bool is_initialized_; |
122 | 122 |
123 // True if the runner has been shut down. | 123 // True if the runner has been shut down. |
124 bool is_shutdown_; | 124 bool is_shutdown_; |
125 | 125 |
(...skipping 13 matching lines...) Expand all Loading... |
139 } // namespace | 139 } // namespace |
140 | 140 |
141 namespace content { | 141 namespace content { |
142 | 142 |
143 // static | 143 // static |
144 BrowserMainRunner* BrowserMainRunner::Create() { | 144 BrowserMainRunner* BrowserMainRunner::Create() { |
145 return new BrowserMainRunnerImpl(); | 145 return new BrowserMainRunnerImpl(); |
146 } | 146 } |
147 | 147 |
148 } // namespace content | 148 } // namespace content |
OLD | NEW |