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