OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/shell/browser/shell_browser_main_parts.h" | 5 #include "extensions/shell/browser/shell_browser_main_parts.h" |
6 | 6 |
7 #include "apps/shell/browser/shell_browser_context.h" | |
8 #include "apps/shell/browser/shell_browser_main_delegate.h" | |
9 #include "apps/shell/browser/shell_desktop_controller.h" | |
10 #include "apps/shell/browser/shell_extension_system.h" | |
11 #include "apps/shell/browser/shell_extension_system_factory.h" | |
12 #include "apps/shell/browser/shell_extensions_browser_client.h" | |
13 #include "apps/shell/browser/shell_omaha_query_params_delegate.h" | |
14 #include "apps/shell/common/shell_extensions_client.h" | |
15 #include "apps/shell/common/switches.h" | |
16 #include "base/command_line.h" | 7 #include "base/command_line.h" |
17 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
18 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 9 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
19 #include "components/omaha_query_params/omaha_query_params.h" | 10 #include "components/omaha_query_params/omaha_query_params.h" |
20 #include "content/public/common/result_codes.h" | 11 #include "content/public/common/result_codes.h" |
21 #include "content/shell/browser/shell_devtools_delegate.h" | 12 #include "content/shell/browser/shell_devtools_delegate.h" |
22 #include "content/shell/browser/shell_net_log.h" | 13 #include "content/shell/browser/shell_net_log.h" |
23 #include "extensions/browser/browser_context_keyed_service_factories.h" | 14 #include "extensions/browser/browser_context_keyed_service_factories.h" |
24 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
| 16 #include "extensions/shell/browser/shell_browser_context.h" |
| 17 #include "extensions/shell/browser/shell_browser_main_delegate.h" |
| 18 #include "extensions/shell/browser/shell_desktop_controller.h" |
| 19 #include "extensions/shell/browser/shell_extension_system.h" |
| 20 #include "extensions/shell/browser/shell_extension_system_factory.h" |
| 21 #include "extensions/shell/browser/shell_extensions_browser_client.h" |
| 22 #include "extensions/shell/browser/shell_omaha_query_params_delegate.h" |
| 23 #include "extensions/shell/common/shell_extensions_client.h" |
| 24 #include "extensions/shell/common/switches.h" |
25 #include "ui/aura/window_tree_host.h" | 25 #include "ui/aura/window_tree_host.h" |
26 #include "ui/base/ime/input_method_initializer.h" | 26 #include "ui/base/ime/input_method_initializer.h" |
27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
28 | 28 |
29 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
30 #include "apps/shell/browser/shell_network_controller_chromeos.h" | |
31 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
| 31 #include "extensions/shell/browser/shell_network_controller_chromeos.h" |
32 #endif | 32 #endif |
33 | 33 |
34 using content::BrowserContext; | 34 using content::BrowserContext; |
35 using extensions::Extension; | |
36 using extensions::ExtensionSystem; | |
37 using extensions::ShellExtensionSystem; | |
38 | 35 |
39 namespace { | 36 namespace { |
40 | 37 |
41 // Register additional KeyedService factories here. See | 38 // Register additional KeyedService factories here. See |
42 // ChromeBrowserMainExtraPartsProfiles for details. | 39 // ChromeBrowserMainExtraPartsProfiles for details. |
43 void EnsureBrowserContextKeyedServiceFactoriesBuilt() { | 40 void EnsureBrowserContextKeyedServiceFactoriesBuilt() { |
44 extensions::EnsureBrowserContextKeyedServiceFactoriesBuilt(); | 41 extensions::EnsureBrowserContextKeyedServiceFactoriesBuilt(); |
45 extensions::ShellExtensionSystemFactory::GetInstance(); | 42 extensions::ShellExtensionSystemFactory::GetInstance(); |
46 } | 43 } |
47 | 44 |
48 } // namespace | 45 } // namespace |
49 | 46 |
50 namespace apps { | 47 namespace extensions { |
51 | 48 |
52 ShellBrowserMainParts::ShellBrowserMainParts( | 49 ShellBrowserMainParts::ShellBrowserMainParts( |
53 const content::MainFunctionParams& parameters, | 50 const content::MainFunctionParams& parameters, |
54 ShellBrowserMainDelegate* browser_main_delegate) | 51 ShellBrowserMainDelegate* browser_main_delegate) |
55 : extension_system_(NULL), | 52 : extension_system_(NULL), |
56 parameters_(parameters), | 53 parameters_(parameters), |
57 run_message_loop_(true), | 54 run_message_loop_(true), |
58 browser_main_delegate_(browser_main_delegate) { | 55 browser_main_delegate_(browser_main_delegate) { |
59 } | 56 } |
60 | 57 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 browser_context_.reset(new ShellBrowserContext); | 89 browser_context_.reset(new ShellBrowserContext); |
93 | 90 |
94 desktop_controller_.reset(browser_main_delegate_->CreateDesktopController()); | 91 desktop_controller_.reset(browser_main_delegate_->CreateDesktopController()); |
95 desktop_controller_->CreateRootWindow(); | 92 desktop_controller_->CreateRootWindow(); |
96 | 93 |
97 // NOTE: Much of this is culled from chrome/test/base/chrome_test_suite.cc | 94 // NOTE: Much of this is culled from chrome/test/base/chrome_test_suite.cc |
98 // TODO(jamescook): Initialize chromeos::UserManager. | 95 // TODO(jamescook): Initialize chromeos::UserManager. |
99 net_log_.reset(new content::ShellNetLog("app_shell")); | 96 net_log_.reset(new content::ShellNetLog("app_shell")); |
100 | 97 |
101 extensions_client_.reset(new ShellExtensionsClient()); | 98 extensions_client_.reset(new ShellExtensionsClient()); |
102 extensions::ExtensionsClient::Set(extensions_client_.get()); | 99 ExtensionsClient::Set(extensions_client_.get()); |
103 | 100 |
104 extensions_browser_client_.reset( | 101 extensions_browser_client_.reset( |
105 new extensions::ShellExtensionsBrowserClient(browser_context_.get())); | 102 new ShellExtensionsBrowserClient(browser_context_.get())); |
106 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get()); | 103 ExtensionsBrowserClient::Set(extensions_browser_client_.get()); |
107 | 104 |
108 omaha_query_params_delegate_.reset( | 105 omaha_query_params_delegate_.reset(new ShellOmahaQueryParamsDelegate); |
109 new extensions::ShellOmahaQueryParamsDelegate); | |
110 omaha_query_params::OmahaQueryParams::SetDelegate( | 106 omaha_query_params::OmahaQueryParams::SetDelegate( |
111 omaha_query_params_delegate_.get()); | 107 omaha_query_params_delegate_.get()); |
112 | 108 |
113 // Create our custom ExtensionSystem first because other | 109 // Create our custom ExtensionSystem first because other |
114 // KeyedServices depend on it. | 110 // KeyedServices depend on it. |
115 // TODO(yoz): Move this after EnsureBrowserContextKeyedServiceFactoriesBuilt. | 111 // TODO(yoz): Move this after EnsureBrowserContextKeyedServiceFactoriesBuilt. |
116 CreateExtensionSystem(); | 112 CreateExtensionSystem(); |
117 | 113 |
118 ::EnsureBrowserContextKeyedServiceFactoriesBuilt(); | 114 ::EnsureBrowserContextKeyedServiceFactoriesBuilt(); |
119 BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( | 115 BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( |
120 browser_context_.get()); | 116 browser_context_.get()); |
121 | 117 |
122 devtools_delegate_.reset( | 118 devtools_delegate_.reset( |
123 new content::ShellDevToolsDelegate(browser_context_.get())); | 119 new content::ShellDevToolsDelegate(browser_context_.get())); |
124 if (parameters_.ui_task) { | 120 if (parameters_.ui_task) { |
125 // For running browser tests. | 121 // For running browser tests. |
126 parameters_.ui_task->Run(); | 122 parameters_.ui_task->Run(); |
127 delete parameters_.ui_task; | 123 delete parameters_.ui_task; |
128 run_message_loop_ = false; | 124 run_message_loop_ = false; |
129 } else { | 125 } else { |
130 browser_main_delegate_->Start(browser_context_.get()); | 126 browser_main_delegate_->Start(browser_context_.get()); |
131 } | 127 } |
132 } | 128 } |
133 | 129 |
134 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { | 130 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { |
135 if (!run_message_loop_) | 131 if (!run_message_loop_) |
136 return true; | 132 return true; |
137 // TODO(yoz): just return false here? | 133 // TODO(yoz): just return false here? |
138 base::RunLoop run_loop; | 134 base::RunLoop run_loop; |
139 run_loop.Run(); | 135 run_loop.Run(); |
140 *result_code = content::RESULT_CODE_NORMAL_EXIT; | 136 *result_code = content::RESULT_CODE_NORMAL_EXIT; |
141 return true; | 137 return true; |
142 } | 138 } |
143 | 139 |
144 void ShellBrowserMainParts::PostMainMessageLoopRun() { | 140 void ShellBrowserMainParts::PostMainMessageLoopRun() { |
145 browser_main_delegate_->Shutdown(); | 141 browser_main_delegate_->Shutdown(); |
146 | 142 |
147 BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices( | 143 BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices( |
148 browser_context_.get()); | 144 browser_context_.get()); |
149 extension_system_ = NULL; | 145 extension_system_ = NULL; |
150 extensions::ExtensionsBrowserClient::Set(NULL); | 146 ExtensionsBrowserClient::Set(NULL); |
151 extensions_browser_client_.reset(); | 147 extensions_browser_client_.reset(); |
152 browser_context_.reset(); | 148 browser_context_.reset(); |
153 | 149 |
154 desktop_controller_.reset(); | 150 desktop_controller_.reset(); |
155 } | 151 } |
156 | 152 |
157 void ShellBrowserMainParts::PostDestroyThreads() { | 153 void ShellBrowserMainParts::PostDestroyThreads() { |
158 #if defined(OS_CHROMEOS) | 154 #if defined(OS_CHROMEOS) |
159 network_controller_.reset(); | 155 network_controller_.reset(); |
160 chromeos::DBusThreadManager::Shutdown(); | 156 chromeos::DBusThreadManager::Shutdown(); |
161 #endif | 157 #endif |
162 } | 158 } |
163 | 159 |
164 void ShellBrowserMainParts::CreateExtensionSystem() { | 160 void ShellBrowserMainParts::CreateExtensionSystem() { |
165 DCHECK(browser_context_); | 161 DCHECK(browser_context_); |
166 extension_system_ = static_cast<ShellExtensionSystem*>( | 162 extension_system_ = static_cast<ShellExtensionSystem*>( |
167 ExtensionSystem::Get(browser_context_.get())); | 163 ExtensionSystem::Get(browser_context_.get())); |
168 extension_system_->InitForRegularProfile(true); | 164 extension_system_->InitForRegularProfile(true); |
169 } | 165 } |
170 | 166 |
171 } // namespace apps | 167 } // namespace extensions |
OLD | NEW |