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/metrics/field_trial.h" | 27 #include "base/metrics/field_trial.h" |
28 #include "base/metrics/histogram.h" | 28 #include "base/metrics/histogram.h" |
| 29 #include "base/metrics/histogram_persistence.h" |
| 30 #include "base/metrics/persistent_memory_allocator.h" |
29 #include "base/process/process_handle.h" | 31 #include "base/process/process_handle.h" |
30 #include "base/rand_util.h" | 32 #include "base/rand_util.h" |
31 #include "base/single_thread_task_runner.h" | 33 #include "base/single_thread_task_runner.h" |
32 #include "base/stl_util.h" | 34 #include "base/stl_util.h" |
33 #include "base/strings/string_number_conversions.h" | 35 #include "base/strings/string_number_conversions.h" |
34 #include "base/supports_user_data.h" | 36 #include "base/supports_user_data.h" |
35 #include "base/sys_info.h" | 37 #include "base/sys_info.h" |
36 #include "base/threading/thread.h" | 38 #include "base/threading/thread.h" |
37 #include "base/threading/thread_restrictions.h" | 39 #include "base/threading/thread_restrictions.h" |
38 #include "base/trace_event/trace_event.h" | 40 #include "base/trace_event/trace_event.h" |
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 | 1127 |
1126 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1128 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
1127 Send(new ViewMsg_TimezoneChange(zone_id)); | 1129 Send(new ViewMsg_TimezoneChange(zone_id)); |
1128 } | 1130 } |
1129 | 1131 |
1130 ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() { | 1132 ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() { |
1131 DCHECK(mojo_application_host_); | 1133 DCHECK(mojo_application_host_); |
1132 return mojo_application_host_->service_registry(); | 1134 return mojo_application_host_->service_registry(); |
1133 } | 1135 } |
1134 | 1136 |
| 1137 scoped_ptr<base::SharedPersistentMemoryAllocator> |
| 1138 RenderProcessHostImpl::GetMetricsAllocator() { |
| 1139 return std::move(metrics_allocator_); |
| 1140 } |
| 1141 |
1135 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1142 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
1136 const { | 1143 const { |
1137 return init_time_; | 1144 return init_time_; |
1138 } | 1145 } |
1139 | 1146 |
1140 bool RenderProcessHostImpl::SubscribeUniformEnabled() const { | 1147 bool RenderProcessHostImpl::SubscribeUniformEnabled() const { |
1141 return subscribe_uniform_enabled_; | 1148 return subscribe_uniform_enabled_; |
1142 } | 1149 } |
1143 | 1150 |
1144 void RenderProcessHostImpl::OnAddSubscription(unsigned int target) { | 1151 void RenderProcessHostImpl::OnAddSubscription(unsigned int target) { |
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2558 // Experiment with not setting the initial priority of a renderer, as this | 2565 // 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 | 2566 // might be a visible tab but since no widgets are currently present, it |
2560 // will get backgrounded. See https://crbug.com/560446. | 2567 // will get backgrounded. See https://crbug.com/560446. |
2561 if (base::FeatureList::IsEnabled( | 2568 if (base::FeatureList::IsEnabled( |
2562 features::kUpdateRendererPriorityOnStartup)) { | 2569 features::kUpdateRendererPriorityOnStartup)) { |
2563 UpdateProcessPriority(); | 2570 UpdateProcessPriority(); |
2564 } | 2571 } |
2565 #else | 2572 #else |
2566 UpdateProcessPriority(); | 2573 UpdateProcessPriority(); |
2567 #endif | 2574 #endif |
| 2575 |
| 2576 // Create a persistent memory segment for renderer histograms only if |
| 2577 // they're active in the browser. |
| 2578 if (base::GetPersistentHistogramMemoryAllocator()) { |
| 2579 DCHECK(!metrics_allocator_); |
| 2580 // TODO(bcwhite): Update this with the correct memory size. |
| 2581 metrics_allocator_.reset( |
| 2582 base::CreateSharedPersistentHistogramMemoryAllocator( |
| 2583 2 << 20, // 2 MiB |
| 2584 "RendererMetrics", |
| 2585 child_process_launcher_->GetProcess().Pid())); |
| 2586 |
| 2587 if (metrics_allocator_) { |
| 2588 base::SharedMemoryHandle shm_handle; |
| 2589 metrics_allocator_->shared_memory()->ShareToProcess( |
| 2590 child_process_launcher_->GetProcess().Handle(), &shm_handle); |
| 2591 Send(new ChildProcessMsg_SetHistogramMemory( |
| 2592 shm_handle, metrics_allocator_->shared_memory()->mapped_size())); |
| 2593 } |
| 2594 } |
2568 } | 2595 } |
2569 | 2596 |
2570 // NOTE: This needs to be before sending queued messages because | 2597 // NOTE: This needs to be before sending queued messages because |
2571 // ExtensionService uses this notification to initialize the renderer process | 2598 // ExtensionService uses this notification to initialize the renderer process |
2572 // with state that must be there before any JavaScript executes. | 2599 // with state that must be there before any JavaScript executes. |
2573 // | 2600 // |
2574 // The queued messages contain such things as "navigate". If this notification | 2601 // The queued messages contain such things as "navigate". If this notification |
2575 // was after, we can end up executing JavaScript before the initialization | 2602 // was after, we can end up executing JavaScript before the initialization |
2576 // happens. | 2603 // happens. |
2577 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 2604 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2806 | 2833 |
2807 // Skip widgets in other processes. | 2834 // Skip widgets in other processes. |
2808 if (rvh->GetProcess()->GetID() != GetID()) | 2835 if (rvh->GetProcess()->GetID() != GetID()) |
2809 continue; | 2836 continue; |
2810 | 2837 |
2811 rvh->OnWebkitPreferencesChanged(); | 2838 rvh->OnWebkitPreferencesChanged(); |
2812 } | 2839 } |
2813 } | 2840 } |
2814 | 2841 |
2815 } // namespace content | 2842 } // namespace content |
OLD | NEW |