Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: chromecast/app/cast_main_delegate.cc

Issue 1181953002: Load non-locale .pak files directly from the .apk on Android (rather than extracting on start-up). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@raw-paks
Patch Set: fix unused LoadMainAndroidPackFile Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/app/cast_main_delegate.h" 5 #include "chromecast/app/cast_main_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/cpu.h" 10 #include "base/cpu.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/posix/global_descriptors.h" 14 #include "base/posix/global_descriptors.h"
15 #include "chromecast/base/cast_paths.h" 15 #include "chromecast/base/cast_paths.h"
16 #include "chromecast/browser/cast_content_browser_client.h" 16 #include "chromecast/browser/cast_content_browser_client.h"
17 #include "chromecast/common/cast_resource_delegate.h" 17 #include "chromecast/common/cast_resource_delegate.h"
18 #include "chromecast/common/global_descriptors.h" 18 #include "chromecast/common/global_descriptors.h"
19 #include "chromecast/crash/cast_crash_reporter_client.h" 19 #include "chromecast/crash/cast_crash_reporter_client.h"
20 #include "chromecast/renderer/cast_content_renderer_client.h" 20 #include "chromecast/renderer/cast_content_renderer_client.h"
21 #include "components/crash/app/crash_reporter_client.h" 21 #include "components/crash/app/crash_reporter_client.h"
22 #include "content/public/browser/browser_main_runner.h" 22 #include "content/public/browser/browser_main_runner.h"
23 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 25
26 #if defined(OS_ANDROID) 26 #if defined(OS_ANDROID)
27 #include "base/android/apk_assets.h"
27 #include "chromecast/crash/android/crash_handler.h" 28 #include "chromecast/crash/android/crash_handler.h"
28 #endif // defined(OS_ANDROID) 29 #endif // defined(OS_ANDROID)
29 30
30 namespace { 31 namespace {
31 32
32 #if !defined(OS_ANDROID) 33 #if !defined(OS_ANDROID)
33 base::LazyInstance<chromecast::CastCrashReporterClient>::Leaky 34 base::LazyInstance<chromecast::CastCrashReporterClient>::Leaky
34 g_crash_reporter_client = LAZY_INSTANCE_INITIALIZER; 35 g_crash_reporter_client = LAZY_INSTANCE_INITIALIZER;
35 #endif // !defined(OS_ANDROID) 36 #endif // !defined(OS_ANDROID)
36 37
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 std::string process_type = 123 std::string process_type =
123 command_line->GetSwitchValueASCII(switches::kProcessType); 124 command_line->GetSwitchValueASCII(switches::kProcessType);
124 CastCrashReporterClient::InitCrashReporter(process_type); 125 CastCrashReporterClient::InitCrashReporter(process_type);
125 } 126 }
126 #endif // !defined(OS_ANDROID) 127 #endif // !defined(OS_ANDROID)
127 128
128 void CastMainDelegate::InitializeResourceBundle() { 129 void CastMainDelegate::InitializeResourceBundle() {
129 #if defined(OS_ANDROID) 130 #if defined(OS_ANDROID)
130 // On Android, the renderer runs with a different UID and can never access 131 // On Android, the renderer runs with a different UID and can never access
131 // the file system. Use the file descriptor passed in at launch time. 132 // the file system. Use the file descriptor passed in at launch time.
132 int pak_fd = 133 auto global_descriptors = base::GlobalDescriptors::GetInstance();
133 base::GlobalDescriptors::GetInstance()->MaybeGet(kAndroidPakDescriptor); 134 int pak_fd = global_descriptors->MaybeGet(kAndroidPakDescriptor);
135 base::MemoryMappedFile::Region pak_region;
134 if (pak_fd >= 0) { 136 if (pak_fd >= 0) {
135 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( 137 pak_region = global_descriptors->GetRegion(kAndroidPakDescriptor);
136 base::File(pak_fd), base::MemoryMappedFile::Region::kWholeFile); 138 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(base::File(pak_fd),
137 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( 139 pak_region);
138 base::File(pak_fd), ui::SCALE_FACTOR_100P); 140 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
141 base::File(pak_fd), pak_region, ui::SCALE_FACTOR_100P);
139 return; 142 return;
143 } else {
144 pak_fd = base::android::OpenApkAsset("assets/cast_shell.pak", &pak_region);
145 DCHECK_GE(pak_fd, 0);
146 global_descriptors->Set(kAndroidPakDescriptor, pak_fd, pak_region);
140 } 147 }
141 #endif // defined(OS_ANDROID) 148 #endif // defined(OS_ANDROID)
142 149
143 resource_delegate_.reset(new CastResourceDelegate()); 150 resource_delegate_.reset(new CastResourceDelegate());
144 // TODO(gunsch): Use LOAD_COMMON_RESOURCES once ResourceBundle no longer 151 // TODO(gunsch): Use LOAD_COMMON_RESOURCES once ResourceBundle no longer
145 // hardcodes resource file names. 152 // hardcodes resource file names.
146 ui::ResourceBundle::InitSharedInstanceWithLocale( 153 ui::ResourceBundle::InitSharedInstanceWithLocale(
147 "en-US", 154 "en-US",
148 resource_delegate_.get(), 155 resource_delegate_.get(),
149 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); 156 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
150 157
158 #if defined(OS_ANDROID)
159 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
160 base::File(pak_fd), pak_region, ui::SCALE_FACTOR_NONE);
161 #else
151 base::FilePath pak_file; 162 base::FilePath pak_file;
152 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file)); 163 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file));
153 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( 164 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
154 pak_file, 165 pak_file,
155 ui::SCALE_FACTOR_NONE); 166 ui::SCALE_FACTOR_NONE);
167 #endif // defined(OS_ANDROID)
156 } 168 }
157 169
158 content::ContentBrowserClient* CastMainDelegate::CreateContentBrowserClient() { 170 content::ContentBrowserClient* CastMainDelegate::CreateContentBrowserClient() {
159 browser_client_ = CastContentBrowserClient::Create(); 171 browser_client_ = CastContentBrowserClient::Create();
160 return browser_client_.get(); 172 return browser_client_.get();
161 } 173 }
162 174
163 content::ContentRendererClient* 175 content::ContentRendererClient*
164 CastMainDelegate::CreateContentRendererClient() { 176 CastMainDelegate::CreateContentRendererClient() {
165 renderer_client_ = CastContentRendererClient::Create(); 177 renderer_client_ = CastContentRendererClient::Create();
166 return renderer_client_.get(); 178 return renderer_client_.get();
167 } 179 }
168 180
169 } // namespace shell 181 } // namespace shell
170 } // namespace chromecast 182 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698