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

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

Issue 490603002: Chromecast: initial checkin of Android-based cast shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: naming change Created 6 years, 3 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/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 the
Yaron 2014/09/06 01:10:14 why is LINUX included here?
gunsch 2014/09/08 19:42:23 Not sure, but ShellMainDelegate and ChromeMainDele
53 // results. This data needs to be cached when file-reading is still allowed,
54 // since base::CPU expects to be callable later, when file-reading is no
55 // longer allowed.
56 base::CPU cpu_info;
57 #endif
58
39 InitializeResourceBundle(); 59 InitializeResourceBundle();
40 } 60 }
41 61
62 int CastMainDelegate::RunProcess(
63 const std::string& process_type,
64 const content::MainFunctionParams& main_function_params) {
65 #if defined(OS_ANDROID)
66 if (!process_type.empty())
67 return -1;
68
69 // Note: Android must handle running its own browser process.
70 // See ChromeMainDelegateAndroid::RunProcess.
71 browser_runner_.reset(content::BrowserMainRunner::Create());
72 return browser_runner_->Initialize(main_function_params);
73 #else
74 return -1;
75 #endif // defined(OS_ANDROID)
76 }
77
78 #if !defined(OS_ANDROID)
42 void CastMainDelegate::ZygoteForked() { 79 void CastMainDelegate::ZygoteForked() {
43 } 80 }
81 #endif // !defined(OS_ANDROID)
44 82
45 void CastMainDelegate::InitializeResourceBundle() { 83 void CastMainDelegate::InitializeResourceBundle() {
84 #if defined(OS_ANDROID)
85 // On Android, the renderer runs with a different UID and can never access
86 // the file system. Use the file descriptor passed in at launch time.
87 int pak_fd =
88 base::GlobalDescriptors::GetInstance()->MaybeGet(kAndroidPakDescriptor);
89 if (pak_fd >= 0) {
90 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
91 base::File(pak_fd), base::MemoryMappedFile::Region::kWholeFile);
92 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
93 base::File(pak_fd), ui::SCALE_FACTOR_100P);
94 return;
95 }
96 #endif
97
46 resource_delegate_.reset(new CastResourceDelegate()); 98 resource_delegate_.reset(new CastResourceDelegate());
47 // TODO(gunsch): Use LOAD_COMMON_RESOURCES once ResourceBundle no longer 99 // TODO(gunsch): Use LOAD_COMMON_RESOURCES once ResourceBundle no longer
48 // hardcodes resource file names. 100 // hardcodes resource file names.
49 ui::ResourceBundle::InitSharedInstanceWithLocale( 101 ui::ResourceBundle::InitSharedInstanceWithLocale(
50 "en-US", 102 "en-US",
51 resource_delegate_.get(), 103 resource_delegate_.get(),
52 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); 104 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
53 105
54 base::FilePath pak_file; 106 base::FilePath pak_file;
55 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file)); 107 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file));
56 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( 108 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
57 pak_file, 109 pak_file,
58 ui::SCALE_FACTOR_NONE); 110 ui::SCALE_FACTOR_NONE);
59 } 111 }
60 112
61 content::ContentBrowserClient* CastMainDelegate::CreateContentBrowserClient() { 113 content::ContentBrowserClient* CastMainDelegate::CreateContentBrowserClient() {
62 browser_client_.reset(new CastContentBrowserClient); 114 browser_client_.reset(new CastContentBrowserClient);
63 return browser_client_.get(); 115 return browser_client_.get();
64 } 116 }
65 117
66 content::ContentRendererClient* 118 content::ContentRendererClient*
67 CastMainDelegate::CreateContentRendererClient() { 119 CastMainDelegate::CreateContentRendererClient() {
68 renderer_client_.reset(new CastContentRendererClient); 120 renderer_client_.reset(new CastContentRendererClient);
69 return renderer_client_.get(); 121 return renderer_client_.get();
70 } 122 }
71 123
72 } // namespace shell 124 } // namespace shell
73 } // namespace chromecast 125 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698