Chromium Code Reviews| 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_main_delegate.h" | 5 #include "apps/shell/shell_main_delegate.h" |
| 6 | 6 |
| 7 #include "apps/shell/shell_content_browser_client.h" | 7 #include "apps/shell/shell_content_browser_client.h" |
| 8 #include "apps/shell/shell_content_client.h" | 8 #include "apps/shell/shell_content_client.h" |
| 9 #include "apps/shell/shell_content_renderer_client.h" | |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "chrome/common/chrome_paths.h" | |
| 13 #include "content/public/browser/browser_main_runner.h" | 15 #include "content/public/browser/browser_main_runner.h" |
| 16 #include "content/public/common/content_switches.h" | |
| 17 #include "extensions/common/extension_paths.h" | |
| 14 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 15 | 19 |
| 20 #if defined(OS_CHROMEOS) | |
| 21 #include "chromeos/chromeos_paths.h" | |
| 22 #endif | |
| 23 | |
| 16 namespace { | 24 namespace { |
| 17 | 25 |
| 18 void InitLogging() { | 26 void InitLogging() { |
| 19 base::FilePath log_filename; | 27 base::FilePath log_filename; |
| 20 PathService::Get(base::DIR_EXE, &log_filename); | 28 PathService::Get(base::DIR_EXE, &log_filename); |
| 21 log_filename = log_filename.AppendASCII("app_shell.log"); | 29 log_filename = log_filename.AppendASCII("app_shell.log"); |
| 22 logging::LoggingSettings settings; | 30 logging::LoggingSettings settings; |
| 23 settings.logging_dest = logging::LOG_TO_ALL; | 31 settings.logging_dest = logging::LOG_TO_ALL; |
| 24 settings.log_file = log_filename.value().c_str(); | 32 settings.log_file = log_filename.value().c_str(); |
| 25 settings.delete_old = logging::DELETE_OLD_LOG_FILE; | 33 settings.delete_old = logging::DELETE_OLD_LOG_FILE; |
| 26 logging::InitLogging(settings); | 34 logging::InitLogging(settings); |
| 27 logging::SetLogItems(true, true, true, true); | 35 logging::SetLogItems(true, true, true, true); |
| 28 } | 36 } |
| 29 | 37 |
| 30 } // namespace | 38 } // namespace |
| 31 | 39 |
| 32 namespace apps { | 40 namespace apps { |
| 33 | 41 |
| 34 ShellMainDelegate::ShellMainDelegate() { | 42 ShellMainDelegate::ShellMainDelegate() { |
| 35 } | 43 } |
| 36 | 44 |
| 37 ShellMainDelegate::~ShellMainDelegate() { | 45 ShellMainDelegate::~ShellMainDelegate() { |
| 38 } | 46 } |
| 39 | 47 |
| 40 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { | 48 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { |
| 41 InitLogging(); | 49 InitLogging(); |
| 42 content_client_.reset(new ShellContentClient); | 50 content_client_.reset(new ShellContentClient); |
| 43 SetContentClient(content_client_.get()); | 51 SetContentClient(content_client_.get()); |
| 52 | |
| 53 chrome::RegisterPathProvider(); | |
| 54 #if defined(OS_CHROMEOS) | |
| 55 chromeos::RegisterPathProvider(); | |
| 56 #endif | |
| 57 extensions::RegisterPathProvider(); | |
| 44 return false; | 58 return false; |
| 45 } | 59 } |
| 46 | 60 |
| 47 void ShellMainDelegate::PreSandboxStartup() { | 61 void ShellMainDelegate::PreSandboxStartup() { |
| 48 InitializeResourceBundle(); | 62 std::string process_type = |
| 63 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 64 switches::kProcessType); | |
| 65 if (ProcessNeedsResourceBundle(process_type)) | |
| 66 InitializeResourceBundle(); | |
| 49 } | 67 } |
| 50 | 68 |
| 51 content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { | 69 content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { |
| 52 browser_client_.reset(new apps::ShellContentBrowserClient); | 70 browser_client_.reset(new apps::ShellContentBrowserClient); |
| 53 return browser_client_.get(); | 71 return browser_client_.get(); |
| 54 } | 72 } |
| 55 | 73 |
| 56 content::ContentRendererClient* | 74 content::ContentRendererClient* |
| 57 ShellMainDelegate::CreateContentRendererClient() { | 75 ShellMainDelegate::CreateContentRendererClient() { |
| 58 // TODO(jamescook): Create a ShellContentRendererClient with the extensions | 76 renderer_client_.reset(new ShellContentRendererClient); |
| 59 // initialization pieces of ChromeContentRendererClient. | 77 return renderer_client_.get(); |
| 60 return content::ContentMainDelegate::CreateContentRendererClient(); | 78 } |
| 79 | |
| 80 // static | |
| 81 bool ShellMainDelegate::ProcessNeedsResourceBundle( | |
| 82 const std::string& process_type) { | |
| 83 // Browser process has no process type. | |
| 84 if (process_type.empty()) | |
|
Yoyo Zhou
2014/01/30 00:49:54
nit: combine this with the below?
James Cook
2014/01/30 01:10:13
Done.
| |
| 85 return true; | |
| 86 | |
| 87 // On Linux the zygote process opens the resources for the renderers. | |
| 88 return process_type == switches::kZygoteProcess || | |
| 89 process_type == switches::kRendererProcess || | |
| 90 process_type == switches::kUtilityProcess; | |
| 61 } | 91 } |
| 62 | 92 |
| 63 void ShellMainDelegate::InitializeResourceBundle() { | 93 void ShellMainDelegate::InitializeResourceBundle() { |
| 64 ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); | 94 ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); |
| 95 | |
| 96 // The extensions system needs manifest data from the Chrome PAK file. | |
| 97 // TODO(jamescook): app_shell needs its own manifest data file. | |
| 98 base::FilePath resources_pack_path; | |
| 99 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | |
| 100 ResourceBundle::GetSharedInstance().AddDataPackFromPath( | |
| 101 resources_pack_path, ui::SCALE_FACTOR_NONE); | |
| 65 } | 102 } |
| 66 | 103 |
| 67 } // namespace apps | 104 } // namespace apps |
| OLD | NEW |