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 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1127 | 1131 |
1128 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1132 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
1129 Send(new ViewMsg_TimezoneChange(zone_id)); | 1133 Send(new ViewMsg_TimezoneChange(zone_id)); |
1130 } | 1134 } |
1131 | 1135 |
1132 ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() { | 1136 ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() { |
1133 DCHECK(mojo_application_host_); | 1137 DCHECK(mojo_application_host_); |
1134 return mojo_application_host_->service_registry(); | 1138 return mojo_application_host_->service_registry(); |
1135 } | 1139 } |
1136 | 1140 |
1141 scoped_ptr<base::SharedPersistentMemoryAllocator> | |
1142 RenderProcessHostImpl::ExtractMetricsAllocator() { | |
1143 return std::move(metrics_allocator_); | |
1144 } | |
1145 | |
1137 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1146 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
1138 const { | 1147 const { |
1139 return init_time_; | 1148 return init_time_; |
1140 } | 1149 } |
1141 | 1150 |
1142 bool RenderProcessHostImpl::SubscribeUniformEnabled() const { | 1151 bool RenderProcessHostImpl::SubscribeUniformEnabled() const { |
1143 return subscribe_uniform_enabled_; | 1152 return subscribe_uniform_enabled_; |
1144 } | 1153 } |
1145 | 1154 |
1146 void RenderProcessHostImpl::OnAddSubscription(unsigned int target) { | 1155 void RenderProcessHostImpl::OnAddSubscription(unsigned int target) { |
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2582 // Experiment with not setting the initial priority of a renderer, as this | 2591 // Experiment with not setting the initial priority of a renderer, as this |
2583 // might be a visible tab but since no widgets are currently present, it | 2592 // might be a visible tab but since no widgets are currently present, it |
2584 // will get backgrounded. See https://crbug.com/560446. | 2593 // will get backgrounded. See https://crbug.com/560446. |
2585 if (base::FeatureList::IsEnabled( | 2594 if (base::FeatureList::IsEnabled( |
2586 features::kUpdateRendererPriorityOnStartup)) { | 2595 features::kUpdateRendererPriorityOnStartup)) { |
2587 UpdateProcessPriority(); | 2596 UpdateProcessPriority(); |
2588 } | 2597 } |
2589 #else | 2598 #else |
2590 UpdateProcessPriority(); | 2599 UpdateProcessPriority(); |
2591 #endif | 2600 #endif |
2601 | |
2602 // Create a persistent memory segment for renderer histograms only if | |
Alexei Svitkine (slow)
2016/03/29 17:51:24
Please make a separate function for this block to
bcwhite
2016/03/30 21:25:55
Done.
| |
2603 // they're active in the browser. | |
2604 if (base::PersistentHistogramAllocator::GetGlobalAllocator()) { | |
2605 DCHECK(!metrics_allocator_); | |
2606 // TODO(bcwhite): Update this with the correct memory size. | |
2607 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); | |
2608 shm->CreateAndMapAnonymous(2 << 20); // 2 MiB | |
2609 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( | |
2610 std::move(shm), child_process_launcher_->GetProcess().Pid(), | |
2611 "RendererMetrics", /*readonly=*/false)); | |
2612 | |
2613 if (metrics_allocator_) { | |
2614 base::SharedMemoryHandle shm_handle; | |
2615 metrics_allocator_->shared_memory()->ShareToProcess( | |
2616 child_process_launcher_->GetProcess().Handle(), &shm_handle); | |
2617 Send(new ChildProcessMsg_SetHistogramMemory( | |
2618 shm_handle, metrics_allocator_->shared_memory()->mapped_size())); | |
2619 } | |
2620 } | |
2592 } | 2621 } |
2593 | 2622 |
2594 // NOTE: This needs to be before sending queued messages because | 2623 // NOTE: This needs to be before sending queued messages because |
2595 // ExtensionService uses this notification to initialize the renderer process | 2624 // ExtensionService uses this notification to initialize the renderer process |
2596 // with state that must be there before any JavaScript executes. | 2625 // with state that must be there before any JavaScript executes. |
2597 // | 2626 // |
2598 // The queued messages contain such things as "navigate". If this notification | 2627 // The queued messages contain such things as "navigate". If this notification |
2599 // was after, we can end up executing JavaScript before the initialization | 2628 // was after, we can end up executing JavaScript before the initialization |
2600 // happens. | 2629 // happens. |
2601 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 2630 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2815 | 2844 |
2816 // Skip widgets in other processes. | 2845 // Skip widgets in other processes. |
2817 if (rvh->GetProcess()->GetID() != GetID()) | 2846 if (rvh->GetProcess()->GetID() != GetID()) |
2818 continue; | 2847 continue; |
2819 | 2848 |
2820 rvh->OnWebkitPreferencesChanged(); | 2849 rvh->OnWebkitPreferencesChanged(); |
2821 } | 2850 } |
2822 } | 2851 } |
2823 | 2852 |
2824 } // namespace content | 2853 } // namespace content |
OLD | NEW |