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 // 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 347 |
348 void AddIntegerValue(CFMutableDictionaryRef dictionary, | 348 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
349 const CFStringRef key, | 349 const CFStringRef key, |
350 int32 value) { | 350 int32 value) { |
351 base::ScopedCFTypeRef<CFNumberRef> number( | 351 base::ScopedCFTypeRef<CFNumberRef> number( |
352 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 352 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
353 CFDictionaryAddValue(dictionary, key, number.get()); | 353 CFDictionaryAddValue(dictionary, key, number.get()); |
354 } | 354 } |
355 #endif | 355 #endif |
356 | 356 |
| 357 const char kSessionStorageHolderKey[] = "kSessionStorageHolderKey"; |
| 358 |
| 359 class SessionStorageHolder : public base::SupportsUserData::Data { |
| 360 public: |
| 361 SessionStorageHolder() {} |
| 362 virtual ~SessionStorageHolder() {} |
| 363 |
| 364 void Hold(const SessionStorageNamespaceMap& sessions, int view_route_id) { |
| 365 session_storage_namespaces_awaiting_close_[view_route_id] = sessions; |
| 366 } |
| 367 |
| 368 void Release(int old_route_id) { |
| 369 session_storage_namespaces_awaiting_close_.erase(old_route_id); |
| 370 } |
| 371 |
| 372 private: |
| 373 std::map<int, SessionStorageNamespaceMap > |
| 374 session_storage_namespaces_awaiting_close_; |
| 375 DISALLOW_COPY_AND_ASSIGN(SessionStorageHolder); |
| 376 }; |
| 377 |
357 } // namespace | 378 } // namespace |
358 | 379 |
359 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; | 380 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; |
360 | 381 |
361 base::MessageLoop* g_in_process_thread; | 382 base::MessageLoop* g_in_process_thread; |
362 | 383 |
363 base::MessageLoop* | 384 base::MessageLoop* |
364 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { | 385 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { |
365 return g_in_process_thread; | 386 return g_in_process_thread; |
366 } | 387 } |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DumpHandlesDone, | 1367 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DumpHandlesDone, |
1347 OnDumpHandlesDone) | 1368 OnDumpHandlesDone) |
1348 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, | 1369 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, |
1349 SuddenTerminationChanged) | 1370 SuddenTerminationChanged) |
1350 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, | 1371 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, |
1351 OnUserMetricsRecordAction) | 1372 OnUserMetricsRecordAction) |
1352 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) | 1373 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) |
1353 IPC_MESSAGE_HANDLER_DELAY_REPLY( | 1374 IPC_MESSAGE_HANDLER_DELAY_REPLY( |
1354 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, | 1375 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, |
1355 OnAllocateGpuMemoryBuffer) | 1376 OnAllocateGpuMemoryBuffer) |
| 1377 IPC_MESSAGE_HANDLER(ViewHostMsg_Close_ACK, OnCloseACK) |
1356 // Adding single handlers for your service here is fine, but once your | 1378 // Adding single handlers for your service here is fine, but once your |
1357 // service needs more than one handler, please extract them into a new | 1379 // service needs more than one handler, please extract them into a new |
1358 // message filter and add that filter to CreateMessageFilters(). | 1380 // message filter and add that filter to CreateMessageFilters(). |
1359 IPC_END_MESSAGE_MAP() | 1381 IPC_END_MESSAGE_MAP() |
1360 | 1382 |
1361 return true; | 1383 return true; |
1362 } | 1384 } |
1363 | 1385 |
1364 // Dispatch incoming messages to the appropriate IPC::Listener. | 1386 // Dispatch incoming messages to the appropriate IPC::Listener. |
1365 IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); | 1387 IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 deleting_soon_ = true; | 1499 deleting_soon_ = true; |
1478 // It's important not to wait for the DeleteTask to delete the channel | 1500 // It's important not to wait for the DeleteTask to delete the channel |
1479 // proxy. Kill it off now. That way, in case the profile is going away, the | 1501 // proxy. Kill it off now. That way, in case the profile is going away, the |
1480 // rest of the objects attached to this RenderProcessHost start going | 1502 // rest of the objects attached to this RenderProcessHost start going |
1481 // away first, since deleting the channel proxy will post a | 1503 // away first, since deleting the channel proxy will post a |
1482 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 1504 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
1483 channel_.reset(); | 1505 channel_.reset(); |
1484 gpu_message_filter_ = NULL; | 1506 gpu_message_filter_ = NULL; |
1485 message_port_message_filter_ = NULL; | 1507 message_port_message_filter_ = NULL; |
1486 screen_orientation_dispatcher_host_ = NULL; | 1508 screen_orientation_dispatcher_host_ = NULL; |
| 1509 RemoveUserData(kSessionStorageHolderKey); |
1487 | 1510 |
1488 // Remove ourself from the list of renderer processes so that we can't be | 1511 // Remove ourself from the list of renderer processes so that we can't be |
1489 // reused in between now and when the Delete task runs. | 1512 // reused in between now and when the Delete task runs. |
1490 UnregisterHost(GetID()); | 1513 UnregisterHost(GetID()); |
1491 } | 1514 } |
1492 } | 1515 } |
1493 | 1516 |
1494 void RenderProcessHostImpl::AddPendingView() { | 1517 void RenderProcessHostImpl::AddPendingView() { |
1495 pending_views_++; | 1518 pending_views_++; |
1496 } | 1519 } |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 FOR_EACH_OBSERVER(RenderProcessHostObserver, | 1913 FOR_EACH_OBSERVER(RenderProcessHostObserver, |
1891 observers_, | 1914 observers_, |
1892 RenderProcessExited(this, GetHandle(), status, exit_code)); | 1915 RenderProcessExited(this, GetHandle(), status, exit_code)); |
1893 within_process_died_observer_ = false; | 1916 within_process_died_observer_ = false; |
1894 | 1917 |
1895 child_process_launcher_.reset(); | 1918 child_process_launcher_.reset(); |
1896 channel_.reset(); | 1919 channel_.reset(); |
1897 gpu_message_filter_ = NULL; | 1920 gpu_message_filter_ = NULL; |
1898 message_port_message_filter_ = NULL; | 1921 message_port_message_filter_ = NULL; |
1899 screen_orientation_dispatcher_host_ = NULL; | 1922 screen_orientation_dispatcher_host_ = NULL; |
| 1923 RemoveUserData(kSessionStorageHolderKey); |
1900 | 1924 |
1901 IDMap<IPC::Listener>::iterator iter(&listeners_); | 1925 IDMap<IPC::Listener>::iterator iter(&listeners_); |
1902 while (!iter.IsAtEnd()) { | 1926 while (!iter.IsAtEnd()) { |
1903 iter.GetCurrentValue()->OnMessageReceived( | 1927 iter.GetCurrentValue()->OnMessageReceived( |
1904 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(), | 1928 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(), |
1905 static_cast<int>(status), | 1929 static_cast<int>(status), |
1906 exit_code)); | 1930 exit_code)); |
1907 iter.Advance(); | 1931 iter.Advance(); |
1908 } | 1932 } |
1909 | 1933 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 if (!webrtc_log_message_callback_.is_null()) | 1982 if (!webrtc_log_message_callback_.is_null()) |
1959 webrtc_log_message_callback_.Run(message); | 1983 webrtc_log_message_callback_.Run(message); |
1960 } | 1984 } |
1961 #endif | 1985 #endif |
1962 | 1986 |
1963 scoped_refptr<ScreenOrientationDispatcherHost> | 1987 scoped_refptr<ScreenOrientationDispatcherHost> |
1964 RenderProcessHostImpl::screen_orientation_dispatcher_host() const { | 1988 RenderProcessHostImpl::screen_orientation_dispatcher_host() const { |
1965 return make_scoped_refptr(screen_orientation_dispatcher_host_); | 1989 return make_scoped_refptr(screen_orientation_dispatcher_host_); |
1966 } | 1990 } |
1967 | 1991 |
| 1992 void RenderProcessHostImpl::ReleaseOnCloseACK( |
| 1993 RenderProcessHost* host, |
| 1994 const SessionStorageNamespaceMap& sessions, |
| 1995 int view_route_id) { |
| 1996 DCHECK(host); |
| 1997 if (sessions.empty()) |
| 1998 return; |
| 1999 SessionStorageHolder* holder = static_cast<SessionStorageHolder*> |
| 2000 (host->GetUserData(kSessionStorageHolderKey)); |
| 2001 if (!holder) { |
| 2002 holder = new SessionStorageHolder(); |
| 2003 host->SetUserData( |
| 2004 kSessionStorageHolderKey, |
| 2005 holder); |
| 2006 } |
| 2007 holder->Hold(sessions, view_route_id); |
| 2008 } |
| 2009 |
1968 void RenderProcessHostImpl::OnShutdownRequest() { | 2010 void RenderProcessHostImpl::OnShutdownRequest() { |
1969 // Don't shut down if there are active RenderViews, or if there are pending | 2011 // Don't shut down if there are active RenderViews, or if there are pending |
1970 // RenderViews being swapped back in. | 2012 // RenderViews being swapped back in. |
1971 // In single process mode, we never shutdown the renderer. | 2013 // In single process mode, we never shutdown the renderer. |
1972 int num_active_views = GetActiveViewCount(); | 2014 int num_active_views = GetActiveViewCount(); |
1973 if (pending_views_ || num_active_views > 0 || run_renderer_in_process()) | 2015 if (pending_views_ || num_active_views > 0 || run_renderer_in_process()) |
1974 return; | 2016 return; |
1975 | 2017 |
1976 // Notify any contents that might have swapped out renderers from this | 2018 // Notify any contents that might have swapped out renderers from this |
1977 // process. They should not attempt to swap them back in. | 2019 // process. They should not attempt to swap them back in. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2075 scoped_refptr<AudioRendererHost> | 2117 scoped_refptr<AudioRendererHost> |
2076 RenderProcessHostImpl::audio_renderer_host() const { | 2118 RenderProcessHostImpl::audio_renderer_host() const { |
2077 return audio_renderer_host_; | 2119 return audio_renderer_host_; |
2078 } | 2120 } |
2079 | 2121 |
2080 void RenderProcessHostImpl::OnUserMetricsRecordAction( | 2122 void RenderProcessHostImpl::OnUserMetricsRecordAction( |
2081 const std::string& action) { | 2123 const std::string& action) { |
2082 RecordComputedAction(action); | 2124 RecordComputedAction(action); |
2083 } | 2125 } |
2084 | 2126 |
| 2127 void RenderProcessHostImpl::OnCloseACK(int old_route_id) { |
| 2128 SessionStorageHolder* holder = static_cast<SessionStorageHolder*> |
| 2129 (GetUserData(kSessionStorageHolderKey)); |
| 2130 if (!holder) |
| 2131 return; |
| 2132 holder->Release(old_route_id); |
| 2133 } |
| 2134 |
2085 void RenderProcessHostImpl::OnSavedPageAsMHTML(int job_id, int64 data_size) { | 2135 void RenderProcessHostImpl::OnSavedPageAsMHTML(int job_id, int64 data_size) { |
2086 MHTMLGenerationManager::GetInstance()->MHTMLGenerated(job_id, data_size); | 2136 MHTMLGenerationManager::GetInstance()->MHTMLGenerated(job_id, data_size); |
2087 } | 2137 } |
2088 | 2138 |
2089 void RenderProcessHostImpl::OnCompositorSurfaceBuffersSwappedNoHost( | 2139 void RenderProcessHostImpl::OnCompositorSurfaceBuffersSwappedNoHost( |
2090 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params) { | 2140 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params) { |
2091 TRACE_EVENT0("renderer_host", | 2141 TRACE_EVENT0("renderer_host", |
2092 "RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwappedNoHost"); | 2142 "RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwappedNoHost"); |
2093 if (!ui::LatencyInfo::Verify(params.latency_info, | 2143 if (!ui::LatencyInfo::Verify(params.latency_info, |
2094 "ViewHostMsg_CompositorSurfaceBuffersSwapped")) | 2144 "ViewHostMsg_CompositorSurfaceBuffersSwapped")) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2251 void RenderProcessHostImpl::GpuMemoryBufferAllocated( | 2301 void RenderProcessHostImpl::GpuMemoryBufferAllocated( |
2252 IPC::Message* reply, | 2302 IPC::Message* reply, |
2253 const gfx::GpuMemoryBufferHandle& handle) { | 2303 const gfx::GpuMemoryBufferHandle& handle) { |
2254 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2304 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2255 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, | 2305 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, |
2256 handle); | 2306 handle); |
2257 Send(reply); | 2307 Send(reply); |
2258 } | 2308 } |
2259 | 2309 |
2260 } // namespace content | 2310 } // namespace content |
OLD | NEW |