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

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 1182443003: Moved logic for mapping child process FDs for ICU and V8 into child_process_launcher.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/scoped_file.h" 14 #include "base/files/scoped_file.h"
15 #include "base/i18n/icu_util.h"
16 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
17 #include "base/path_service.h" 16 #include "base/path_service.h"
18 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
19 #include "base/prefs/scoped_user_pref_update.h" 18 #include "base/prefs/scoped_user_pref_update.h"
20 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
22 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
23 #include "chrome/browser/after_startup_task_utils.h" 22 #include "chrome/browser/after_startup_task_utils.h"
24 #include "chrome/browser/browser_about_handler.h" 23 #include "chrome/browser/browser_about_handler.h"
25 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 #include "content/public/browser/render_process_host.h" 115 #include "content/public/browser/render_process_host.h"
117 #include "content/public/browser/render_view_host.h" 116 #include "content/public/browser/render_view_host.h"
118 #include "content/public/browser/resource_context.h" 117 #include "content/public/browser/resource_context.h"
119 #include "content/public/browser/site_instance.h" 118 #include "content/public/browser/site_instance.h"
120 #include "content/public/browser/web_contents.h" 119 #include "content/public/browser/web_contents.h"
121 #include "content/public/common/child_process_host.h" 120 #include "content/public/common/child_process_host.h"
122 #include "content/public/common/content_descriptors.h" 121 #include "content/public/common/content_descriptors.h"
123 #include "content/public/common/service_registry.h" 122 #include "content/public/common/service_registry.h"
124 #include "content/public/common/url_utils.h" 123 #include "content/public/common/url_utils.h"
125 #include "content/public/common/web_preferences.h" 124 #include "content/public/common/web_preferences.h"
126 #include "gin/v8_initializer.h"
127 #include "net/base/mime_util.h" 125 #include "net/base/mime_util.h"
128 #include "net/cookies/canonical_cookie.h" 126 #include "net/cookies/canonical_cookie.h"
129 #include "net/cookies/cookie_options.h" 127 #include "net/cookies/cookie_options.h"
130 #include "net/ssl/ssl_cert_request_info.h" 128 #include "net/ssl/ssl_cert_request_info.h"
131 #include "ppapi/host/ppapi_host.h" 129 #include "ppapi/host/ppapi_host.h"
132 #include "storage/browser/fileapi/external_mount_points.h" 130 #include "storage/browser/fileapi/external_mount_points.h"
133 #include "ui/base/l10n/l10n_util.h" 131 #include "ui/base/l10n/l10n_util.h"
134 #include "ui/base/resource/resource_bundle.h" 132 #include "ui/base/resource/resource_bundle.h"
135 #include "ui/resources/grit/ui_resources.h" 133 #include "ui/resources/grit/ui_resources.h"
136 134
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 incognito)); 598 incognito));
601 } 599 }
602 #endif // defined(ENABLE_EXTENSIONS) 600 #endif // defined(ENABLE_EXTENSIONS)
603 601
604 } // namespace 602 } // namespace
605 603
606 namespace chrome { 604 namespace chrome {
607 605
608 ChromeContentBrowserClient::ChromeContentBrowserClient() 606 ChromeContentBrowserClient::ChromeContentBrowserClient()
609 : 607 :
610 #if defined(OS_POSIX) && !defined(OS_MACOSX)
611 v8_natives_fd_(-1),
612 v8_snapshot_fd_(-1),
613 #endif // OS_POSIX && !OS_MACOSX
614 weak_factory_(this) { 608 weak_factory_(this) {
615 #if defined(ENABLE_PLUGINS) 609 #if defined(ENABLE_PLUGINS)
616 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) 610 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i)
617 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); 611 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
618 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) 612 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
619 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); 613 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
620 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) 614 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
621 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); 615 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
622 616
623 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); 617 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 } 1159 }
1166 if (browser_command_line.HasSwitch( 1160 if (browser_command_line.HasSwitch(
1167 switches::kDisableOfflineAutoReloadVisibleOnly)) { 1161 switches::kDisableOfflineAutoReloadVisibleOnly)) {
1168 return false; 1162 return false;
1169 } 1163 }
1170 return true; 1164 return true;
1171 } 1165 }
1172 1166
1173 } // namespace 1167 } // namespace
1174 1168
1175 // When Chrome is updated on non-Windows platforms, the new files (like
1176 // V8 natives and snapshot) can have the same names as the previous
1177 // versions. Since the renderers for an existing Chrome browser process
1178 // are likely not compatible with the new files, the browser keeps hold
1179 // of the old files using an open fd. This fd is passed to subprocesses
1180 // like renderers. Here we add the flag to tell the subprocesses where
1181 // to find these file descriptors.
1182 void ChromeContentBrowserClient::AppendMappedFileCommandLineSwitches(
1183 base::CommandLine* command_line) {
1184 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1185 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
1186 std::string process_type =
1187 command_line->GetSwitchValueASCII(switches::kProcessType);
1188 if (process_type != switches::kZygoteProcess) {
1189 // We want to pass the natives by fd because after an update the file may
1190 // be updated, but we want the newly launched renderers to get the old one,
1191 // opened by the browser when it started.
1192 DCHECK(natives_fd_exists());
1193 command_line->AppendSwitch(::switches::kV8NativesPassedByFD);
1194 if (snapshot_fd_exists())
1195 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD);
1196 }
1197 #endif // V8_USE_EXTERNAL_STARTUP_DATA
1198 #endif // OS_POSIX && !OS_MACOSX
1199 }
1200
1201 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( 1169 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1202 base::CommandLine* command_line, 1170 base::CommandLine* command_line,
1203 int child_process_id) { 1171 int child_process_id) {
1204 #if defined(OS_MACOSX) 1172 #if defined(OS_MACOSX)
1205 scoped_ptr<metrics::ClientInfo> client_info = 1173 scoped_ptr<metrics::ClientInfo> client_info =
1206 GoogleUpdateSettings::LoadMetricsClientInfo(); 1174 GoogleUpdateSettings::LoadMetricsClientInfo();
1207 if (client_info) { 1175 if (client_info) {
1208 command_line->AppendSwitchASCII(switches::kMetricsClientID, 1176 command_line->AppendSwitchASCII(switches::kMetricsClientID,
1209 client_info->client_id); 1177 client_info->client_id);
1210 } 1178 }
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 extra_parts_[i]->GetAdditionalFileSystemBackends( 2202 extra_parts_[i]->GetAdditionalFileSystemBackends(
2235 browser_context, storage_partition_path, additional_backends); 2203 browser_context, storage_partition_path, additional_backends);
2236 } 2204 }
2237 } 2205 }
2238 2206
2239 #if defined(OS_POSIX) && !defined(OS_MACOSX) 2207 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2240 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( 2208 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2241 const base::CommandLine& command_line, 2209 const base::CommandLine& command_line,
2242 int child_process_id, 2210 int child_process_id,
2243 FileDescriptorInfo* mappings) { 2211 FileDescriptorInfo* mappings) {
2244 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
2245 if (!natives_fd_exists()) {
2246 int v8_natives_fd = -1;
2247 int v8_snapshot_fd = -1;
2248 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd,
2249 &v8_snapshot_fd)) {
2250 v8_natives_fd_.reset(v8_natives_fd);
2251 v8_snapshot_fd_.reset(v8_snapshot_fd);
2252 }
2253 }
2254 // V8 can't start up without the source of the natives, but it can
2255 // start up (slower) without the snapshot.
2256 DCHECK(natives_fd_exists());
2257 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get());
2258 if (snapshot_fd_exists())
2259 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get());
2260 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2261
2262 #if defined(OS_ANDROID) 2212 #if defined(OS_ANDROID)
2263 base::FilePath data_path; 2213 base::FilePath data_path;
2264 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path); 2214 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2265 DCHECK(!data_path.empty()); 2215 DCHECK(!data_path.empty());
2266 2216
2267 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; 2217 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2268 base::FilePath chrome_resources_pak = 2218 base::FilePath chrome_resources_pak =
2269 data_path.AppendASCII("chrome_100_percent.pak"); 2219 data_path.AppendASCII("chrome_100_percent.pak");
2270 base::File file(chrome_resources_pak, flags); 2220 base::File file(chrome_resources_pak, flags);
2271 DCHECK(file.IsValid()); 2221 DCHECK(file.IsValid());
(...skipping 23 matching lines...) Expand all
2295 base::ScopedFD(file.TakePlatformFile())); 2245 base::ScopedFD(file.TakePlatformFile()));
2296 } else { 2246 } else {
2297 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " 2247 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2298 "be disabled for this process."; 2248 "be disabled for this process.";
2299 } 2249 }
2300 } 2250 }
2301 2251
2302 base::FilePath app_data_path; 2252 base::FilePath app_data_path;
2303 PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path); 2253 PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
2304 DCHECK(!app_data_path.empty()); 2254 DCHECK(!app_data_path.empty());
2305
2306 flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2307 base::FilePath icudata_path =
2308 app_data_path.AppendASCII(base::i18n::kIcuDataFileName);
2309 base::File icudata_file(icudata_path, flags);
2310 DCHECK(icudata_file.IsValid());
2311 mappings->Transfer(kAndroidICUDataDescriptor,
2312 base::ScopedFD(icudata_file.TakePlatformFile()));
2313 #else 2255 #else
2314 int crash_signal_fd = GetCrashSignalFD(command_line); 2256 int crash_signal_fd = GetCrashSignalFD(command_line);
2315 if (crash_signal_fd >= 0) { 2257 if (crash_signal_fd >= 0) {
2316 mappings->Share(kCrashDumpSignal, crash_signal_fd); 2258 mappings->Share(kCrashDumpSignal, crash_signal_fd);
2317 } 2259 }
2318 #endif // defined(OS_ANDROID) 2260 #endif // defined(OS_ANDROID)
2319 } 2261 }
2320 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) 2262 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2321 2263
2322 #if defined(OS_WIN) 2264 #if defined(OS_WIN)
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
2478 switches::kDisableWebRtcEncryption, 2420 switches::kDisableWebRtcEncryption,
2479 }; 2421 };
2480 to_command_line->CopySwitchesFrom(from_command_line, 2422 to_command_line->CopySwitchesFrom(from_command_line,
2481 kWebRtcDevSwitchNames, 2423 kWebRtcDevSwitchNames,
2482 arraysize(kWebRtcDevSwitchNames)); 2424 arraysize(kWebRtcDevSwitchNames));
2483 } 2425 }
2484 } 2426 }
2485 #endif // defined(ENABLE_WEBRTC) 2427 #endif // defined(ENABLE_WEBRTC)
2486 2428
2487 } // namespace chrome 2429 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698