OLD | NEW |
| (Empty) |
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(CreateShellContentBrowserClient()); | |
71 return browser_client_.get(); | |
72 } | |
73 | |
74 content::ContentBrowserClient* | |
75 ShellMainDelegate::CreateShellContentBrowserClient() { | |
76 return new apps::ShellContentBrowserClient( | |
77 new DefaultShellBrowserMainDelegate()); | |
78 } | |
79 | |
80 content::ContentRendererClient* | |
81 ShellMainDelegate::CreateContentRendererClient() { | |
82 renderer_client_.reset( | |
83 new ShellContentRendererClient(CreateShellRendererMainDelegate())); | |
84 return renderer_client_.get(); | |
85 } | |
86 | |
87 scoped_ptr<ShellRendererMainDelegate> | |
88 ShellMainDelegate::CreateShellRendererMainDelegate() { | |
89 return scoped_ptr<ShellRendererMainDelegate>(); | |
90 } | |
91 | |
92 void ShellMainDelegate::InitializeResourceBundle() { | |
93 base::FilePath pak_dir; | |
94 PathService::Get(base::DIR_MODULE, &pak_dir); | |
95 ui::ResourceBundle::InitSharedInstanceWithPakPath( | |
96 pak_dir.AppendASCII("app_shell.pak")); | |
97 } | |
98 | |
99 // static | |
100 bool ShellMainDelegate::ProcessNeedsResourceBundle( | |
101 const std::string& process_type) { | |
102 // The browser process has no process type flag, but needs resources. | |
103 // On Linux the zygote process opens the resources for the renderers. | |
104 return process_type.empty() || | |
105 process_type == switches::kZygoteProcess || | |
106 process_type == switches::kRendererProcess || | |
107 process_type == switches::kUtilityProcess; | |
108 } | |
109 | |
110 } // namespace apps | |
OLD | NEW |