Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 1671933002: Create and pass shared-histogram-allocator from browser to renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hsm-merge
Patch Set: addressed review comments by Alexei; fixed test on some builds Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2377 2386
2378 // Only register valid, non-empty sites. Empty or invalid sites will not 2387 // Only register valid, non-empty sites. Empty or invalid sites will not
2379 // use process-per-site mode. We cannot check whether the process has 2388 // use process-per-site mode. We cannot check whether the process has
2380 // appropriate bindings here, because the bindings have not yet been granted. 2389 // appropriate bindings here, because the bindings have not yet been granted.
2381 std::string site = 2390 std::string site =
2382 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); 2391 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec();
2383 if (!site.empty()) 2392 if (!site.empty())
2384 map->RegisterProcess(site, process); 2393 map->RegisterProcess(site, process);
2385 } 2394 }
2386 2395
2396 void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() {
2397 DCHECK(!metrics_allocator_);
2398
2399 // Create a persistent memory segment for renderer histograms only if
2400 // they're active in the browser.
2401 if (!base::PersistentHistogramAllocator::GetGlobalAllocator())
2402 return;
2403
2404 // TODO(bcwhite): Update this with the correct memory size.
2405 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
2406 shm->CreateAndMapAnonymous(2 << 20); // 2 MiB
2407 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator(
2408 std::move(shm), child_process_launcher_->GetProcess().Pid(),
2409 "RendererMetrics", /*readonly=*/false));
2410
2411 base::SharedMemoryHandle shm_handle;
2412 metrics_allocator_->shared_memory()->ShareToProcess(
2413 child_process_launcher_->GetProcess().Handle(), &shm_handle);
2414 Send(new ChildProcessMsg_SetHistogramMemory(
2415 shm_handle, metrics_allocator_->shared_memory()->mapped_size()));
2416 }
2417
2387 void RenderProcessHostImpl::ProcessDied(bool already_dead, 2418 void RenderProcessHostImpl::ProcessDied(bool already_dead,
2388 RendererClosedDetails* known_details) { 2419 RendererClosedDetails* known_details) {
2389 // Our child process has died. If we didn't expect it, it's a crash. 2420 // Our child process has died. If we didn't expect it, it's a crash.
2390 // In any case, we need to let everyone know it's gone. 2421 // In any case, we need to let everyone know it's gone.
2391 // The OnChannelError notification can fire multiple times due to nested sync 2422 // The OnChannelError notification can fire multiple times due to nested sync
2392 // calls to a renderer. If we don't have a valid channel here it means we 2423 // calls to a renderer. If we don't have a valid channel here it means we
2393 // already handled the error. 2424 // already handled the error.
2394 2425
2395 // It should not be possible for us to be called re-entrantly. 2426 // It should not be possible for us to be called re-entrantly.
2396 DCHECK(!within_process_died_observer_); 2427 DCHECK(!within_process_died_observer_);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2582 // Experiment with not setting the initial priority of a renderer, as this 2613 // 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 2614 // might be a visible tab but since no widgets are currently present, it
2584 // will get backgrounded. See https://crbug.com/560446. 2615 // will get backgrounded. See https://crbug.com/560446.
2585 if (base::FeatureList::IsEnabled( 2616 if (base::FeatureList::IsEnabled(
2586 features::kUpdateRendererPriorityOnStartup)) { 2617 features::kUpdateRendererPriorityOnStartup)) {
2587 UpdateProcessPriority(); 2618 UpdateProcessPriority();
2588 } 2619 }
2589 #else 2620 #else
2590 UpdateProcessPriority(); 2621 UpdateProcessPriority();
2591 #endif 2622 #endif
2623
2624 // Share histograms between the renderer and this process.
2625 CreateSharedRendererHistogramAllocator();
2592 } 2626 }
2593 2627
2594 // NOTE: This needs to be before sending queued messages because 2628 // NOTE: This needs to be before sending queued messages because
2595 // ExtensionService uses this notification to initialize the renderer process 2629 // ExtensionService uses this notification to initialize the renderer process
2596 // with state that must be there before any JavaScript executes. 2630 // with state that must be there before any JavaScript executes.
2597 // 2631 //
2598 // The queued messages contain such things as "navigate". If this notification 2632 // The queued messages contain such things as "navigate". If this notification
2599 // was after, we can end up executing JavaScript before the initialization 2633 // was after, we can end up executing JavaScript before the initialization
2600 // happens. 2634 // happens.
2601 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, 2635 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 2849
2816 // Skip widgets in other processes. 2850 // Skip widgets in other processes.
2817 if (rvh->GetProcess()->GetID() != GetID()) 2851 if (rvh->GetProcess()->GetID() != GetID())
2818 continue; 2852 continue;
2819 2853
2820 rvh->OnWebkitPreferencesChanged(); 2854 rvh->OnWebkitPreferencesChanged();
2821 } 2855 }
2822 } 2856 }
2823 2857
2824 } // namespace content 2858 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698