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 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 | 1116 |
1113 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1117 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
1114 Send(new ViewMsg_TimezoneChange(zone_id)); | 1118 Send(new ViewMsg_TimezoneChange(zone_id)); |
1115 } | 1119 } |
1116 | 1120 |
1117 ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() { | 1121 ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() { |
1118 DCHECK(mojo_application_host_); | 1122 DCHECK(mojo_application_host_); |
1119 return mojo_application_host_->service_registry(); | 1123 return mojo_application_host_->service_registry(); |
1120 } | 1124 } |
1121 | 1125 |
| 1126 scoped_ptr<base::SharedPersistentMemoryAllocator> |
| 1127 RenderProcessHostImpl::TakeMetricsAllocator() { |
| 1128 return std::move(metrics_allocator_); |
| 1129 } |
| 1130 |
1122 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1131 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
1123 const { | 1132 const { |
1124 return init_time_; | 1133 return init_time_; |
1125 } | 1134 } |
1126 | 1135 |
1127 bool RenderProcessHostImpl::SubscribeUniformEnabled() const { | 1136 bool RenderProcessHostImpl::SubscribeUniformEnabled() const { |
1128 return subscribe_uniform_enabled_; | 1137 return subscribe_uniform_enabled_; |
1129 } | 1138 } |
1130 | 1139 |
1131 void RenderProcessHostImpl::OnAddSubscription(unsigned int target) { | 1140 void RenderProcessHostImpl::OnAddSubscription(unsigned int target) { |
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2352 | 2361 |
2353 // Only register valid, non-empty sites. Empty or invalid sites will not | 2362 // Only register valid, non-empty sites. Empty or invalid sites will not |
2354 // use process-per-site mode. We cannot check whether the process has | 2363 // use process-per-site mode. We cannot check whether the process has |
2355 // appropriate bindings here, because the bindings have not yet been granted. | 2364 // appropriate bindings here, because the bindings have not yet been granted. |
2356 std::string site = | 2365 std::string site = |
2357 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); | 2366 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); |
2358 if (!site.empty()) | 2367 if (!site.empty()) |
2359 map->RegisterProcess(site, process); | 2368 map->RegisterProcess(site, process); |
2360 } | 2369 } |
2361 | 2370 |
| 2371 void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() { |
| 2372 DCHECK(!metrics_allocator_); |
| 2373 |
| 2374 // Create a persistent memory segment for renderer histograms only if |
| 2375 // they're active in the browser. |
| 2376 if (!base::GlobalHistogramAllocator::Get()) |
| 2377 return; |
| 2378 |
| 2379 // Get handle to the renderer process. Stop if there is none. |
| 2380 base::ProcessHandle destination = GetHandle(); |
| 2381 if (destination == base::kNullProcessHandle) |
| 2382 return; |
| 2383 |
| 2384 // TODO(bcwhite): Update this with the correct memory size. |
| 2385 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
| 2386 shm->CreateAndMapAnonymous(2 << 20); // 2 MiB |
| 2387 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( |
| 2388 std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false)); |
| 2389 |
| 2390 base::SharedMemoryHandle shm_handle; |
| 2391 metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle); |
| 2392 Send(new ChildProcessMsg_SetHistogramMemory( |
| 2393 shm_handle, metrics_allocator_->shared_memory()->mapped_size())); |
| 2394 } |
| 2395 |
2362 void RenderProcessHostImpl::ProcessDied(bool already_dead, | 2396 void RenderProcessHostImpl::ProcessDied(bool already_dead, |
2363 RendererClosedDetails* known_details) { | 2397 RendererClosedDetails* known_details) { |
2364 // Our child process has died. If we didn't expect it, it's a crash. | 2398 // Our child process has died. If we didn't expect it, it's a crash. |
2365 // In any case, we need to let everyone know it's gone. | 2399 // In any case, we need to let everyone know it's gone. |
2366 // The OnChannelError notification can fire multiple times due to nested sync | 2400 // The OnChannelError notification can fire multiple times due to nested sync |
2367 // calls to a renderer. If we don't have a valid channel here it means we | 2401 // calls to a renderer. If we don't have a valid channel here it means we |
2368 // already handled the error. | 2402 // already handled the error. |
2369 | 2403 |
2370 // It should not be possible for us to be called re-entrantly. | 2404 // It should not be possible for us to be called re-entrantly. |
2371 DCHECK(!within_process_died_observer_); | 2405 DCHECK(!within_process_died_observer_); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2554 child_process_launcher_->GetProcess().IsProcessBackgrounded(); | 2588 child_process_launcher_->GetProcess().IsProcessBackgrounded(); |
2555 | 2589 |
2556 // Disable updating process priority on startup for now as it incorrectly | 2590 // Disable updating process priority on startup for now as it incorrectly |
2557 // results in backgrounding foreground navigations until their first commit | 2591 // results in backgrounding foreground navigations until their first commit |
2558 // is made. A better long term solution would be to be aware of the tab's | 2592 // is made. A better long term solution would be to be aware of the tab's |
2559 // visibility at this point. https://crbug.com/560446. | 2593 // visibility at this point. https://crbug.com/560446. |
2560 // Except on Android for now because of https://crbug.com/601184 :-(. | 2594 // Except on Android for now because of https://crbug.com/601184 :-(. |
2561 #if defined(OS_ANDROID) | 2595 #if defined(OS_ANDROID) |
2562 UpdateProcessPriority(); | 2596 UpdateProcessPriority(); |
2563 #endif | 2597 #endif |
| 2598 |
| 2599 // Share histograms between the renderer and this process. |
| 2600 CreateSharedRendererHistogramAllocator(); |
2564 } | 2601 } |
2565 | 2602 |
2566 // NOTE: This needs to be before sending queued messages because | 2603 // NOTE: This needs to be before sending queued messages because |
2567 // ExtensionService uses this notification to initialize the renderer process | 2604 // ExtensionService uses this notification to initialize the renderer process |
2568 // with state that must be there before any JavaScript executes. | 2605 // with state that must be there before any JavaScript executes. |
2569 // | 2606 // |
2570 // The queued messages contain such things as "navigate". If this notification | 2607 // The queued messages contain such things as "navigate". If this notification |
2571 // was after, we can end up executing JavaScript before the initialization | 2608 // was after, we can end up executing JavaScript before the initialization |
2572 // happens. | 2609 // happens. |
2573 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 2610 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2785 | 2822 |
2786 // Skip widgets in other processes. | 2823 // Skip widgets in other processes. |
2787 if (rvh->GetProcess()->GetID() != GetID()) | 2824 if (rvh->GetProcess()->GetID() != GetID()) |
2788 continue; | 2825 continue; |
2789 | 2826 |
2790 rvh->OnWebkitPreferencesChanged(); | 2827 rvh->OnWebkitPreferencesChanged(); |
2791 } | 2828 } |
2792 } | 2829 } |
2793 | 2830 |
2794 } // namespace content | 2831 } // namespace content |
OLD | NEW |