| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_IMPL_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_IMPL_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <queue> | 13 #include <queue> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 19 #include "base/process/process.h" | 19 #include "base/process/process.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "content/browser/child_process_launcher.h" | 23 #include "content/browser/child_process_launcher.h" |
| 24 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 24 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| 25 #include "content/browser/power_monitor_message_broadcaster.h" | 25 #include "content/browser/power_monitor_message_broadcaster.h" |
| 26 #include "content/browser/webrtc/webrtc_eventlog_host.h" | 26 #include "content/browser/webrtc/webrtc_eventlog_host.h" |
| 27 #include "content/common/associated_interfaces.mojom.h" |
| 27 #include "content/common/content_export.h" | 28 #include "content/common/content_export.h" |
| 28 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
| 29 #include "content/public/common/mojo_shell_connection.h" | 30 #include "content/public/common/mojo_shell_connection.h" |
| 30 #include "ipc/ipc_channel_proxy.h" | 31 #include "ipc/ipc_channel_proxy.h" |
| 31 #include "ipc/ipc_platform_file.h" | 32 #include "ipc/ipc_platform_file.h" |
| 33 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 34 #include "mojo/public/cpp/bindings/associated_binding_set.h" |
| 32 #include "mojo/public/cpp/bindings/interface_ptr.h" | 35 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 33 #include "services/shell/public/cpp/interface_registry.h" | 36 #include "services/shell/public/cpp/interface_registry.h" |
| 34 #include "services/shell/public/interfaces/service.mojom.h" | 37 #include "services/shell/public/interfaces/service.mojom.h" |
| 35 #include "ui/gfx/gpu_memory_buffer.h" | 38 #include "ui/gfx/gpu_memory_buffer.h" |
| 36 #include "ui/gl/gpu_switching_observer.h" | 39 #include "ui/gl/gpu_switching_observer.h" |
| 37 | 40 |
| 38 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
| 39 #include "content/public/browser/android/interface_registry_android.h" | 42 #include "content/public/browser/android/interface_registry_android.h" |
| 40 #endif | 43 #endif |
| 41 | 44 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // are correlated with IDs. This way, the Views and the corresponding ViewHosts | 102 // are correlated with IDs. This way, the Views and the corresponding ViewHosts |
| 100 // communicate through the two process objects. | 103 // communicate through the two process objects. |
| 101 // | 104 // |
| 102 // A RenderProcessHost is also associated with one and only one | 105 // A RenderProcessHost is also associated with one and only one |
| 103 // StoragePartition. This allows us to implement strong storage isolation | 106 // StoragePartition. This allows us to implement strong storage isolation |
| 104 // because all the IPCs from the RenderViews (renderer) will only ever be able | 107 // because all the IPCs from the RenderViews (renderer) will only ever be able |
| 105 // to access the partition they are assigned to. | 108 // to access the partition they are assigned to. |
| 106 class CONTENT_EXPORT RenderProcessHostImpl | 109 class CONTENT_EXPORT RenderProcessHostImpl |
| 107 : public RenderProcessHost, | 110 : public RenderProcessHost, |
| 108 public ChildProcessLauncher::Client, | 111 public ChildProcessLauncher::Client, |
| 109 public ui::GpuSwitchingObserver { | 112 public ui::GpuSwitchingObserver, |
| 113 public NON_EXPORTED_BASE(mojom::RouteProvider), |
| 114 public NON_EXPORTED_BASE(mojom::AssociatedInterfaceProvider) { |
| 110 public: | 115 public: |
| 111 RenderProcessHostImpl(BrowserContext* browser_context, | 116 RenderProcessHostImpl(BrowserContext* browser_context, |
| 112 StoragePartitionImpl* storage_partition_impl, | 117 StoragePartitionImpl* storage_partition_impl, |
| 113 bool is_for_guests_only); | 118 bool is_for_guests_only); |
| 114 ~RenderProcessHostImpl() override; | 119 ~RenderProcessHostImpl() override; |
| 115 | 120 |
| 116 // RenderProcessHost implementation (public portion). | 121 // RenderProcessHost implementation (public portion). |
| 117 void EnableSendQueue() override; | 122 void EnableSendQueue() override; |
| 118 bool Init() override; | 123 bool Init() override; |
| 119 int GetNextRoutingID() override; | 124 int GetNextRoutingID() override; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 scoped_refptr<media::MediaKeys> GetCdm(int render_frame_id, | 177 scoped_refptr<media::MediaKeys> GetCdm(int render_frame_id, |
| 173 int cdm_id) const override; | 178 int cdm_id) const override; |
| 174 #endif | 179 #endif |
| 175 bool IsProcessBackgrounded() const override; | 180 bool IsProcessBackgrounded() const override; |
| 176 void IncrementServiceWorkerRefCount() override; | 181 void IncrementServiceWorkerRefCount() override; |
| 177 void DecrementServiceWorkerRefCount() override; | 182 void DecrementServiceWorkerRefCount() override; |
| 178 void IncrementSharedWorkerRefCount() override; | 183 void IncrementSharedWorkerRefCount() override; |
| 179 void DecrementSharedWorkerRefCount() override; | 184 void DecrementSharedWorkerRefCount() override; |
| 180 void PurgeAndSuspend() override; | 185 void PurgeAndSuspend() override; |
| 181 | 186 |
| 187 mojom::RouteProvider* GetRemoteRouteProvider(); |
| 188 |
| 182 // IPC::Sender via RenderProcessHost. | 189 // IPC::Sender via RenderProcessHost. |
| 183 bool Send(IPC::Message* msg) override; | 190 bool Send(IPC::Message* msg) override; |
| 184 | 191 |
| 185 // IPC::Listener via RenderProcessHost. | 192 // IPC::Listener via RenderProcessHost. |
| 186 bool OnMessageReceived(const IPC::Message& msg) override; | 193 bool OnMessageReceived(const IPC::Message& msg) override; |
| 187 void OnChannelConnected(int32_t peer_pid) override; | 194 void OnChannelConnected(int32_t peer_pid) override; |
| 188 void OnChannelError() override; | 195 void OnChannelError() override; |
| 189 void OnBadMessageReceived(const IPC::Message& message) override; | 196 void OnBadMessageReceived(const IPC::Message& message) override; |
| 190 | 197 |
| 191 // ChildProcessLauncher::Client implementation. | 198 // ChildProcessLauncher::Client implementation. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 321 |
| 315 std::unique_ptr<IPC::ChannelProxy> CreateChannelProxy( | 322 std::unique_ptr<IPC::ChannelProxy> CreateChannelProxy( |
| 316 const std::string& channel_id); | 323 const std::string& channel_id); |
| 317 | 324 |
| 318 // Creates and adds the IO thread message filters. | 325 // Creates and adds the IO thread message filters. |
| 319 void CreateMessageFilters(); | 326 void CreateMessageFilters(); |
| 320 | 327 |
| 321 // Registers Mojo interfaces to be exposed to the renderer. | 328 // Registers Mojo interfaces to be exposed to the renderer. |
| 322 void RegisterMojoInterfaces(); | 329 void RegisterMojoInterfaces(); |
| 323 | 330 |
| 331 // mojom::RouteProvider: |
| 332 void GetRoute( |
| 333 int32_t routing_id, |
| 334 mojom::AssociatedInterfaceProviderAssociatedRequest request) override; |
| 335 |
| 336 // mojom::AssociatedInterfaceProvider: |
| 337 void GetAssociatedInterface( |
| 338 const std::string& name, |
| 339 mojom::AssociatedInterfaceAssociatedRequest request) override; |
| 340 |
| 324 void CreateStoragePartitionService( | 341 void CreateStoragePartitionService( |
| 325 mojo::InterfaceRequest<mojom::StoragePartitionService> request); | 342 mojo::InterfaceRequest<mojom::StoragePartitionService> request); |
| 326 | 343 |
| 327 // Control message handlers. | 344 // Control message handlers. |
| 328 void OnShutdownRequest(); | 345 void OnShutdownRequest(); |
| 329 void SuddenTerminationChanged(bool enabled); | 346 void SuddenTerminationChanged(bool enabled); |
| 330 void OnUserMetricsRecordAction(const std::string& action); | 347 void OnUserMetricsRecordAction(const std::string& action); |
| 331 void OnCloseACK(int old_route_id); | 348 void OnCloseACK(int old_route_id); |
| 332 | 349 |
| 333 // Generates a command line to be used to spawn a renderer and appends the | 350 // Generates a command line to be used to spawn a renderer and appends the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 348 | 365 |
| 349 // Creates a PersistentMemoryAllocator and shares it with the renderer | 366 // Creates a PersistentMemoryAllocator and shares it with the renderer |
| 350 // process for it to store histograms from that process. The allocator is | 367 // process for it to store histograms from that process. The allocator is |
| 351 // available for extraction by a SubprocesMetricsProvider in order to | 368 // available for extraction by a SubprocesMetricsProvider in order to |
| 352 // report those histograms to UMA. | 369 // report those histograms to UMA. |
| 353 void CreateSharedRendererHistogramAllocator(); | 370 void CreateSharedRendererHistogramAllocator(); |
| 354 | 371 |
| 355 // Handle termination of our process. | 372 // Handle termination of our process. |
| 356 void ProcessDied(bool already_dead, RendererClosedDetails* known_details); | 373 void ProcessDied(bool already_dead, RendererClosedDetails* known_details); |
| 357 | 374 |
| 375 void OnRouteProviderRequest(mojom::RouteProviderAssociatedRequest request); |
| 376 |
| 358 // GpuSwitchingObserver implementation. | 377 // GpuSwitchingObserver implementation. |
| 359 void OnGpuSwitched() override; | 378 void OnGpuSwitched() override; |
| 360 | 379 |
| 361 #if defined(ENABLE_WEBRTC) | 380 #if defined(ENABLE_WEBRTC) |
| 362 void OnRegisterAecDumpConsumer(int id); | 381 void OnRegisterAecDumpConsumer(int id); |
| 363 void OnUnregisterAecDumpConsumer(int id); | 382 void OnUnregisterAecDumpConsumer(int id); |
| 364 void RegisterAecDumpConsumerOnUIThread(int id); | 383 void RegisterAecDumpConsumerOnUIThread(int id); |
| 365 void UnregisterAecDumpConsumerOnUIThread(int id); | 384 void UnregisterAecDumpConsumerOnUIThread(int id); |
| 366 void EnableAecDumpForId(const base::FilePath& file, int id); | 385 void EnableAecDumpForId(const base::FilePath& file, int id); |
| 367 // Sends |file_for_transit| to the render process. | 386 // Sends |file_for_transit| to the render process. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 std::unique_ptr<InterfaceRegistryAndroid> interface_registry_android_; | 436 std::unique_ptr<InterfaceRegistryAndroid> interface_registry_android_; |
| 418 #endif | 437 #endif |
| 419 | 438 |
| 420 size_t service_worker_ref_count_; | 439 size_t service_worker_ref_count_; |
| 421 size_t shared_worker_ref_count_; | 440 size_t shared_worker_ref_count_; |
| 422 | 441 |
| 423 // The registered IPC listener objects. When this list is empty, we should | 442 // The registered IPC listener objects. When this list is empty, we should |
| 424 // delete ourselves. | 443 // delete ourselves. |
| 425 IDMap<IPC::Listener> listeners_; | 444 IDMap<IPC::Listener> listeners_; |
| 426 | 445 |
| 446 mojo::AssociatedBinding<mojom::RouteProvider> route_provider_binding_; |
| 447 mojo::AssociatedBindingSet<mojom::AssociatedInterfaceProvider> |
| 448 associated_interface_provider_bindings_; |
| 449 |
| 427 // The count of currently visible widgets. Since the host can be a container | 450 // The count of currently visible widgets. Since the host can be a container |
| 428 // for multiple widgets, it uses this count to determine when it should be | 451 // for multiple widgets, it uses this count to determine when it should be |
| 429 // backgrounded. | 452 // backgrounded. |
| 430 int32_t visible_widgets_; | 453 int32_t visible_widgets_; |
| 431 | 454 |
| 432 // Whether this process currently has backgrounded priority. Tracked so that | 455 // Whether this process currently has backgrounded priority. Tracked so that |
| 433 // UpdateProcessPriority() can avoid redundantly setting the priority. | 456 // UpdateProcessPriority() can avoid redundantly setting the priority. |
| 434 bool is_process_backgrounded_; | 457 bool is_process_backgrounded_; |
| 435 | 458 |
| 436 // Used to allow a RenderWidgetHost to intercept various messages on the | 459 // Used to allow a RenderWidgetHost to intercept various messages on the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 453 // also reset that in the case of process termination. | 476 // also reset that in the case of process termination. |
| 454 bool is_initialized_; | 477 bool is_initialized_; |
| 455 | 478 |
| 456 // PlzNavigate | 479 // PlzNavigate |
| 457 // Stores the time at which the first call to Init happened. | 480 // Stores the time at which the first call to Init happened. |
| 458 base::TimeTicks init_time_; | 481 base::TimeTicks init_time_; |
| 459 | 482 |
| 460 // Used to launch and terminate the process without blocking the UI thread. | 483 // Used to launch and terminate the process without blocking the UI thread. |
| 461 std::unique_ptr<ChildProcessLauncher> child_process_launcher_; | 484 std::unique_ptr<ChildProcessLauncher> child_process_launcher_; |
| 462 | 485 |
| 463 // Messages we queue while waiting for the process handle. We queue them here | 486 // Messages we queue before the ChannelProxy is created. |
| 464 // instead of in the channel so that we ensure they're sent after init related | 487 using MessageQueue = std::queue<std::unique_ptr<IPC::Message>>; |
| 465 // messages that are sent once the process handle is available. This is | 488 MessageQueue queued_messages_; |
| 466 // because the queued messages may have dependencies on the init messages. | |
| 467 std::queue<IPC::Message*> queued_messages_; | |
| 468 | 489 |
| 469 // The globally-unique identifier for this RPH. | 490 // The globally-unique identifier for this RPH. |
| 470 const int id_; | 491 const int id_; |
| 471 | 492 |
| 472 // A secondary ID used by the Mojo shell to distinguish different incarnations | 493 // A secondary ID used by the Mojo shell to distinguish different incarnations |
| 473 // of the same RPH from each other. Unlike |id_| this is not globally unique, | 494 // of the same RPH from each other. Unlike |id_| this is not globally unique, |
| 474 // but it is guaranteed to change every time Init() is called. | 495 // but it is guaranteed to change every time Init() is called. |
| 475 int instance_id_ = 1; | 496 int instance_id_ = 1; |
| 476 | 497 |
| 477 BrowserContext* browser_context_; | 498 BrowserContext* browser_context_; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // UI thread is the source of sync IPCs and all shutdown signals. | 583 // UI thread is the source of sync IPCs and all shutdown signals. |
| 563 // Therefore a proper shutdown event to unblock the UI thread is not | 584 // Therefore a proper shutdown event to unblock the UI thread is not |
| 564 // possible without massive refactoring shutdown code. | 585 // possible without massive refactoring shutdown code. |
| 565 // Luckily Android never performs a clean shutdown. So explicitly | 586 // Luckily Android never performs a clean shutdown. So explicitly |
| 566 // ignore this problem. | 587 // ignore this problem. |
| 567 base::WaitableEvent never_signaled_; | 588 base::WaitableEvent never_signaled_; |
| 568 #endif | 589 #endif |
| 569 | 590 |
| 570 scoped_refptr<ResourceMessageFilter> resource_message_filter_; | 591 scoped_refptr<ResourceMessageFilter> resource_message_filter_; |
| 571 | 592 |
| 593 mojom::RouteProviderAssociatedPtr remote_route_provider_; |
| 594 |
| 572 // A WeakPtrFactory which is reset every time Cleanup() runs. Used to vend | 595 // A WeakPtrFactory which is reset every time Cleanup() runs. Used to vend |
| 573 // WeakPtrs which are invalidated any time the RPHI is recycled. | 596 // WeakPtrs which are invalidated any time the RPHI is recycled. |
| 574 std::unique_ptr<base::WeakPtrFactory<RenderProcessHostImpl>> | 597 std::unique_ptr<base::WeakPtrFactory<RenderProcessHostImpl>> |
| 575 instance_weak_factory_; | 598 instance_weak_factory_; |
| 576 | 599 |
| 577 base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_; | 600 base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_; |
| 578 | 601 |
| 579 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); | 602 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); |
| 580 }; | 603 }; |
| 581 | 604 |
| 582 } // namespace content | 605 } // namespace content |
| 583 | 606 |
| 584 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_IMPL_H_ | 607 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_IMPL_H_ |
| OLD | NEW |