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/shell_browser_main_parts.h" | 5 #include "apps/shell/shell_browser_main_parts.h" |
6 | 6 |
7 #include "apps/shell/shell_browser_context.h" | 7 #include "apps/shell/shell_browser_context.h" |
8 #include "apps/shell/shell_extension_system.h" | 8 #include "apps/shell/shell_extension_system.h" |
9 #include "apps/shell/shell_extensions_browser_client.h" | 9 #include "apps/shell/shell_extensions_browser_client.h" |
10 #include "apps/shell/shell_extensions_client.h" | 10 #include "apps/shell/shell_extensions_client.h" |
11 #include "apps/shell/web_view_window.h" | 11 #include "apps/shell/web_view_window.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "chrome/browser/extensions/extension_system_factory.h" | 16 #include "chrome/browser/extensions/extension_prefs_factory.h" |
17 #include "chrome/browser/extensions/extension_system.h" | |
17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
18 #include "chromeos/chromeos_paths.h" | 19 #include "chromeos/chromeos_paths.h" |
20 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | |
19 #include "content/public/common/result_codes.h" | 21 #include "content/public/common/result_codes.h" |
20 #include "extensions/common/extension_paths.h" | 22 #include "extensions/common/extension_paths.h" |
21 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
22 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
23 #include "ui/aura/test/test_screen.h" | 25 #include "ui/aura/test/test_screen.h" |
24 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
26 #include "ui/wm/test/wm_test_helper.h" | 28 #include "ui/wm/test/wm_test_helper.h" |
27 | 29 |
28 using content::BrowserContext; | 30 using content::BrowserContext; |
29 using extensions::Extension; | 31 using extensions::Extension; |
32 using extensions::ExtensionSystem; | |
33 using extensions::ShellExtensionSystem; | |
30 | 34 |
31 namespace apps { | 35 namespace apps { |
36 namespace { | |
37 | |
38 // TODO(jamescook): Register additional BrowserContextKeyedService factories | |
39 // here. See ChromeBrowserMainExtraPartsProfiles for details. | |
40 void EnsureBrowserContextKeyedServiceFactoriesBuilt() { | |
41 extensions::ExtensionPrefsFactory::GetInstance(); | |
Yoyo Zhou
2014/01/08 02:29:42
Is there some reason this can't be declared as a D
James Cook
2014/01/08 17:37:02
Yeah, it should be done there. Chrome does it in b
| |
42 } | |
43 | |
44 } // namespace | |
32 | 45 |
33 ShellBrowserMainParts::ShellBrowserMainParts( | 46 ShellBrowserMainParts::ShellBrowserMainParts( |
34 const content::MainFunctionParams& parameters) | 47 const content::MainFunctionParams& parameters) |
35 : extension_system_(NULL) { | 48 : extension_system_(NULL) { |
36 } | 49 } |
37 | 50 |
38 ShellBrowserMainParts::~ShellBrowserMainParts() { | 51 ShellBrowserMainParts::~ShellBrowserMainParts() { |
39 } | 52 } |
40 | 53 |
41 void ShellBrowserMainParts::PreMainMessageLoopStart() { | 54 void ShellBrowserMainParts::PreMainMessageLoopStart() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 // Initialize our "profile" equivalent. | 86 // Initialize our "profile" equivalent. |
74 browser_context_.reset(new ShellBrowserContext); | 87 browser_context_.reset(new ShellBrowserContext); |
75 | 88 |
76 extensions_client_.reset(new ShellExtensionsClient()); | 89 extensions_client_.reset(new ShellExtensionsClient()); |
77 extensions::ExtensionsClient::Set(extensions_client_.get()); | 90 extensions::ExtensionsClient::Set(extensions_client_.get()); |
78 | 91 |
79 extensions_browser_client_.reset( | 92 extensions_browser_client_.reset( |
80 new ShellExtensionsBrowserClient(browser_context_.get())); | 93 new ShellExtensionsBrowserClient(browser_context_.get())); |
81 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get()); | 94 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get()); |
82 | 95 |
83 // TODO(jamescook): Initialize policy::ProfilePolicyConnector. | 96 // Create our custom ExtensionSystem first because other |
84 | 97 // BrowserContextKeyedServices depend on it. |
85 CreateExtensionSystem(); | 98 CreateExtensionSystem(); |
86 | 99 |
87 // TODO(jamescook): Create the rest of the services using | 100 EnsureBrowserContextKeyedServiceFactoriesBuilt(); |
88 // BrowserContextDependencyManager::CreateBrowserContextServices. | 101 BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( |
102 browser_context_.get()); | |
89 | 103 |
90 CreateRootWindow(); | 104 CreateRootWindow(); |
91 | 105 |
92 const std::string kAppSwitch = "app"; | 106 const std::string kAppSwitch = "app"; |
93 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 107 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
94 if (command_line->HasSwitch(kAppSwitch)) { | 108 if (command_line->HasSwitch(kAppSwitch)) { |
95 base::FilePath app_dir(command_line->GetSwitchValueNative(kAppSwitch)); | 109 base::FilePath app_dir(command_line->GetSwitchValueNative(kAppSwitch)); |
96 extension_system_->LoadAndLaunchApp(app_dir); | 110 extension_system_->LoadAndLaunchApp(app_dir); |
97 } else { | 111 } else { |
98 // TODO(jamescook): For demo purposes create a window with a WebView just | 112 // TODO(jamescook): For demo purposes create a window with a WebView just |
99 // to ensure that the content module is properly initialized. | 113 // to ensure that the content module is properly initialized. |
100 ShowWebViewWindow(browser_context_.get(), | 114 ShowWebViewWindow(browser_context_.get(), |
101 wm_test_helper_->root_window()->window()); | 115 wm_test_helper_->root_window()->window()); |
102 } | 116 } |
103 } | 117 } |
104 | 118 |
105 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { | 119 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { |
106 base::RunLoop run_loop; | 120 base::RunLoop run_loop; |
107 run_loop.Run(); | 121 run_loop.Run(); |
108 *result_code = content::RESULT_CODE_NORMAL_EXIT; | 122 *result_code = content::RESULT_CODE_NORMAL_EXIT; |
109 return true; | 123 return true; |
110 } | 124 } |
111 | 125 |
112 void ShellBrowserMainParts::PostMainMessageLoopRun() { | 126 void ShellBrowserMainParts::PostMainMessageLoopRun() { |
113 DestroyRootWindow(); | 127 DestroyRootWindow(); |
114 // TODO(jamescook): Destroy the rest of the services with | 128 BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices( |
115 // BrowserContextDependencyManager::DestroyBrowserContextServices. | 129 browser_context_.get()); |
130 extension_system_ = NULL; | |
116 extensions::ExtensionsBrowserClient::Set(NULL); | 131 extensions::ExtensionsBrowserClient::Set(NULL); |
117 extensions_browser_client_.reset(); | 132 extensions_browser_client_.reset(); |
118 browser_context_.reset(); | 133 browser_context_.reset(); |
119 aura::Env::DeleteInstance(); | 134 aura::Env::DeleteInstance(); |
120 | |
121 LOG(WARNING) << "-----------------------------------"; | |
122 LOG(WARNING) << "app_shell is expected to crash now."; | |
123 LOG(WARNING) << "-----------------------------------"; | |
124 } | 135 } |
125 | 136 |
126 void ShellBrowserMainParts::OnRootWindowHostCloseRequested( | 137 void ShellBrowserMainParts::OnRootWindowHostCloseRequested( |
127 const aura::RootWindow* root) { | 138 const aura::RootWindow* root) { |
128 base::MessageLoop::current()->PostTask(FROM_HERE, | 139 base::MessageLoop::current()->PostTask(FROM_HERE, |
129 base::MessageLoop::QuitClosure()); | 140 base::MessageLoop::QuitClosure()); |
130 } | 141 } |
131 | 142 |
132 void ShellBrowserMainParts::CreateRootWindow() { | 143 void ShellBrowserMainParts::CreateRootWindow() { |
133 test_screen_.reset(aura::TestScreen::Create()); | 144 test_screen_.reset(aura::TestScreen::Create()); |
134 // TODO(jamescook): Replace this with a real Screen implementation. | 145 // TODO(jamescook): Replace this with a real Screen implementation. |
135 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); | 146 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); |
136 // Set up basic pieces of views::corewm. | 147 // Set up basic pieces of views::corewm. |
137 wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600))); | 148 wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600))); |
138 // Ensure the X window gets mapped. | 149 // Ensure the X window gets mapped. |
139 wm_test_helper_->root_window()->host()->Show(); | 150 wm_test_helper_->root_window()->host()->Show(); |
140 // Watch for the user clicking the close box. | 151 // Watch for the user clicking the close box. |
141 wm_test_helper_->root_window()->AddRootWindowObserver(this); | 152 wm_test_helper_->root_window()->AddRootWindowObserver(this); |
142 } | 153 } |
143 | 154 |
144 void ShellBrowserMainParts::DestroyRootWindow() { | 155 void ShellBrowserMainParts::DestroyRootWindow() { |
145 wm_test_helper_->root_window()->RemoveRootWindowObserver(this); | 156 wm_test_helper_->root_window()->RemoveRootWindowObserver(this); |
146 wm_test_helper_->root_window()->PrepareForShutdown(); | 157 wm_test_helper_->root_window()->PrepareForShutdown(); |
147 wm_test_helper_.reset(); | 158 wm_test_helper_.reset(); |
148 } | 159 } |
149 | 160 |
150 void ShellBrowserMainParts::CreateExtensionSystem() { | 161 void ShellBrowserMainParts::CreateExtensionSystem() { |
151 DCHECK(browser_context_); | 162 DCHECK(browser_context_); |
152 extension_system_ = | 163 extension_system_ = static_cast<ShellExtensionSystem*>( |
153 new extensions::ShellExtensionSystem(browser_context_.get()); | 164 ExtensionSystem::GetForBrowserContext(browser_context_.get())); |
154 extensions::ExtensionSystemFactory::GetInstance()->SetCustomInstance( | |
155 extension_system_); | |
156 // Must occur after setting the instance above, as it will end up calling | |
157 // ExtensionSystem::Get(). | |
158 extension_system_->InitForRegularProfile(true); | 165 extension_system_->InitForRegularProfile(true); |
159 } | 166 } |
160 | 167 |
161 } // namespace apps | 168 } // namespace apps |
OLD | NEW |