| 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> |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 is_for_guests_only_(is_for_guests_only), | 519 is_for_guests_only_(is_for_guests_only), |
| 520 gpu_observer_registered_(false), | 520 gpu_observer_registered_(false), |
| 521 delayed_cleanup_needed_(false), | 521 delayed_cleanup_needed_(false), |
| 522 within_process_died_observer_(false), | 522 within_process_died_observer_(false), |
| 523 power_monitor_broadcaster_(this), | 523 power_monitor_broadcaster_(this), |
| 524 worker_ref_count_(0), | 524 worker_ref_count_(0), |
| 525 max_worker_count_(0), | 525 max_worker_count_(0), |
| 526 permission_service_context_(new PermissionServiceContext(this)), | 526 permission_service_context_(new PermissionServiceContext(this)), |
| 527 pending_valuebuffer_state_(new gpu::ValueStateMap()), | 527 pending_valuebuffer_state_(new gpu::ValueStateMap()), |
| 528 subscribe_uniform_enabled_(false), | 528 subscribe_uniform_enabled_(false), |
| 529 channel_connected_(false), |
| 530 sent_render_process_ready_(false), |
| 529 weak_factory_(this) { | 531 weak_factory_(this) { |
| 530 widget_helper_ = new RenderWidgetHelper(); | 532 widget_helper_ = new RenderWidgetHelper(); |
| 531 | 533 |
| 532 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID()); | 534 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID()); |
| 533 | 535 |
| 534 CHECK(!BrowserMainRunner::ExitedMainMessageLoop()); | 536 CHECK(!BrowserMainRunner::ExitedMainMessageLoop()); |
| 535 RegisterHost(GetID(), this); | 537 RegisterHost(GetID(), this); |
| 536 g_all_hosts.Get().set_check_on_null_data(true); | 538 g_all_hosts.Get().set_check_on_null_data(true); |
| 537 // Initialize |child_process_activity_time_| to a reasonable value. | 539 // Initialize |child_process_activity_time_| to a reasonable value. |
| 538 mark_child_process_activity_time(); | 540 mark_child_process_activity_time(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 #else | 648 #else |
| 647 int flags = ChildProcessHost::CHILD_NORMAL; | 649 int flags = ChildProcessHost::CHILD_NORMAL; |
| 648 #endif | 650 #endif |
| 649 | 651 |
| 650 // Find the renderer before creating the channel so if this fails early we | 652 // Find the renderer before creating the channel so if this fails early we |
| 651 // return without creating the channel. | 653 // return without creating the channel. |
| 652 base::FilePath renderer_path = ChildProcessHost::GetChildPath(flags); | 654 base::FilePath renderer_path = ChildProcessHost::GetChildPath(flags); |
| 653 if (renderer_path.empty()) | 655 if (renderer_path.empty()) |
| 654 return false; | 656 return false; |
| 655 | 657 |
| 658 channel_connected_ = false; |
| 659 sent_render_process_ready_ = false; |
| 660 |
| 656 // Setup the IPC channel. | 661 // Setup the IPC channel. |
| 657 const std::string channel_id = | 662 const std::string channel_id = |
| 658 IPC::Channel::GenerateVerifiedChannelID(std::string()); | 663 IPC::Channel::GenerateVerifiedChannelID(std::string()); |
| 659 channel_ = CreateChannelProxy(channel_id); | 664 channel_ = CreateChannelProxy(channel_id); |
| 660 | 665 |
| 661 // Setup the Mojo channel. | 666 // Setup the Mojo channel. |
| 662 mojo_application_host_->Init(); | 667 mojo_application_host_->Init(); |
| 663 | 668 |
| 664 // Call the embedder first so that their IPC filters have priority. | 669 // Call the embedder first so that their IPC filters have priority. |
| 665 GetContentClient()->browser()->RenderProcessWillLaunch(this); | 670 GetContentClient()->browser()->RenderProcessWillLaunch(this); |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 base::ProcessHandle RenderProcessHostImpl::GetHandle() const { | 1480 base::ProcessHandle RenderProcessHostImpl::GetHandle() const { |
| 1476 if (run_renderer_in_process()) | 1481 if (run_renderer_in_process()) |
| 1477 return base::GetCurrentProcessHandle(); | 1482 return base::GetCurrentProcessHandle(); |
| 1478 | 1483 |
| 1479 if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) | 1484 if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) |
| 1480 return base::kNullProcessHandle; | 1485 return base::kNullProcessHandle; |
| 1481 | 1486 |
| 1482 return child_process_launcher_->GetProcess().Handle(); | 1487 return child_process_launcher_->GetProcess().Handle(); |
| 1483 } | 1488 } |
| 1484 | 1489 |
| 1490 bool RenderProcessHostImpl::IsReady() const { |
| 1491 // The process launch result (that sets GetHandle()) and the channel |
| 1492 // connection (that sets channel_connected_) can happen in either order. |
| 1493 return GetHandle() && channel_connected_; |
| 1494 } |
| 1495 |
| 1485 bool RenderProcessHostImpl::Shutdown(int exit_code, bool wait) { | 1496 bool RenderProcessHostImpl::Shutdown(int exit_code, bool wait) { |
| 1486 if (run_renderer_in_process()) | 1497 if (run_renderer_in_process()) |
| 1487 return false; // Single process mode never shuts down the renderer. | 1498 return false; // Single process mode never shuts down the renderer. |
| 1488 | 1499 |
| 1489 #if defined(OS_ANDROID) | 1500 #if defined(OS_ANDROID) |
| 1490 // Android requires a different approach for killing. | 1501 // Android requires a different approach for killing. |
| 1491 StopChildProcess(GetHandle()); | 1502 StopChildProcess(GetHandle()); |
| 1492 return true; | 1503 return true; |
| 1493 #else | 1504 #else |
| 1494 if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) | 1505 if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 1605 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
| 1595 reply->set_reply_error(); | 1606 reply->set_reply_error(); |
| 1596 Send(reply); | 1607 Send(reply); |
| 1597 } | 1608 } |
| 1598 return true; | 1609 return true; |
| 1599 } | 1610 } |
| 1600 return listener->OnMessageReceived(msg); | 1611 return listener->OnMessageReceived(msg); |
| 1601 } | 1612 } |
| 1602 | 1613 |
| 1603 void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) { | 1614 void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) { |
| 1615 channel_connected_ = true; |
| 1616 if (IsReady()) { |
| 1617 DCHECK(!sent_render_process_ready_); |
| 1618 sent_render_process_ready_ = true; |
| 1619 // Send RenderProcessReady only if we already received the process handle. |
| 1620 FOR_EACH_OBSERVER(RenderProcessHostObserver, |
| 1621 observers_, |
| 1622 RenderProcessReady(this)); |
| 1623 } |
| 1624 |
| 1604 #if defined(IPC_MESSAGE_LOG_ENABLED) | 1625 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 1605 Send(new ChildProcessMsg_SetIPCLoggingEnabled( | 1626 Send(new ChildProcessMsg_SetIPCLoggingEnabled( |
| 1606 IPC::Logging::GetInstance()->Enabled())); | 1627 IPC::Logging::GetInstance()->Enabled())); |
| 1607 #endif | 1628 #endif |
| 1608 | 1629 |
| 1609 tracked_objects::ThreadData::Status status = | 1630 tracked_objects::ThreadData::Status status = |
| 1610 tracked_objects::ThreadData::status(); | 1631 tracked_objects::ThreadData::status(); |
| 1611 Send(new ChildProcessMsg_SetProfilerStatus(status)); | 1632 Send(new ChildProcessMsg_SetProfilerStatus(status)); |
| 1612 | 1633 |
| 1613 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1634 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2396 // is fixed. | 2417 // is fixed. |
| 2397 tracked_objects::ScopedTracker tracking_profile6( | 2418 tracked_objects::ScopedTracker tracking_profile6( |
| 2398 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 2419 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2399 "465841 " | 2420 "465841 " |
| 2400 "RenderProcessHostImpl::OnProcessLaunched::SendQueuedMessages")); | 2421 "RenderProcessHostImpl::OnProcessLaunched::SendQueuedMessages")); |
| 2401 while (!queued_messages_.empty()) { | 2422 while (!queued_messages_.empty()) { |
| 2402 Send(queued_messages_.front()); | 2423 Send(queued_messages_.front()); |
| 2403 queued_messages_.pop(); | 2424 queued_messages_.pop(); |
| 2404 } | 2425 } |
| 2405 | 2426 |
| 2427 if (IsReady()) { |
| 2428 DCHECK(!sent_render_process_ready_); |
| 2429 sent_render_process_ready_ = true; |
| 2430 // Send RenderProcessReady only if the channel is already connected. |
| 2431 FOR_EACH_OBSERVER(RenderProcessHostObserver, |
| 2432 observers_, |
| 2433 RenderProcessReady(this)); |
| 2434 } |
| 2435 |
| 2406 #if defined(ENABLE_WEBRTC) | 2436 #if defined(ENABLE_WEBRTC) |
| 2407 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841 | 2437 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841 |
| 2408 // is fixed. | 2438 // is fixed. |
| 2409 tracked_objects::ScopedTracker tracking_profile7( | 2439 tracked_objects::ScopedTracker tracking_profile7( |
| 2410 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 2440 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2411 "465841 RenderProcessHostImpl::OnProcessLaunched::EnableAec")); | 2441 "465841 RenderProcessHostImpl::OnProcessLaunched::EnableAec")); |
| 2412 if (WebRTCInternals::GetInstance()->IsAudioDebugRecordingsEnabled()) { | 2442 if (WebRTCInternals::GetInstance()->IsAudioDebugRecordingsEnabled()) { |
| 2413 EnableAudioDebugRecordings( | 2443 EnableAudioDebugRecordings( |
| 2414 WebRTCInternals::GetInstance()->GetAudioDebugRecordingsFilePath()); | 2444 WebRTCInternals::GetInstance()->GetAudioDebugRecordingsFilePath()); |
| 2415 } | 2445 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2561 void RenderProcessHostImpl::GetAudioOutputControllers( | 2591 void RenderProcessHostImpl::GetAudioOutputControllers( |
| 2562 const GetAudioOutputControllersCallback& callback) const { | 2592 const GetAudioOutputControllersCallback& callback) const { |
| 2563 audio_renderer_host()->GetOutputControllers(callback); | 2593 audio_renderer_host()->GetOutputControllers(callback); |
| 2564 } | 2594 } |
| 2565 | 2595 |
| 2566 BluetoothDispatcherHost* RenderProcessHostImpl::GetBluetoothDispatcherHost() { | 2596 BluetoothDispatcherHost* RenderProcessHostImpl::GetBluetoothDispatcherHost() { |
| 2567 return bluetooth_dispatcher_host_.get(); | 2597 return bluetooth_dispatcher_host_.get(); |
| 2568 } | 2598 } |
| 2569 | 2599 |
| 2570 } // namespace content | 2600 } // namespace content |
| OLD | NEW |