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

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

Issue 1185973003: Take 2: 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/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
23 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
24 #include "chrome/browser/after_startup_task_utils.h" 23 #include "chrome/browser/after_startup_task_utils.h"
25 #include "chrome/browser/browser_about_handler.h" 24 #include "chrome/browser/browser_about_handler.h"
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 incognito)); 604 incognito));
606 } 605 }
607 #endif // defined(ENABLE_EXTENSIONS) 606 #endif // defined(ENABLE_EXTENSIONS)
608 607
609 } // namespace 608 } // namespace
610 609
611 namespace chrome { 610 namespace chrome {
612 611
613 ChromeContentBrowserClient::ChromeContentBrowserClient() 612 ChromeContentBrowserClient::ChromeContentBrowserClient()
614 : 613 :
615 #if defined(OS_POSIX) && !defined(OS_MACOSX)
616 v8_natives_fd_(-1),
617 v8_snapshot_fd_(-1),
618 #endif // OS_POSIX && !OS_MACOSX
619 weak_factory_(this) { 614 weak_factory_(this) {
620 #if defined(ENABLE_PLUGINS) 615 #if defined(ENABLE_PLUGINS)
621 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) 616 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i)
622 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); 617 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
623 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) 618 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
624 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); 619 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
625 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) 620 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
626 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); 621 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
627 622
628 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); 623 extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 } 1165 }
1171 if (browser_command_line.HasSwitch( 1166 if (browser_command_line.HasSwitch(
1172 switches::kDisableOfflineAutoReloadVisibleOnly)) { 1167 switches::kDisableOfflineAutoReloadVisibleOnly)) {
1173 return false; 1168 return false;
1174 } 1169 }
1175 return true; 1170 return true;
1176 } 1171 }
1177 1172
1178 } // namespace 1173 } // namespace
1179 1174
1180 // When Chrome is updated on non-Windows platforms, the new files (like
1181 // V8 natives and snapshot) can have the same names as the previous
1182 // versions. Since the renderers for an existing Chrome browser process
1183 // are likely not compatible with the new files, the browser keeps hold
1184 // of the old files using an open fd. This fd is passed to subprocesses
1185 // like renderers. Here we add the flag to tell the subprocesses where
1186 // to find these file descriptors.
1187 void ChromeContentBrowserClient::AppendMappedFileCommandLineSwitches(
1188 base::CommandLine* command_line) {
1189 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1190 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
1191 std::string process_type =
1192 command_line->GetSwitchValueASCII(switches::kProcessType);
1193 if (process_type != switches::kZygoteProcess) {
1194 // We want to pass the natives by fd because after an update the file may
1195 // be updated, but we want the newly launched renderers to get the old one,
1196 // opened by the browser when it started.
1197 DCHECK(natives_fd_exists());
1198 command_line->AppendSwitch(::switches::kV8NativesPassedByFD);
1199 if (snapshot_fd_exists())
1200 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD);
1201 }
1202 #endif // V8_USE_EXTERNAL_STARTUP_DATA
1203 #endif // OS_POSIX && !OS_MACOSX
1204 }
1205
1206 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( 1175 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1207 base::CommandLine* command_line, 1176 base::CommandLine* command_line,
1208 int child_process_id) { 1177 int child_process_id) {
1209 #if defined(OS_MACOSX) 1178 #if defined(OS_MACOSX)
1210 scoped_ptr<metrics::ClientInfo> client_info = 1179 scoped_ptr<metrics::ClientInfo> client_info =
1211 GoogleUpdateSettings::LoadMetricsClientInfo(); 1180 GoogleUpdateSettings::LoadMetricsClientInfo();
1212 if (client_info) { 1181 if (client_info) {
1213 command_line->AppendSwitchASCII(switches::kMetricsClientID, 1182 command_line->AppendSwitchASCII(switches::kMetricsClientID,
1214 client_info->client_id); 1183 client_info->client_id);
1215 } 1184 }
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 extra_parts_[i]->GetAdditionalFileSystemBackends( 2210 extra_parts_[i]->GetAdditionalFileSystemBackends(
2242 browser_context, storage_partition_path, additional_backends); 2211 browser_context, storage_partition_path, additional_backends);
2243 } 2212 }
2244 } 2213 }
2245 2214
2246 #if defined(OS_POSIX) && !defined(OS_MACOSX) 2215 #if defined(OS_POSIX) && !defined(OS_MACOSX)
2247 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( 2216 void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2248 const base::CommandLine& command_line, 2217 const base::CommandLine& command_line,
2249 int child_process_id, 2218 int child_process_id,
2250 FileDescriptorInfo* mappings) { 2219 FileDescriptorInfo* mappings) {
2251 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
2252 if (!natives_fd_exists()) {
2253 int v8_natives_fd = -1;
2254 int v8_snapshot_fd = -1;
2255 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd,
2256 &v8_snapshot_fd)) {
2257 v8_natives_fd_.reset(v8_natives_fd);
2258 v8_snapshot_fd_.reset(v8_snapshot_fd);
2259 }
2260 }
2261 // V8 can't start up without the source of the natives, but it can
2262 // start up (slower) without the snapshot.
2263 DCHECK(natives_fd_exists());
2264 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get());
2265 if (snapshot_fd_exists())
2266 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get());
2267 #endif // V8_USE_EXTERNAL_STARTUP_DATA
2268
2269 #if defined(OS_ANDROID) 2220 #if defined(OS_ANDROID)
2270 base::FilePath data_path; 2221 base::FilePath data_path;
2271 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path); 2222 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2272 DCHECK(!data_path.empty()); 2223 DCHECK(!data_path.empty());
2273 2224
2274 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; 2225 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2275 base::FilePath chrome_resources_pak = 2226 base::FilePath chrome_resources_pak =
2276 data_path.AppendASCII("chrome_100_percent.pak"); 2227 data_path.AppendASCII("chrome_100_percent.pak");
2277 base::File file(chrome_resources_pak, flags); 2228 base::File file(chrome_resources_pak, flags);
2278 DCHECK(file.IsValid()); 2229 DCHECK(file.IsValid());
(...skipping 23 matching lines...) Expand all
2302 base::ScopedFD(file.TakePlatformFile())); 2253 base::ScopedFD(file.TakePlatformFile()));
2303 } else { 2254 } else {
2304 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " 2255 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2305 "be disabled for this process."; 2256 "be disabled for this process.";
2306 } 2257 }
2307 } 2258 }
2308 2259
2309 base::FilePath app_data_path; 2260 base::FilePath app_data_path;
2310 PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path); 2261 PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path);
2311 DCHECK(!app_data_path.empty()); 2262 DCHECK(!app_data_path.empty());
2312
2313 flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2314 base::FilePath icudata_path =
2315 app_data_path.AppendASCII(base::i18n::kIcuDataFileName);
2316 base::File icudata_file(icudata_path, flags);
2317 DCHECK(icudata_file.IsValid());
2318 mappings->Transfer(kAndroidICUDataDescriptor,
2319 base::ScopedFD(icudata_file.TakePlatformFile()));
2320 #else 2263 #else
2321 int crash_signal_fd = GetCrashSignalFD(command_line); 2264 int crash_signal_fd = GetCrashSignalFD(command_line);
2322 if (crash_signal_fd >= 0) { 2265 if (crash_signal_fd >= 0) {
2323 mappings->Share(kCrashDumpSignal, crash_signal_fd); 2266 mappings->Share(kCrashDumpSignal, crash_signal_fd);
2324 } 2267 }
2325 #endif // defined(OS_ANDROID) 2268 #endif // defined(OS_ANDROID)
2326 } 2269 }
2327 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) 2270 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
2328 2271
2329 #if defined(OS_WIN) 2272 #if defined(OS_WIN)
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2494 switches::kDisableWebRtcEncryption, 2437 switches::kDisableWebRtcEncryption,
2495 }; 2438 };
2496 to_command_line->CopySwitchesFrom(from_command_line, 2439 to_command_line->CopySwitchesFrom(from_command_line,
2497 kWebRtcDevSwitchNames, 2440 kWebRtcDevSwitchNames,
2498 arraysize(kWebRtcDevSwitchNames)); 2441 arraysize(kWebRtcDevSwitchNames));
2499 } 2442 }
2500 } 2443 }
2501 #endif // defined(ENABLE_WEBRTC) 2444 #endif // defined(ENABLE_WEBRTC)
2502 2445
2503 } // namespace chrome 2446 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.h ('k') | chromecast/browser/cast_content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698