OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Represents the browser side of the browser <--> renderer communication | 5 // Represents the browser side of the browser <--> renderer communication |
6 // channel. There will be one RenderProcessHost per renderer process. | 6 // channel. There will be one RenderProcessHost per renderer process. |
7 | 7 |
8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <limits> | 11 #include <limits> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/base_switches.h" | 15 #include "base/base_switches.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
18 #include "base/callback.h" | 18 #include "base/callback.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "base/debug/dump_without_crashing.h" | 20 #include "base/debug/dump_without_crashing.h" |
21 #include "base/feature_list.h" | 21 #include "base/feature_list.h" |
22 #include "base/files/file.h" | 22 #include "base/files/file.h" |
23 #include "base/lazy_instance.h" | 23 #include "base/lazy_instance.h" |
24 #include "base/location.h" | 24 #include "base/location.h" |
25 #include "base/logging.h" | 25 #include "base/logging.h" |
26 #include "base/macros.h" | 26 #include "base/macros.h" |
27 #include "base/memory/shared_memory.h" | |
28 #include "base/memory/shared_memory_handle.h" | |
27 #include "base/metrics/field_trial.h" | 29 #include "base/metrics/field_trial.h" |
28 #include "base/metrics/histogram.h" | 30 #include "base/metrics/histogram.h" |
31 #include "base/metrics/persistent_histogram_allocator.h" | |
32 #include "base/metrics/persistent_memory_allocator.h" | |
29 #include "base/process/process_handle.h" | 33 #include "base/process/process_handle.h" |
30 #include "base/rand_util.h" | 34 #include "base/rand_util.h" |
31 #include "base/single_thread_task_runner.h" | 35 #include "base/single_thread_task_runner.h" |
32 #include "base/stl_util.h" | 36 #include "base/stl_util.h" |
33 #include "base/strings/string_number_conversions.h" | 37 #include "base/strings/string_number_conversions.h" |
34 #include "base/supports_user_data.h" | 38 #include "base/supports_user_data.h" |
35 #include "base/sys_info.h" | 39 #include "base/sys_info.h" |
36 #include "base/threading/thread.h" | 40 #include "base/threading/thread.h" |
37 #include "base/threading/thread_restrictions.h" | 41 #include "base/threading/thread_restrictions.h" |
38 #include "base/trace_event/trace_event.h" | 42 #include "base/trace_event/trace_event.h" |
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1114 | 1118 |
1115 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1119 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
1116 Send(new ViewMsg_TimezoneChange(zone_id)); | 1120 Send(new ViewMsg_TimezoneChange(zone_id)); |
1117 } | 1121 } |
1118 | 1122 |
1119 ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() { | 1123 ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() { |
1120 DCHECK(mojo_application_host_); | 1124 DCHECK(mojo_application_host_); |
1121 return mojo_application_host_->service_registry(); | 1125 return mojo_application_host_->service_registry(); |
1122 } | 1126 } |
1123 | 1127 |
1128 scoped_ptr<base::SharedPersistentMemoryAllocator> | |
1129 RenderProcessHostImpl::TakeMetricsAllocator() { | |
1130 return std::move(metrics_allocator_); | |
1131 } | |
1132 | |
1124 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1133 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
1125 const { | 1134 const { |
1126 return init_time_; | 1135 return init_time_; |
1127 } | 1136 } |
1128 | 1137 |
1129 bool RenderProcessHostImpl::SubscribeUniformEnabled() const { | 1138 bool RenderProcessHostImpl::SubscribeUniformEnabled() const { |
1130 return subscribe_uniform_enabled_; | 1139 return subscribe_uniform_enabled_; |
1131 } | 1140 } |
1132 | 1141 |
1133 void RenderProcessHostImpl::OnAddSubscription(unsigned int target) { | 1142 void RenderProcessHostImpl::OnAddSubscription(unsigned int target) { |
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2353 | 2362 |
2354 // Only register valid, non-empty sites. Empty or invalid sites will not | 2363 // Only register valid, non-empty sites. Empty or invalid sites will not |
2355 // use process-per-site mode. We cannot check whether the process has | 2364 // use process-per-site mode. We cannot check whether the process has |
2356 // appropriate bindings here, because the bindings have not yet been granted. | 2365 // appropriate bindings here, because the bindings have not yet been granted. |
2357 std::string site = | 2366 std::string site = |
2358 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); | 2367 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); |
2359 if (!site.empty()) | 2368 if (!site.empty()) |
2360 map->RegisterProcess(site, process); | 2369 map->RegisterProcess(site, process); |
2361 } | 2370 } |
2362 | 2371 |
2372 void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() { | |
2373 DCHECK(!metrics_allocator_); | |
2374 | |
2375 // Create a persistent memory segment for renderer histograms only if | |
2376 // they're active in the browser. | |
2377 if (!base::GlobalHistogramAllocator::Get()) | |
2378 return; | |
2379 | |
2380 // TODO(bcwhite): Update this with the correct memory size. | |
2381 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); | |
2382 shm->CreateAndMapAnonymous(2 << 20); // 2 MiB | |
2383 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( | |
2384 std::move(shm), child_process_launcher_->GetProcess().Pid(), | |
Will Harris
2016/04/07 00:29:41
use RenderProcessHostImpl::GetHandle here
also, d
bcwhite
2016/04/07 01:15:55
It looks like GetId() is a better choice; I just n
| |
2385 "RendererMetrics", /*readonly=*/false)); | |
2386 | |
2387 base::SharedMemoryHandle shm_handle; | |
2388 metrics_allocator_->shared_memory()->ShareToProcess( | |
2389 child_process_launcher_->GetProcess().Handle(), &shm_handle); | |
2390 Send(new ChildProcessMsg_SetHistogramMemory( | |
2391 shm_handle, metrics_allocator_->shared_memory()->mapped_size())); | |
2392 } | |
2393 | |
2363 void RenderProcessHostImpl::ProcessDied(bool already_dead, | 2394 void RenderProcessHostImpl::ProcessDied(bool already_dead, |
2364 RendererClosedDetails* known_details) { | 2395 RendererClosedDetails* known_details) { |
2365 // Our child process has died. If we didn't expect it, it's a crash. | 2396 // Our child process has died. If we didn't expect it, it's a crash. |
2366 // In any case, we need to let everyone know it's gone. | 2397 // In any case, we need to let everyone know it's gone. |
2367 // The OnChannelError notification can fire multiple times due to nested sync | 2398 // The OnChannelError notification can fire multiple times due to nested sync |
2368 // calls to a renderer. If we don't have a valid channel here it means we | 2399 // calls to a renderer. If we don't have a valid channel here it means we |
2369 // already handled the error. | 2400 // already handled the error. |
2370 | 2401 |
2371 // It should not be possible for us to be called re-entrantly. | 2402 // It should not be possible for us to be called re-entrantly. |
2372 DCHECK(!within_process_died_observer_); | 2403 DCHECK(!within_process_died_observer_); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2558 // Experiment with not setting the initial priority of a renderer, as this | 2589 // Experiment with not setting the initial priority of a renderer, as this |
2559 // might be a visible tab but since no widgets are currently present, it | 2590 // might be a visible tab but since no widgets are currently present, it |
2560 // will get backgrounded. See https://crbug.com/560446. | 2591 // will get backgrounded. See https://crbug.com/560446. |
2561 if (base::FeatureList::IsEnabled( | 2592 if (base::FeatureList::IsEnabled( |
2562 features::kUpdateRendererPriorityOnStartup)) { | 2593 features::kUpdateRendererPriorityOnStartup)) { |
2563 UpdateProcessPriority(); | 2594 UpdateProcessPriority(); |
2564 } | 2595 } |
2565 #else | 2596 #else |
2566 UpdateProcessPriority(); | 2597 UpdateProcessPriority(); |
2567 #endif | 2598 #endif |
2599 | |
2600 // Share histograms between the renderer and this process. | |
2601 CreateSharedRendererHistogramAllocator(); | |
2568 } | 2602 } |
2569 | 2603 |
2570 // NOTE: This needs to be before sending queued messages because | 2604 // NOTE: This needs to be before sending queued messages because |
2571 // ExtensionService uses this notification to initialize the renderer process | 2605 // ExtensionService uses this notification to initialize the renderer process |
2572 // with state that must be there before any JavaScript executes. | 2606 // with state that must be there before any JavaScript executes. |
2573 // | 2607 // |
2574 // The queued messages contain such things as "navigate". If this notification | 2608 // The queued messages contain such things as "navigate". If this notification |
2575 // was after, we can end up executing JavaScript before the initialization | 2609 // was after, we can end up executing JavaScript before the initialization |
2576 // happens. | 2610 // happens. |
2577 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 2611 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2791 | 2825 |
2792 // Skip widgets in other processes. | 2826 // Skip widgets in other processes. |
2793 if (rvh->GetProcess()->GetID() != GetID()) | 2827 if (rvh->GetProcess()->GetID() != GetID()) |
2794 continue; | 2828 continue; |
2795 | 2829 |
2796 rvh->OnWebkitPreferencesChanged(); | 2830 rvh->OnWebkitPreferencesChanged(); |
2797 } | 2831 } |
2798 } | 2832 } |
2799 | 2833 |
2800 } // namespace content | 2834 } // namespace content |
OLD | NEW |