OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromecast/shell/app/cast_main_delegate.h" | 5 #include "chromecast/shell/app/cast_main_delegate.h" |
6 | 6 |
7 #include "base/cpu.h" | |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/posix/global_descriptors.h" | |
9 #include "chromecast/common/cast_paths.h" | 11 #include "chromecast/common/cast_paths.h" |
10 #include "chromecast/common/cast_resource_delegate.h" | 12 #include "chromecast/common/cast_resource_delegate.h" |
13 #include "chromecast/common/global_descriptors.h" | |
11 #include "chromecast/shell/browser/cast_content_browser_client.h" | 14 #include "chromecast/shell/browser/cast_content_browser_client.h" |
12 #include "chromecast/shell/renderer/cast_content_renderer_client.h" | 15 #include "chromecast/shell/renderer/cast_content_renderer_client.h" |
16 #include "content/public/browser/browser_main_runner.h" | |
13 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
14 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
15 | 19 |
16 namespace chromecast { | 20 namespace chromecast { |
17 namespace shell { | 21 namespace shell { |
18 | 22 |
19 CastMainDelegate::CastMainDelegate() { | 23 CastMainDelegate::CastMainDelegate() { |
20 } | 24 } |
21 | 25 |
22 CastMainDelegate::~CastMainDelegate() { | 26 CastMainDelegate::~CastMainDelegate() { |
23 } | 27 } |
24 | 28 |
25 bool CastMainDelegate::BasicStartupComplete(int* exit_code) { | 29 bool CastMainDelegate::BasicStartupComplete(int* exit_code) { |
30 RegisterPathProvider(); | |
31 | |
26 logging::LoggingSettings settings; | 32 logging::LoggingSettings settings; |
33 #if defined(OS_ANDROID) | |
34 base::FilePath log_file; | |
35 PathService::Get(FILE_CAST_ANDROID_LOG, &log_file); | |
36 settings.logging_dest = logging::LOG_TO_ALL; | |
37 settings.log_file = log_file.value().c_str(); | |
38 settings.delete_old = logging::DELETE_OLD_LOG_FILE; | |
39 #else | |
27 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 40 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
41 #endif // defined(OS_ANDROID) | |
28 logging::InitLogging(settings); | 42 logging::InitLogging(settings); |
29 // Time, process, and thread ID are available through logcat. | 43 // Time, process, and thread ID are available through logcat. |
30 logging::SetLogItems(true, true, false, false); | 44 logging::SetLogItems(true, true, false, false); |
31 | 45 |
32 RegisterPathProvider(); | |
33 | |
34 content::SetContentClient(&content_client_); | 46 content::SetContentClient(&content_client_); |
35 return false; | 47 return false; |
36 } | 48 } |
37 | 49 |
38 void CastMainDelegate::PreSandboxStartup() { | 50 void CastMainDelegate::PreSandboxStartup() { |
51 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) | |
52 // Create an instance of the CPU class to parse /proc/cpuinfo and cache | |
53 // cpu_brand info. | |
54 base::CPU cpu_info; | |
lcwu1
2014/08/27 16:47:46
This variable doesn't appear to be used.
gunsch
2014/08/28 00:12:09
True, it is not used---but instantiating it has ma
lcwu1
2014/08/28 02:40:29
I see. In that case I think we should add more com
gunsch
2014/08/28 02:59:26
Done.
| |
55 #endif | |
56 | |
39 InitializeResourceBundle(); | 57 InitializeResourceBundle(); |
40 } | 58 } |
41 | 59 |
60 int CastMainDelegate::RunProcess( | |
61 const std::string& process_type, | |
62 const content::MainFunctionParams& main_function_params) { | |
63 #if defined(OS_ANDROID) | |
64 if (!process_type.empty()) | |
65 return -1; | |
66 | |
67 // Note: Android must handle running its own browser process. | |
68 // See ChromeMainDelegateAndroid::RunProcess. | |
69 browser_runner_.reset(content::BrowserMainRunner::Create()); | |
70 return browser_runner_->Initialize(main_function_params); | |
71 #else | |
72 return -1; | |
73 #endif // defined(OS_ANDROID) | |
74 } | |
75 | |
76 #if !defined(OS_ANDROID) | |
byungchul
2014/08/27 23:19:17
Don't you have to guard it in .h as well?
gunsch
2014/08/28 00:12:09
It is already?
| |
42 void CastMainDelegate::ZygoteForked() { | 77 void CastMainDelegate::ZygoteForked() { |
43 } | 78 } |
79 #endif // defined(OS_ANDROID) | |
44 | 80 |
45 void CastMainDelegate::InitializeResourceBundle() { | 81 void CastMainDelegate::InitializeResourceBundle() { |
82 #if defined(OS_ANDROID) | |
83 // On Android, the renderer runs with a different UID and can never access | |
84 // the file system. Use the file descriptor passed in at launch time. | |
85 int pak_fd = | |
86 base::GlobalDescriptors::GetInstance()->MaybeGet(kAndroidPakDescriptor); | |
87 if (pak_fd >= 0) { | |
88 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | |
89 base::File(pak_fd), base::MemoryMappedFile::Region::kWholeFile); | |
90 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | |
91 base::File(pak_fd), ui::SCALE_FACTOR_100P); | |
92 return; | |
93 } | |
94 #endif | |
95 | |
46 resource_delegate_.reset(new CastResourceDelegate()); | 96 resource_delegate_.reset(new CastResourceDelegate()); |
47 // TODO(gunsch): Use LOAD_COMMON_RESOURCES once ResourceBundle no longer | 97 // TODO(gunsch): Use LOAD_COMMON_RESOURCES once ResourceBundle no longer |
48 // hardcodes resource file names. | 98 // hardcodes resource file names. |
49 ui::ResourceBundle::InitSharedInstanceWithLocale( | 99 ui::ResourceBundle::InitSharedInstanceWithLocale( |
50 "en-US", | 100 "en-US", |
51 resource_delegate_.get(), | 101 resource_delegate_.get(), |
52 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); | 102 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); |
53 | 103 |
54 base::FilePath pak_file; | 104 base::FilePath pak_file; |
55 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file)); | 105 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file)); |
56 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | 106 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
57 pak_file, | 107 pak_file, |
58 ui::SCALE_FACTOR_NONE); | 108 ui::SCALE_FACTOR_NONE); |
59 } | 109 } |
60 | 110 |
61 content::ContentBrowserClient* CastMainDelegate::CreateContentBrowserClient() { | 111 content::ContentBrowserClient* CastMainDelegate::CreateContentBrowserClient() { |
62 browser_client_.reset(new CastContentBrowserClient); | 112 browser_client_.reset(new CastContentBrowserClient); |
63 return browser_client_.get(); | 113 return browser_client_.get(); |
64 } | 114 } |
65 | 115 |
66 content::ContentRendererClient* | 116 content::ContentRendererClient* |
67 CastMainDelegate::CreateContentRendererClient() { | 117 CastMainDelegate::CreateContentRendererClient() { |
68 renderer_client_.reset(new CastContentRendererClient); | 118 renderer_client_.reset(new CastContentRendererClient); |
69 return renderer_client_.get(); | 119 return renderer_client_.get(); |
70 } | 120 } |
71 | 121 |
72 } // namespace shell | 122 } // namespace shell |
73 } // namespace chromecast | 123 } // namespace chromecast |
OLD | NEW |