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 3 // found in the LICENSE file. 4 5 #include "apps/shell/app/shell_main_delegate.h" 6 7 #include "apps/shell/browser/default_shell_browser_main_delegate.h" 8 #include "apps/shell/browser/shell_content_browser_client.h" 9 #include "apps/shell/common/shell_content_client.h" 10 #include "apps/shell/renderer/shell_content_renderer_client.h" 11 #include "apps/shell/renderer/shell_renderer_main_delegate.h" 12 #include "base/command_line.h" 13 #include "base/files/file_path.h" 14 #include "base/logging.h" 15 #include "base/path_service.h" 16 #include "content/public/browser/browser_main_runner.h" 17 #include "content/public/common/content_switches.h" 18 #include "extensions/common/extension_paths.h" 19 #include "ui/base/resource/resource_bundle.h" 20 21 #if defined(OS_CHROMEOS) 22 #include "chromeos/chromeos_paths.h" 23 #endif 24 25 namespace { 26 27 void InitLogging() { 28 base::FilePath log_filename; 29 PathService::Get(base::DIR_EXE, &log_filename); 30 log_filename = log_filename.AppendASCII("app_shell.log"); 31 logging::LoggingSettings settings; 32 settings.logging_dest = logging::LOG_TO_ALL; 33 settings.log_file = log_filename.value().c_str(); 34 settings.delete_old = logging::DELETE_OLD_LOG_FILE; 35 logging::InitLogging(settings); 36 logging::SetLogItems(true, true, true, true); 37 } 38 39 } // namespace 40 41 namespace apps { 42 43 ShellMainDelegate::ShellMainDelegate() { 44 } 45 46 ShellMainDelegate::~ShellMainDelegate() { 47 } 48 49 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { 50 InitLogging(); 51 content_client_.reset(new ShellContentClient); 52 SetContentClient(content_client_.get()); 53 54 #if defined(OS_CHROMEOS) 55 chromeos::RegisterPathProvider(); 56 #endif 57 extensions::RegisterPathProvider(); 58 return false; 59 } 60 61 void ShellMainDelegate::PreSandboxStartup() { 62 std::string process_type = 63 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 64 switches::kProcessType); 65 if (ProcessNeedsResourceBundle(process_type)) 66 InitializeResourceBundle(); 67 } 68 69 content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { 70 browser_client_.reset( 71 new apps::ShellContentBrowserClient(CreateShellBrowserMainDelegate())); 72 return browser_client_.get(); 73 } 74 75 content::ContentRendererClient* 76 ShellMainDelegate::CreateContentRendererClient() { 77 renderer_client_.reset( 78 new ShellContentRendererClient(CreateShellRendererMainDelegate())); 79 return renderer_client_.get(); 80 } 81 82 ShellBrowserMainDelegate* ShellMainDelegate::CreateShellBrowserMainDelegate() { 83 return new DefaultShellBrowserMainDelegate(); 84 } 85 86 scoped_ptr<ShellRendererMainDelegate> 87 ShellMainDelegate::CreateShellRendererMainDelegate() { 88 return scoped_ptr<ShellRendererMainDelegate>(); 89 } 90 91 // static 92 bool ShellMainDelegate::ProcessNeedsResourceBundle( 93 const std::string& process_type) { 94 // The browser process has no process type flag, but needs resources. 95 // On Linux the zygote process opens the resources for the renderers. 96 return process_type.empty() || 97 process_type == switches::kZygoteProcess || 98 process_type == switches::kRendererProcess || 99 process_type == switches::kUtilityProcess; 100 } 101 102 void ShellMainDelegate::InitializeResourceBundle() { 103 base::FilePath pak_dir; 104 PathService::Get(base::DIR_MODULE, &pak_dir); 105 ui::ResourceBundle::InitSharedInstanceWithPakPath( 106 pak_dir.AppendASCII("app_shell.pak")); 107 } 108 109 } // namespace apps 110