summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzturner@chromium.org <zturner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-10 19:13:02 +0000
committerzturner@chromium.org <zturner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-10 19:13:02 +0000
commit950be55e1a72d70b783a281b04c8025801ba1141 (patch)
treea458743396ab849fca0ef35f11dbbca1496b7881
parent156e714fe729cab99af62aee3c866333e2608e64 (diff)
downloadchromium_src-950be55e1a72d70b783a281b04c8025801ba1141.zip
chromium_src-950be55e1a72d70b783a281b04c8025801ba1141.tar.gz
chromium_src-950be55e1a72d70b783a281b04c8025801ba1141.tar.bz2
Lazily allocate peer handles in the BrowserMessageFilter to reduce excessive
handle usage. BUG=252980 Review URL: https://chromiumcodereview.appspot.com/18580007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210904 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc2
-rw-r--r--chrome/browser/media/webrtc_logging_handler_host.cc2
-rw-r--r--chrome/browser/nacl_host/nacl_file_host.cc6
-rw-r--r--chrome/browser/nacl_host/nacl_process_host.cc2
-rw-r--r--chrome/browser/printing/printing_message_filter.cc2
-rw-r--r--chrome/browser/renderer_host/chrome_render_message_filter.cc8
-rw-r--r--content/browser/fileapi/fileapi_message_filter.cc4
-rw-r--r--content/browser/indexed_db/indexed_db_dispatcher_host.cc4
-rw-r--r--content/browser/loader/async_resource_handler.cc4
-rw-r--r--content/browser/profiler_message_filter.cc2
-rw-r--r--content/browser/renderer_host/clipboard_message_filter.cc4
-rw-r--r--content/browser/renderer_host/database_message_filter.cc2
-rw-r--r--content/browser/renderer_host/file_utilities_message_filter.cc2
-rw-r--r--content/browser/renderer_host/gamepad_browser_message_filter.cc2
-rw-r--r--content/browser/renderer_host/media/audio_input_renderer_host.cc6
-rw-r--r--content/browser/renderer_host/media/audio_renderer_host.cc6
-rw-r--r--content/browser/renderer_host/media/peer_connection_tracker_host.cc10
-rw-r--r--content/browser/renderer_host/media/video_capture_host.cc2
-rw-r--r--content/browser/renderer_host/render_message_filter.cc16
-rw-r--r--content/public/browser/browser_message_filter.cc31
-rw-r--r--content/public/browser/browser_message_filter.h14
21 files changed, 80 insertions, 51 deletions
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index daa25d2..14e384a 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -155,7 +155,7 @@ void IOThreadResponseCallback(
CommonResponseCallback(ipc_sender.get(),
routing_id,
- ipc_sender->peer_handle(),
+ ipc_sender->PeerHandle(),
request_id,
type,
results,
diff --git a/chrome/browser/media/webrtc_logging_handler_host.cc b/chrome/browser/media/webrtc_logging_handler_host.cc
index c46ae32..8839fac 100644
--- a/chrome/browser/media/webrtc_logging_handler_host.cc
+++ b/chrome/browser/media/webrtc_logging_handler_host.cc
@@ -165,7 +165,7 @@ void WebRtcLoggingHandlerHost::DoOpenLog() {
return;
}
- if (!shared_memory_->ShareToProcess(peer_handle(),
+ if (!shared_memory_->ShareToProcess(PeerHandle(),
&foreign_memory_handle_)) {
Send(new WebRtcLoggingMsg_OpenLogFailed());
return;
diff --git a/chrome/browser/nacl_host/nacl_file_host.cc b/chrome/browser/nacl_host/nacl_file_host.cc
index 21646ef..0ea1e9a 100644
--- a/chrome/browser/nacl_host/nacl_file_host.cc
+++ b/chrome/browser/nacl_host/nacl_file_host.cc
@@ -134,7 +134,7 @@ void DoOpenPnaclFile(
// Do any DuplicateHandle magic that is necessary first.
IPC::PlatformFileForTransit target_desc =
IPC::GetFileHandleForProcess(file_to_open,
- nacl_host_message_filter->peer_handle(),
+ nacl_host_message_filter->PeerHandle(),
true /* Close source */);
if (target_desc == IPC::InvalidPlatformFileForTransit()) {
NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
@@ -173,7 +173,7 @@ void DoCreateTemporaryFile(
// Do any DuplicateHandle magic that is necessary first.
IPC::PlatformFileForTransit target_desc =
IPC::GetFileHandleForProcess(file_handle,
- nacl_host_message_filter->peer_handle(),
+ nacl_host_message_filter->PeerHandle(),
true);
if (target_desc == IPC::InvalidPlatformFileForTransit()) {
NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
@@ -200,7 +200,7 @@ void DoRegisterOpenedNaClExecutableFile(
IPC::PlatformFileForTransit file_desc = IPC::GetFileHandleForProcess(
file,
- nacl_host_message_filter->peer_handle(),
+ nacl_host_message_filter->PeerHandle(),
true /* close_source */);
NaClHostMsg_OpenNaClExecutable::WriteReplyParams(
diff --git a/chrome/browser/nacl_host/nacl_process_host.cc b/chrome/browser/nacl_host/nacl_process_host.cc
index f0125ce..13e6634 100644
--- a/chrome/browser/nacl_host/nacl_process_host.cc
+++ b/chrome/browser/nacl_host/nacl_process_host.cc
@@ -513,7 +513,7 @@ bool NaClProcessHost::ReplyToRenderer(
if (!DuplicateHandle(base::GetCurrentProcessHandle(),
reinterpret_cast<HANDLE>(
internal_->socket_for_renderer),
- nacl_host_message_filter_->peer_handle(),
+ nacl_host_message_filter_->PeerHandle(),
&handle_in_renderer,
0, // Unused given DUPLICATE_SAME_ACCESS.
FALSE,
diff --git a/chrome/browser/printing/printing_message_filter.cc b/chrome/browser/printing/printing_message_filter.cc
index 1bbb85b..09ad68f 100644
--- a/chrome/browser/printing/printing_message_filter.cc
+++ b/chrome/browser/printing/printing_message_filter.cc
@@ -132,7 +132,7 @@ void PrintingMessageFilter::OnDuplicateSection(
base::SharedMemoryHandle* browser_handle) {
// Duplicate the handle in this process right now so the memory is kept alive
// (even if it is not mapped)
- base::SharedMemory shared_buf(renderer_handle, true, peer_handle());
+ base::SharedMemory shared_buf(renderer_handle, true, PeerHandle());
shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), browser_handle);
}
#endif
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc
index df2858c..645f90a 100644
--- a/chrome/browser/renderer_host/chrome_render_message_filter.cc
+++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc
@@ -299,8 +299,8 @@ void ChromeRenderMessageFilter::OnResourceTypeStats(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
#if defined(ENABLE_TASK_MANAGER)
- TaskManager::GetInstance()->model()->NotifyResourceTypeStats(
- base::GetProcId(peer_handle()), stats);
+ TaskManager::GetInstance()->model()->NotifyResourceTypeStats(peer_pid(),
+ stats);
#endif // defined(ENABLE_TASK_MANAGER)
}
@@ -319,7 +319,7 @@ void ChromeRenderMessageFilter::OnFPS(int routing_id, float fps) {
return;
}
- base::ProcessId renderer_id = base::GetProcId(peer_handle());
+ base::ProcessId renderer_id = peer_pid();
#if defined(ENABLE_TASK_MANAGER)
TaskManager::GetInstance()->model()->NotifyFPS(
@@ -344,7 +344,7 @@ void ChromeRenderMessageFilter::OnV8HeapStats(int v8_memory_allocated,
return;
}
- base::ProcessId renderer_id = base::GetProcId(peer_handle());
+ base::ProcessId renderer_id = peer_pid();
#if defined(ENABLE_TASK_MANAGER)
TaskManager::GetInstance()->model()->NotifyV8HeapStats(
diff --git a/content/browser/fileapi/fileapi_message_filter.cc b/content/browser/fileapi/fileapi_message_filter.cc
index 63a50a1..312e04d 100644
--- a/content/browser/fileapi/fileapi_message_filter.cc
+++ b/content/browser/fileapi/fileapi_message_filter.cc
@@ -440,7 +440,7 @@ void FileAPIMessageFilter::OnOpenFile(
}
operations_[request_id] = operation_runner()->OpenFile(
- url, file_flags, peer_handle(),
+ url, file_flags, PeerHandle(),
base::Bind(&FileAPIMessageFilter::DidOpenFile, this, request_id,
quota_policy));
}
@@ -552,7 +552,7 @@ void FileAPIMessageFilter::OnAppendSharedMemory(
return;
}
#if defined(OS_WIN)
- base::SharedMemory shared_memory(handle, true, peer_handle());
+ base::SharedMemory shared_memory(handle, true, PeerHandle());
#else
base::SharedMemory shared_memory(handle, true);
#endif
diff --git a/content/browser/indexed_db/indexed_db_dispatcher_host.cc b/content/browser/indexed_db/indexed_db_dispatcher_host.cc
index ee9882f..87f430e 100644
--- a/content/browser/indexed_db/indexed_db_dispatcher_host.cc
+++ b/content/browser/indexed_db/indexed_db_dispatcher_host.cc
@@ -143,7 +143,7 @@ int64 IndexedDBDispatcherHost::HostTransactionId(int64 transaction_id) {
// uniquely identify this transaction, and effectively bind it to
// the renderer that initiated it. The lower 32 bits of
// transaction_id are guaranteed to be unique within that renderer.
- base::ProcessId pid = base::GetProcId(peer_handle());
+ base::ProcessId pid = peer_pid();
DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits";
COMPILE_ASSERT(sizeof(base::ProcessId) <= sizeof(int32),
Process_ID_must_fit_in_32_bits);
@@ -153,7 +153,7 @@ int64 IndexedDBDispatcherHost::HostTransactionId(int64 transaction_id) {
int64 IndexedDBDispatcherHost::RendererTransactionId(
int64 host_transaction_id) {
- DCHECK(host_transaction_id >> 32 == base::GetProcId(peer_handle()))
+ DCHECK(host_transaction_id >> 32 == peer_pid())
<< "Invalid renderer target for transaction id";
return host_transaction_id & 0xffffffff;
}
diff --git a/content/browser/loader/async_resource_handler.cc b/content/browser/loader/async_resource_handler.cc
index 574b137..d0bade5 100644
--- a/content/browser/loader/async_resource_handler.cc
+++ b/content/browser/loader/async_resource_handler.cc
@@ -253,11 +253,11 @@ bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read,
if (!sent_first_data_msg_) {
base::SharedMemoryHandle handle;
int size;
- if (!buffer_->ShareToProcess(filter_->peer_handle(), &handle, &size))
+ if (!buffer_->ShareToProcess(filter_->PeerHandle(), &handle, &size))
return false;
filter_->Send(
new ResourceMsg_SetDataBuffer(routing_id_, request_id, handle, size,
- base::GetProcId(filter_->peer_handle())));
+ filter_->peer_pid()));
sent_first_data_msg_ = true;
}
diff --git a/content/browser/profiler_message_filter.cc b/content/browser/profiler_message_filter.cc
index 217a2f4..9eeaa03 100644
--- a/content/browser/profiler_message_filter.cc
+++ b/content/browser/profiler_message_filter.cc
@@ -50,7 +50,7 @@ void ProfilerMessageFilter::OnChildProfilerData(
#if defined(USE_TCMALLOC)
void ProfilerMessageFilter::OnTcmallocStats(const std::string& output) {
AboutTcmallocOutputs::GetInstance()->OnStatsForChildProcess(
- base::GetProcId(peer_handle()), process_type_, output);
+ peer_pid(), process_type_, output);
}
#endif
diff --git a/content/browser/renderer_host/clipboard_message_filter.cc b/content/browser/renderer_host/clipboard_message_filter.cc
index 1d4a851..46475df 100644
--- a/content/browser/renderer_host/clipboard_message_filter.cc
+++ b/content/browser/renderer_host/clipboard_message_filter.cc
@@ -95,7 +95,7 @@ void ClipboardMessageFilter::OnWriteObjectsSync(
DCHECK(base::SharedMemory::IsHandleValid(bitmap_handle))
<< "Bad bitmap handle";
// Splice the shared memory handle into the clipboard data.
- ui::Clipboard::ReplaceSharedMemHandle(&objects, bitmap_handle, peer_handle());
+ ui::Clipboard::ReplaceSharedMemHandle(&objects, bitmap_handle, PeerHandle());
#if defined(OS_WIN)
// We cannot write directly from the IO thread, and cannot service the IPC
// on the UI thread. We'll copy the relevant data and get a handle to any
@@ -214,7 +214,7 @@ void ClipboardMessageFilter::OnReadImageReply(
base::SharedMemory buffer;
if (buffer.CreateAndMapAnonymous(png_data.size())) {
memcpy(buffer.memory(), vector_as_array(&png_data), png_data.size());
- if (buffer.GiveToProcess(peer_handle(), &image_handle)) {
+ if (buffer.GiveToProcess(PeerHandle(), &image_handle)) {
image_size = png_data.size();
}
}
diff --git a/content/browser/renderer_host/database_message_filter.cc b/content/browser/renderer_host/database_message_filter.cc
index 470da3b..38cc49a 100644
--- a/content/browser/renderer_host/database_message_filter.cc
+++ b/content/browser/renderer_host/database_message_filter.cc
@@ -157,7 +157,7 @@ void DatabaseMessageFilter::OnDatabaseOpenFile(const string16& vfs_file_name,
// database tracker.
bool auto_close = !db_tracker_->HasSavedIncognitoFileHandle(vfs_file_name);
IPC::PlatformFileForTransit target_handle =
- IPC::GetFileHandleForProcess(file_handle, peer_handle(), auto_close);
+ IPC::GetFileHandleForProcess(file_handle, PeerHandle(), auto_close);
DatabaseHostMsg_OpenFile::WriteReplyParams(reply_msg, target_handle);
Send(reply_msg);
diff --git a/content/browser/renderer_host/file_utilities_message_filter.cc b/content/browser/renderer_host/file_utilities_message_filter.cc
index a2fcd80..bae1079 100644
--- a/content/browser/renderer_host/file_utilities_message_filter.cc
+++ b/content/browser/renderer_host/file_utilities_message_filter.cc
@@ -80,7 +80,7 @@ void FileUtilitiesMessageFilter::OnOpenFile(
#if defined(OS_WIN)
// Duplicate the file handle so that the renderer process can access the file.
if (!DuplicateHandle(GetCurrentProcess(), file_handle,
- peer_handle(), result, 0, false,
+ PeerHandle(), result, 0, false,
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
// file_handle is closed whether or not DuplicateHandle succeeds.
*result = INVALID_HANDLE_VALUE;
diff --git a/content/browser/renderer_host/gamepad_browser_message_filter.cc b/content/browser/renderer_host/gamepad_browser_message_filter.cc
index 71c2aab..6b5972e 100644
--- a/content/browser/renderer_host/gamepad_browser_message_filter.cc
+++ b/content/browser/renderer_host/gamepad_browser_message_filter.cc
@@ -39,7 +39,7 @@ void GamepadBrowserMessageFilter::OnGamepadStartPolling(
if (!is_started_) {
is_started_ = true;
service->AddConsumer();
- *renderer_handle = service->GetSharedMemoryHandleForProcess(peer_handle());
+ *renderer_handle = service->GetSharedMemoryHandleForProcess(PeerHandle());
} else {
// Currently we only expect the renderer to tell us once to start.
NOTREACHED();
diff --git a/content/browser/renderer_host/media/audio_input_renderer_host.cc b/content/browser/renderer_host/media/audio_input_renderer_host.cc
index 7b0416e..27c300d 100644
--- a/content/browser/renderer_host/media/audio_input_renderer_host.cc
+++ b/content/browser/renderer_host/media/audio_input_renderer_host.cc
@@ -118,7 +118,7 @@ void AudioInputRendererHost::DoCompleteCreation(
if (!entry)
return;
- if (!peer_handle()) {
+ if (!PeerHandle()) {
NOTREACHED() << "Renderer process handle is invalid.";
DeleteEntryOnError(entry);
return;
@@ -133,7 +133,7 @@ void AudioInputRendererHost::DoCompleteCreation(
// Once the audio stream is created then complete the creation process by
// mapping shared memory and sharing with the renderer process.
base::SharedMemoryHandle foreign_memory_handle;
- if (!entry->shared_memory.ShareToProcess(peer_handle(),
+ if (!entry->shared_memory.ShareToProcess(PeerHandle(),
&foreign_memory_handle)) {
// If we failed to map and share the shared memory then close the audio
// stream and send an error message.
@@ -152,7 +152,7 @@ void AudioInputRendererHost::DoCompleteCreation(
// If we failed to prepare the sync socket for the renderer then we fail
// the construction of audio input stream.
- if (!writer->PrepareForeignSocketHandle(peer_handle(),
+ if (!writer->PrepareForeignSocketHandle(PeerHandle(),
&foreign_socket_handle)) {
DeleteEntryOnError(entry);
return;
diff --git a/content/browser/renderer_host/media/audio_renderer_host.cc b/content/browser/renderer_host/media/audio_renderer_host.cc
index 0c8c310..d53fd1c 100644
--- a/content/browser/renderer_host/media/audio_renderer_host.cc
+++ b/content/browser/renderer_host/media/audio_renderer_host.cc
@@ -195,7 +195,7 @@ void AudioRendererHost::AudioEntry::OnDeviceChange(int new_buffer_size,
void AudioRendererHost::DoCompleteCreation(AudioEntry* entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (!peer_handle()) {
+ if (!PeerHandle()) {
NOTREACHED() << "Renderer process handle is invalid.";
ReportErrorAndClose(entry->stream_id());
return;
@@ -204,7 +204,7 @@ void AudioRendererHost::DoCompleteCreation(AudioEntry* entry) {
// Once the audio stream is created then complete the creation process by
// mapping shared memory and sharing with the renderer process.
base::SharedMemoryHandle foreign_memory_handle;
- if (!entry->shared_memory()->ShareToProcess(peer_handle(),
+ if (!entry->shared_memory()->ShareToProcess(PeerHandle(),
&foreign_memory_handle)) {
// If we failed to map and share the shared memory then close the audio
// stream and send an error message.
@@ -222,7 +222,7 @@ void AudioRendererHost::DoCompleteCreation(AudioEntry* entry) {
// If we failed to prepare the sync socket for the renderer then we fail
// the construction of audio stream.
- if (!reader->PrepareForeignSocketHandle(peer_handle(),
+ if (!reader->PrepareForeignSocketHandle(PeerHandle(),
&foreign_socket_handle)) {
ReportErrorAndClose(entry->stream_id());
return;
diff --git a/content/browser/renderer_host/media/peer_connection_tracker_host.cc b/content/browser/renderer_host/media/peer_connection_tracker_host.cc
index 4ba1a0a..3919be7 100644
--- a/content/browser/renderer_host/media/peer_connection_tracker_host.cc
+++ b/content/browser/renderer_host/media/peer_connection_tracker_host.cc
@@ -42,7 +42,7 @@ void PeerConnectionTrackerHost::OnAddPeerConnection(
const PeerConnectionInfo& info) {
WebRTCInternals::GetInstance()->OnAddPeerConnection(
render_process_id_,
- base::GetProcId(peer_handle()),
+ peer_pid(),
info.lid,
info.url,
info.servers,
@@ -50,14 +50,13 @@ void PeerConnectionTrackerHost::OnAddPeerConnection(
}
void PeerConnectionTrackerHost::OnRemovePeerConnection(int lid) {
- WebRTCInternals::GetInstance()->OnRemovePeerConnection(
- base::GetProcId(peer_handle()), lid);
+ WebRTCInternals::GetInstance()->OnRemovePeerConnection(peer_pid(), lid);
}
void PeerConnectionTrackerHost::OnUpdatePeerConnection(
int lid, const std::string& type, const std::string& value) {
WebRTCInternals::GetInstance()->OnUpdatePeerConnection(
- base::GetProcId(peer_handle()),
+ peer_pid(),
lid,
type,
value);
@@ -65,8 +64,7 @@ void PeerConnectionTrackerHost::OnUpdatePeerConnection(
void PeerConnectionTrackerHost::OnAddStats(int lid,
const base::ListValue& value) {
- WebRTCInternals::GetInstance()->OnAddStats(
- base::GetProcId(peer_handle()), lid, value);
+ WebRTCInternals::GetInstance()->OnAddStats(peer_pid(), lid, value);
}
} // namespace content
diff --git a/content/browser/renderer_host/media/video_capture_host.cc b/content/browser/renderer_host/media/video_capture_host.cc
index 17f56b5..91ecca0 100644
--- a/content/browser/renderer_host/media/video_capture_host.cc
+++ b/content/browser/renderer_host/media/video_capture_host.cc
@@ -232,7 +232,7 @@ void VideoCaptureHost::DoControllerAddedOnIOThread(
}
it->second->controller = controller;
- controller->StartCapture(controller_id, this, peer_handle(), params);
+ controller->StartCapture(controller_id, this, PeerHandle(), params);
}
void VideoCaptureHost::OnStopCapture(int device_id) {
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index fcb719c..f313079 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -143,7 +143,7 @@ class OpenChannelToPpapiPluginCallback
virtual void GetPpapiChannelInfo(base::ProcessHandle* renderer_handle,
int* renderer_id) OVERRIDE {
- *renderer_handle = filter()->peer_handle();
+ *renderer_handle = filter()->PeerHandle();
*renderer_id = filter()->render_process_id();
}
@@ -182,7 +182,7 @@ class OpenChannelToPpapiBrokerCallback
virtual void GetPpapiChannelInfo(base::ProcessHandle* renderer_handle,
int* renderer_id) OVERRIDE {
- *renderer_handle = filter_->peer_handle();
+ *renderer_handle = filter_->PeerHandle();
*renderer_id = filter_->render_process_id();
}
@@ -345,7 +345,7 @@ void RenderMessageFilter::OnChannelClosing() {
void RenderMessageFilter::OnChannelConnected(int32 peer_id) {
BrowserMessageFilter::OnChannelConnected(peer_id);
- base::ProcessHandle handle = peer_handle();
+ base::ProcessHandle handle = PeerHandle();
#if defined(OS_MACOSX)
process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle,
NULL));
@@ -480,7 +480,7 @@ void RenderMessageFilter::OnCreateWindow(
render_widget_helper_->CreateNewWindow(params,
no_javascript_access,
- peer_handle(),
+ PeerHandle(),
route_id,
main_frame_route_id,
surface_id,
@@ -508,10 +508,10 @@ void RenderMessageFilter::OnGetProcessMemorySizes(size_t* private_bytes,
using base::ProcessMetrics;
#if !defined(OS_MACOSX) || defined(OS_IOS)
scoped_ptr<ProcessMetrics> metrics(ProcessMetrics::CreateProcessMetrics(
- peer_handle()));
+ PeerHandle()));
#else
scoped_ptr<ProcessMetrics> metrics(ProcessMetrics::CreateProcessMetrics(
- peer_handle(), content::BrowserChildProcessHost::GetPortProvider()));
+ PeerHandle(), content::BrowserChildProcessHost::GetPortProvider()));
#endif
if (!metrics->GetMemoryBytes(private_bytes, shared_bytes)) {
*private_bytes = 0;
@@ -856,7 +856,7 @@ void RenderMessageFilter::OnAllocateSharedMemory(
uint32 buffer_size,
base::SharedMemoryHandle* handle) {
ChildProcessHostImpl::AllocateSharedMemory(
- buffer_size, peer_handle(), handle);
+ buffer_size, PeerHandle(), handle);
}
net::URLRequestContext* RenderMessageFilter::GetRequestContextForURL(
@@ -1009,7 +1009,7 @@ void RenderMessageFilter::AsyncOpenFileOnFileThread(const base::FilePath& path,
path, flags, NULL, &error_code);
IPC::PlatformFileForTransit file_for_transit =
file != base::kInvalidPlatformFileValue ?
- IPC::GetFileHandleForProcess(file, peer_handle(), true) :
+ IPC::GetFileHandleForProcess(file, PeerHandle(), true) :
IPC::InvalidPlatformFileForTransit();
IPC::Message* reply = new ViewMsg_AsyncOpenFile_ACK(
diff --git a/content/public/browser/browser_message_filter.cc b/content/public/browser/browser_message_filter.cc
index 372bf6b..e3c43a4 100644
--- a/content/public/browser/browser_message_filter.cc
+++ b/content/public/browser/browser_message_filter.cc
@@ -19,7 +19,11 @@ using content::BrowserMessageFilter;
namespace content {
BrowserMessageFilter::BrowserMessageFilter()
- : channel_(NULL), peer_handle_(base::kNullProcessHandle) {
+ : channel_(NULL),
+#if defined(OS_WIN)
+ peer_handle_(base::kNullProcessHandle),
+#endif
+ peer_pid_(base::kNullProcessId) {
}
void BrowserMessageFilter::OnFilterAdded(IPC::Channel* channel) {
@@ -31,9 +35,7 @@ void BrowserMessageFilter::OnChannelClosing() {
}
void BrowserMessageFilter::OnChannelConnected(int32 peer_pid) {
- if (!base::OpenPrivilegedProcessHandle(peer_pid, &peer_handle_)) {
- NOTREACHED();
- }
+ peer_pid_ = peer_pid;
}
bool BrowserMessageFilter::OnMessageReceived(const IPC::Message& message) {
@@ -64,6 +66,20 @@ bool BrowserMessageFilter::OnMessageReceived(const IPC::Message& message) {
return true;
}
+base::ProcessHandle BrowserMessageFilter::PeerHandle() {
+#if defined(OS_WIN)
+ base::AutoLock lock(peer_handle_lock_);
+ if (peer_handle_ == base::kNullProcessHandle)
+ base::OpenPrivilegedProcessHandle(peer_pid_, &peer_handle_);
+
+ return peer_handle_;
+#else
+ base::ProcessHandle result = base::kNullProcessHandle;
+ base::OpenPrivilegedProcessHandle(peer_pid_, &result);
+ return result;
+#endif
+}
+
bool BrowserMessageFilter::Send(IPC::Message* message) {
if (message->is_sync()) {
// We don't support sending synchronous messages from the browser. If we
@@ -125,12 +141,15 @@ bool BrowserMessageFilter::CheckCanDispatchOnUI(const IPC::Message& message,
}
void BrowserMessageFilter::BadMessageReceived() {
- base::KillProcess(peer_handle(), content::RESULT_CODE_KILLED_BAD_MESSAGE,
+ base::KillProcess(PeerHandle(), content::RESULT_CODE_KILLED_BAD_MESSAGE,
false);
}
BrowserMessageFilter::~BrowserMessageFilter() {
- base::CloseProcessHandle(peer_handle_);
+#if defined(OS_WIN)
+ if (peer_handle_ != base::kNullProcessHandle)
+ base::CloseProcessHandle(peer_handle_);
+#endif
}
bool BrowserMessageFilter::DispatchMessage(const IPC::Message& message) {
diff --git a/content/public/browser/browser_message_filter.h b/content/public/browser/browser_message_filter.h
index 6edb669..52c802a 100644
--- a/content/public/browser/browser_message_filter.h
+++ b/content/public/browser/browser_message_filter.h
@@ -10,6 +10,10 @@
#include "content/public/browser/browser_thread.h"
#include "ipc/ipc_channel_proxy.h"
+#if defined(OS_WIN)
+#include "base/synchronization/lock.h"
+#endif
+
namespace base {
class TaskRunner;
}
@@ -62,7 +66,10 @@ class CONTENT_EXPORT BrowserMessageFilter
bool* message_was_ok) = 0;
// Can be called on any thread, after OnChannelConnected is called.
- base::ProcessHandle peer_handle() { return peer_handle_; }
+ base::ProcessHandle PeerHandle();
+
+ // Can be called on any thread, after OnChannelConnected is called.
+ base::ProcessId peer_pid() const { return peer_pid_; }
// Checks that the given message can be dispatched on the UI thread, depending
// on the platform. If not, returns false and an error ot the sender.
@@ -81,7 +88,12 @@ class CONTENT_EXPORT BrowserMessageFilter
bool DispatchMessage(const IPC::Message& message);
IPC::Channel* channel_;
+ base::ProcessId peer_pid_;
+
+#if defined(OS_WIN)
+ base::Lock peer_handle_lock_;
base::ProcessHandle peer_handle_;
+#endif
};
} // namespace content