| 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/content_export.h" | 27 #include "content/common/content_export.h" |
| 28 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 29 #include "content/public/common/associated_interfaces.mojom.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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 327 |
| 321 std::unique_ptr<IPC::ChannelProxy> CreateChannelProxy( | 328 std::unique_ptr<IPC::ChannelProxy> CreateChannelProxy( |
| 322 const std::string& channel_id); | 329 const std::string& channel_id); |
| 323 | 330 |
| 324 // Creates and adds the IO thread message filters. | 331 // Creates and adds the IO thread message filters. |
| 325 void CreateMessageFilters(); | 332 void CreateMessageFilters(); |
| 326 | 333 |
| 327 // Registers Mojo interfaces to be exposed to the renderer. | 334 // Registers Mojo interfaces to be exposed to the renderer. |
| 328 void RegisterMojoInterfaces(); | 335 void RegisterMojoInterfaces(); |
| 329 | 336 |
| 337 // mojom::RouteProvider: |
| 338 void GetRoute( |
| 339 int32_t routing_id, |
| 340 mojom::AssociatedInterfaceProviderAssociatedRequest request) override; |
| 341 |
| 342 // mojom::AssociatedInterfaceProvider: |
| 343 void GetAssociatedInterface( |
| 344 const std::string& name, |
| 345 mojom::AssociatedInterfaceAssociatedRequest request) override; |
| 346 |
| 330 void CreateStoragePartitionService( | 347 void CreateStoragePartitionService( |
| 331 mojo::InterfaceRequest<mojom::StoragePartitionService> request); | 348 mojo::InterfaceRequest<mojom::StoragePartitionService> request); |
| 332 | 349 |
| 333 // Control message handlers. | 350 // Control message handlers. |
| 334 void OnShutdownRequest(); | 351 void OnShutdownRequest(); |
| 335 void SuddenTerminationChanged(bool enabled); | 352 void SuddenTerminationChanged(bool enabled); |
| 336 void OnUserMetricsRecordAction(const std::string& action); | 353 void OnUserMetricsRecordAction(const std::string& action); |
| 337 void OnCloseACK(int old_route_id); | 354 void OnCloseACK(int old_route_id); |
| 338 | 355 |
| 339 // Generates a command line to be used to spawn a renderer and appends the | 356 // Generates a command line to be used to spawn a renderer and appends the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 354 | 371 |
| 355 // Creates a PersistentMemoryAllocator and shares it with the renderer | 372 // Creates a PersistentMemoryAllocator and shares it with the renderer |
| 356 // process for it to store histograms from that process. The allocator is | 373 // process for it to store histograms from that process. The allocator is |
| 357 // available for extraction by a SubprocesMetricsProvider in order to | 374 // available for extraction by a SubprocesMetricsProvider in order to |
| 358 // report those histograms to UMA. | 375 // report those histograms to UMA. |
| 359 void CreateSharedRendererHistogramAllocator(); | 376 void CreateSharedRendererHistogramAllocator(); |
| 360 | 377 |
| 361 // Handle termination of our process. | 378 // Handle termination of our process. |
| 362 void ProcessDied(bool already_dead, RendererClosedDetails* known_details); | 379 void ProcessDied(bool already_dead, RendererClosedDetails* known_details); |
| 363 | 380 |
| 381 void OnRouteProviderRequest(mojom::RouteProviderAssociatedRequest request); |
| 382 |
| 364 // GpuSwitchingObserver implementation. | 383 // GpuSwitchingObserver implementation. |
| 365 void OnGpuSwitched() override; | 384 void OnGpuSwitched() override; |
| 366 | 385 |
| 367 #if defined(ENABLE_WEBRTC) | 386 #if defined(ENABLE_WEBRTC) |
| 368 void OnRegisterAecDumpConsumer(int id); | 387 void OnRegisterAecDumpConsumer(int id); |
| 369 void OnUnregisterAecDumpConsumer(int id); | 388 void OnUnregisterAecDumpConsumer(int id); |
| 370 void RegisterAecDumpConsumerOnUIThread(int id); | 389 void RegisterAecDumpConsumerOnUIThread(int id); |
| 371 void UnregisterAecDumpConsumerOnUIThread(int id); | 390 void UnregisterAecDumpConsumerOnUIThread(int id); |
| 372 void EnableAecDumpForId(const base::FilePath& file, int id); | 391 void EnableAecDumpForId(const base::FilePath& file, int id); |
| 373 // Sends |file_for_transit| to the render process. | 392 // Sends |file_for_transit| to the render process. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 std::unique_ptr<InterfaceRegistryAndroid> interface_registry_android_; | 442 std::unique_ptr<InterfaceRegistryAndroid> interface_registry_android_; |
| 424 #endif | 443 #endif |
| 425 | 444 |
| 426 size_t service_worker_ref_count_; | 445 size_t service_worker_ref_count_; |
| 427 size_t shared_worker_ref_count_; | 446 size_t shared_worker_ref_count_; |
| 428 | 447 |
| 429 // The registered IPC listener objects. When this list is empty, we should | 448 // The registered IPC listener objects. When this list is empty, we should |
| 430 // delete ourselves. | 449 // delete ourselves. |
| 431 IDMap<IPC::Listener> listeners_; | 450 IDMap<IPC::Listener> listeners_; |
| 432 | 451 |
| 452 mojo::AssociatedBinding<mojom::RouteProvider> route_provider_binding_; |
| 453 mojo::AssociatedBindingSet<mojom::AssociatedInterfaceProvider> |
| 454 associated_interface_provider_bindings_; |
| 455 |
| 433 // The count of currently visible widgets. Since the host can be a container | 456 // The count of currently visible widgets. Since the host can be a container |
| 434 // for multiple widgets, it uses this count to determine when it should be | 457 // for multiple widgets, it uses this count to determine when it should be |
| 435 // backgrounded. | 458 // backgrounded. |
| 436 int32_t visible_widgets_; | 459 int32_t visible_widgets_; |
| 437 | 460 |
| 438 // Whether this process currently has backgrounded priority. Tracked so that | 461 // Whether this process currently has backgrounded priority. Tracked so that |
| 439 // UpdateProcessPriority() can avoid redundantly setting the priority. | 462 // UpdateProcessPriority() can avoid redundantly setting the priority. |
| 440 bool is_process_backgrounded_; | 463 bool is_process_backgrounded_; |
| 441 | 464 |
| 442 // Used to allow a RenderWidgetHost to intercept various messages on the | 465 // Used to allow a RenderWidgetHost to intercept various messages on the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 459 // also reset that in the case of process termination. | 482 // also reset that in the case of process termination. |
| 460 bool is_initialized_; | 483 bool is_initialized_; |
| 461 | 484 |
| 462 // PlzNavigate | 485 // PlzNavigate |
| 463 // Stores the time at which the first call to Init happened. | 486 // Stores the time at which the first call to Init happened. |
| 464 base::TimeTicks init_time_; | 487 base::TimeTicks init_time_; |
| 465 | 488 |
| 466 // Used to launch and terminate the process without blocking the UI thread. | 489 // Used to launch and terminate the process without blocking the UI thread. |
| 467 std::unique_ptr<ChildProcessLauncher> child_process_launcher_; | 490 std::unique_ptr<ChildProcessLauncher> child_process_launcher_; |
| 468 | 491 |
| 469 // Messages we queue while waiting for the process handle. We queue them here | 492 // Messages we queue before the ChannelProxy is created. |
| 470 // instead of in the channel so that we ensure they're sent after init related | 493 using MessageQueue = std::queue<std::unique_ptr<IPC::Message>>; |
| 471 // messages that are sent once the process handle is available. This is | 494 MessageQueue queued_messages_; |
| 472 // because the queued messages may have dependencies on the init messages. | |
| 473 std::queue<IPC::Message*> queued_messages_; | |
| 474 | 495 |
| 475 // The globally-unique identifier for this RPH. | 496 // The globally-unique identifier for this RPH. |
| 476 const int id_; | 497 const int id_; |
| 477 | 498 |
| 478 // A secondary ID used by the Mojo shell to distinguish different incarnations | 499 // A secondary ID used by the Mojo shell to distinguish different incarnations |
| 479 // of the same RPH from each other. Unlike |id_| this is not globally unique, | 500 // of the same RPH from each other. Unlike |id_| this is not globally unique, |
| 480 // but it is guaranteed to change every time Init() is called. | 501 // but it is guaranteed to change every time Init() is called. |
| 481 int instance_id_ = 1; | 502 int instance_id_ = 1; |
| 482 | 503 |
| 483 BrowserContext* browser_context_; | 504 BrowserContext* browser_context_; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 // UI thread is the source of sync IPCs and all shutdown signals. | 589 // UI thread is the source of sync IPCs and all shutdown signals. |
| 569 // Therefore a proper shutdown event to unblock the UI thread is not | 590 // Therefore a proper shutdown event to unblock the UI thread is not |
| 570 // possible without massive refactoring shutdown code. | 591 // possible without massive refactoring shutdown code. |
| 571 // Luckily Android never performs a clean shutdown. So explicitly | 592 // Luckily Android never performs a clean shutdown. So explicitly |
| 572 // ignore this problem. | 593 // ignore this problem. |
| 573 base::WaitableEvent never_signaled_; | 594 base::WaitableEvent never_signaled_; |
| 574 #endif | 595 #endif |
| 575 | 596 |
| 576 scoped_refptr<ResourceMessageFilter> resource_message_filter_; | 597 scoped_refptr<ResourceMessageFilter> resource_message_filter_; |
| 577 | 598 |
| 599 mojom::RouteProviderAssociatedPtr remote_route_provider_; |
| 600 |
| 578 // A WeakPtrFactory which is reset every time Cleanup() runs. Used to vend | 601 // A WeakPtrFactory which is reset every time Cleanup() runs. Used to vend |
| 579 // WeakPtrs which are invalidated any time the RPHI is recycled. | 602 // WeakPtrs which are invalidated any time the RPHI is recycled. |
| 580 std::unique_ptr<base::WeakPtrFactory<RenderProcessHostImpl>> | 603 std::unique_ptr<base::WeakPtrFactory<RenderProcessHostImpl>> |
| 581 instance_weak_factory_; | 604 instance_weak_factory_; |
| 582 | 605 |
| 583 base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_; | 606 base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_; |
| 584 | 607 |
| 585 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); | 608 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); |
| 586 }; | 609 }; |
| 587 | 610 |
| 588 } // namespace content | 611 } // namespace content |
| 589 | 612 |
| 590 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_IMPL_H_ | 613 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_IMPL_H_ |
| OLD | NEW |