| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromecast/shell/app/cast_main_delegate.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/cpu.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "base/posix/global_descriptors.h" | |
| 12 #include "chromecast/common/cast_paths.h" | |
| 13 #include "chromecast/common/cast_resource_delegate.h" | |
| 14 #include "chromecast/common/global_descriptors.h" | |
| 15 #include "chromecast/shell/browser/cast_content_browser_client.h" | |
| 16 #include "chromecast/shell/renderer/cast_content_renderer_client.h" | |
| 17 #include "content/public/browser/browser_main_runner.h" | |
| 18 #include "content/public/common/content_switches.h" | |
| 19 #include "ui/base/resource/resource_bundle.h" | |
| 20 | |
| 21 #if defined(OS_ANDROID) | |
| 22 #include "chromecast/crash/android/crash_handler.h" | |
| 23 #endif // defined(OS_ANDROID) | |
| 24 | |
| 25 namespace chromecast { | |
| 26 namespace shell { | |
| 27 | |
| 28 CastMainDelegate::CastMainDelegate() { | |
| 29 } | |
| 30 | |
| 31 CastMainDelegate::~CastMainDelegate() { | |
| 32 } | |
| 33 | |
| 34 bool CastMainDelegate::BasicStartupComplete(int* exit_code) { | |
| 35 RegisterPathProvider(); | |
| 36 | |
| 37 logging::LoggingSettings settings; | |
| 38 #if defined(OS_ANDROID) | |
| 39 base::FilePath log_file; | |
| 40 PathService::Get(FILE_CAST_ANDROID_LOG, &log_file); | |
| 41 settings.logging_dest = logging::LOG_TO_ALL; | |
| 42 settings.log_file = log_file.value().c_str(); | |
| 43 settings.delete_old = logging::DELETE_OLD_LOG_FILE; | |
| 44 #else | |
| 45 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
| 46 #endif // defined(OS_ANDROID) | |
| 47 logging::InitLogging(settings); | |
| 48 // Time, process, and thread ID are available through logcat. | |
| 49 logging::SetLogItems(true, true, false, false); | |
| 50 | |
| 51 content::SetContentClient(&content_client_); | |
| 52 return false; | |
| 53 } | |
| 54 | |
| 55 void CastMainDelegate::PreSandboxStartup() { | |
| 56 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) | |
| 57 // Create an instance of the CPU class to parse /proc/cpuinfo and cache the | |
| 58 // results. This data needs to be cached when file-reading is still allowed, | |
| 59 // since base::CPU expects to be callable later, when file-reading is no | |
| 60 // longer allowed. | |
| 61 base::CPU cpu_info; | |
| 62 #endif | |
| 63 | |
| 64 const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess()); | |
| 65 std::string process_type = | |
| 66 command_line->GetSwitchValueASCII(switches::kProcessType); | |
| 67 | |
| 68 #if defined(OS_ANDROID) | |
| 69 base::FilePath log_file; | |
| 70 PathService::Get(FILE_CAST_ANDROID_LOG, &log_file); | |
| 71 chromecast::CrashHandler::Initialize(process_type, log_file); | |
| 72 #endif // defined(OS_ANDROID) | |
| 73 | |
| 74 InitializeResourceBundle(); | |
| 75 } | |
| 76 | |
| 77 int CastMainDelegate::RunProcess( | |
| 78 const std::string& process_type, | |
| 79 const content::MainFunctionParams& main_function_params) { | |
| 80 #if defined(OS_ANDROID) | |
| 81 if (!process_type.empty()) | |
| 82 return -1; | |
| 83 | |
| 84 // Note: Android must handle running its own browser process. | |
| 85 // See ChromeMainDelegateAndroid::RunProcess. | |
| 86 browser_runner_.reset(content::BrowserMainRunner::Create()); | |
| 87 return browser_runner_->Initialize(main_function_params); | |
| 88 #else | |
| 89 return -1; | |
| 90 #endif // defined(OS_ANDROID) | |
| 91 } | |
| 92 | |
| 93 #if !defined(OS_ANDROID) | |
| 94 void CastMainDelegate::ZygoteForked() { | |
| 95 } | |
| 96 #endif // !defined(OS_ANDROID) | |
| 97 | |
| 98 void CastMainDelegate::InitializeResourceBundle() { | |
| 99 #if defined(OS_ANDROID) | |
| 100 // On Android, the renderer runs with a different UID and can never access | |
| 101 // the file system. Use the file descriptor passed in at launch time. | |
| 102 int pak_fd = | |
| 103 base::GlobalDescriptors::GetInstance()->MaybeGet(kAndroidPakDescriptor); | |
| 104 if (pak_fd >= 0) { | |
| 105 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | |
| 106 base::File(pak_fd), base::MemoryMappedFile::Region::kWholeFile); | |
| 107 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | |
| 108 base::File(pak_fd), ui::SCALE_FACTOR_100P); | |
| 109 return; | |
| 110 } | |
| 111 #endif // defined(OS_ANDROID) | |
| 112 | |
| 113 resource_delegate_.reset(new CastResourceDelegate()); | |
| 114 // TODO(gunsch): Use LOAD_COMMON_RESOURCES once ResourceBundle no longer | |
| 115 // hardcodes resource file names. | |
| 116 ui::ResourceBundle::InitSharedInstanceWithLocale( | |
| 117 "en-US", | |
| 118 resource_delegate_.get(), | |
| 119 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); | |
| 120 | |
| 121 base::FilePath pak_file; | |
| 122 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file)); | |
| 123 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | |
| 124 pak_file, | |
| 125 ui::SCALE_FACTOR_NONE); | |
| 126 } | |
| 127 | |
| 128 content::ContentBrowserClient* CastMainDelegate::CreateContentBrowserClient() { | |
| 129 browser_client_.reset(new CastContentBrowserClient); | |
| 130 return browser_client_.get(); | |
| 131 } | |
| 132 | |
| 133 content::ContentRendererClient* | |
| 134 CastMainDelegate::CreateContentRendererClient() { | |
| 135 renderer_client_.reset(new CastContentRendererClient); | |
| 136 return renderer_client_.get(); | |
| 137 } | |
| 138 | |
| 139 } // namespace shell | |
| 140 } // namespace chromecast | |
| OLD | NEW |