Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Unified Diff: chrome/browser/renderer_host/file_utilities_message_filter.cc

Issue 5698008: Switch a bunch of remaining filters to derive from BrowserMessageFilters so t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_host/file_utilities_message_filter.cc
===================================================================
--- chrome/browser/renderer_host/file_utilities_message_filter.cc (revision 68877)
+++ chrome/browser/renderer_host/file_utilities_message_filter.cc (working copy)
@@ -2,160 +2,89 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/renderer_host/file_utilities_dispatcher_host.h"
+#include "chrome/browser/renderer_host/file_utilities_message_filter.h"
#include "base/file_util.h"
-#include "base/platform_file.h"
#include "chrome/browser/child_process_security_policy.h"
-#include "chrome/browser/browser_thread.h"
-#include "chrome/common/render_messages.h"
-#include "chrome/common/render_messages_params.h"
+#include "chrome/common/file_utilities_messages.h"
-namespace {
-void WriteFileSize(IPC::Message* reply_msg,
- const base::PlatformFileInfo& file_info) {
- ViewHostMsg_GetFileSize::WriteReplyParams(reply_msg, file_info.size);
+FileUtilitiesMessageFilter::FileUtilitiesMessageFilter(int process_id)
+ : process_id_(process_id) {
}
-void WriteFileModificationTime(IPC::Message* reply_msg,
- const base::PlatformFileInfo& file_info) {
- ViewHostMsg_GetFileModificationTime::WriteReplyParams(
- reply_msg, file_info.last_modified);
+FileUtilitiesMessageFilter::~FileUtilitiesMessageFilter() {
}
-} // namespace
-
-FileUtilitiesDispatcherHost::FileUtilitiesDispatcherHost(
- IPC::Message::Sender* sender, int process_id)
- : message_sender_(sender),
- process_id_(process_id),
- process_handle_(0),
- shutdown_(false) {
- DCHECK(message_sender_);
+void FileUtilitiesMessageFilter::OverrideThreadForMessage(
+ const IPC::Message& message,
+ BrowserThread::ID* thread) {
+ if (IPC_MESSAGE_CLASS(message) == FileUtilitiesMsgStart)
+ *thread = BrowserThread::FILE;
}
-FileUtilitiesDispatcherHost::~FileUtilitiesDispatcherHost() {
-}
-
-void FileUtilitiesDispatcherHost::Init(base::ProcessHandle process_handle) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK(!shutdown_);
- DCHECK(!process_handle_);
- DCHECK(process_handle);
- process_handle_ = process_handle;
-}
-
-void FileUtilitiesDispatcherHost::Shutdown() {
- message_sender_ = NULL;
- shutdown_ = true;
-}
-
-bool FileUtilitiesDispatcherHost::OnMessageReceived(
- const IPC::Message& message) {
- DCHECK(!shutdown_);
+bool FileUtilitiesMessageFilter::OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) {
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(FileUtilitiesDispatcherHost, message)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileSize, OnGetFileSize)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileModificationTime,
- OnGetFileModificationTime)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_OpenFile, OnOpenFile)
- IPC_MESSAGE_UNHANDLED((handled = false))
+ IPC_BEGIN_MESSAGE_MAP_EX(FileUtilitiesMessageFilter, message, *message_was_ok)
+ IPC_MESSAGE_HANDLER(FileUtilitiesMsg_GetFileSize, OnGetFileSize)
+ IPC_MESSAGE_HANDLER(FileUtilitiesMsg_GetFileModificationTime,
+ OnGetFileModificationTime)
+ IPC_MESSAGE_HANDLER(FileUtilitiesMsg_OpenFile, OnOpenFile)
+ IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
-void FileUtilitiesDispatcherHost::OnGetFileSize(
- const FilePath& path, IPC::Message* reply_msg) {
+void FileUtilitiesMessageFilter::OnGetFileSize(const FilePath& path,
+ int64* result) {
// Get file size only when the child process has been granted permission to
// upload the file.
if (!ChildProcessSecurityPolicy::GetInstance()->CanReadFile(
process_id_, path)) {
- ViewHostMsg_GetFileSize::WriteReplyParams(
- reply_msg, static_cast<int64>(-1));
- Send(reply_msg);
+ *result = -1;
return;
}
- // Getting file size could take long time if it lives on a network share,
- // so run it on FILE thread.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this, &FileUtilitiesDispatcherHost::OnGetFileInfoOnFileThread, path,
- reply_msg, &WriteFileSize));
+ base::PlatformFileInfo file_info;
+ file_info.size = 0;
+ file_util::GetFileInfo(path, &file_info);
+ *result = file_info.size;
}
-void FileUtilitiesDispatcherHost::OnGetFileModificationTime(
- const FilePath& path, IPC::Message* reply_msg) {
+void FileUtilitiesMessageFilter::OnGetFileModificationTime(
+ const FilePath& path, base::Time* result) {
// Get file modification time only when the child process has been granted
// permission to upload the file.
if (!ChildProcessSecurityPolicy::GetInstance()->CanReadFile(
process_id_, path)) {
- ViewHostMsg_GetFileModificationTime::WriteReplyParams(reply_msg,
- base::Time());
- Send(reply_msg);
+ *result = base::Time();
return;
}
- // Getting file modification time could take a long time if it lives on a
- // network share, so run it on the FILE thread.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this, &FileUtilitiesDispatcherHost::OnGetFileInfoOnFileThread,
- path, reply_msg, &WriteFileModificationTime));
-}
-
-void FileUtilitiesDispatcherHost::OnGetFileInfoOnFileThread(
- const FilePath& path,
- IPC::Message* reply_msg,
- FileInfoWriteFunc write_func) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-
base::PlatformFileInfo file_info;
file_info.size = 0;
file_util::GetFileInfo(path, &file_info);
-
- (*write_func)(reply_msg, file_info);
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &FileUtilitiesDispatcherHost::Send, reply_msg));
+ *result = file_info.last_modified;
}
-void FileUtilitiesDispatcherHost::OnOpenFile(
- const FilePath& path, int mode, IPC::Message* reply_msg) {
+void FileUtilitiesMessageFilter::OnOpenFile(
+ const FilePath& path,
+ int mode,
+ IPC::PlatformFileForTransit* result) {
// Open the file only when the child process has been granted permission to
// upload the file.
// TODO(jianli): Do we need separate permission to control opening the file?
if (!ChildProcessSecurityPolicy::GetInstance()->CanReadFile(
- process_id_, path)) {
- ViewHostMsg_OpenFile::WriteReplyParams(
- reply_msg,
+ process_id_, path)) {
#if defined(OS_WIN)
- base::kInvalidPlatformFileValue
+ *result = base::kInvalidPlatformFileValue;
#elif defined(OS_POSIX)
- base::FileDescriptor(base::kInvalidPlatformFileValue, true)
+ *result = base::FileDescriptor(base::kInvalidPlatformFileValue, true);
#endif
- );
- Send(reply_msg);
return;
}
- // Opening the file could take a long time if it lives on a network share,
- // so run it on the FILE thread.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this, &FileUtilitiesDispatcherHost::OnOpenFileOnFileThread,
- path, mode, reply_msg));
-}
-
-void FileUtilitiesDispatcherHost::OnOpenFileOnFileThread(
- const FilePath& path, int mode, IPC::Message* reply_msg) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-
base::PlatformFile file_handle = base::CreatePlatformFile(
path,
(mode == 0) ? (base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ)
@@ -163,37 +92,15 @@
base::PLATFORM_FILE_WRITE),
NULL, NULL);
- base::PlatformFile target_file_handle;
#if defined(OS_WIN)
// Duplicate the file handle so that the renderer process can access the file.
if (!DuplicateHandle(GetCurrentProcess(), file_handle,
- process_handle_, &target_file_handle, 0, false,
+ peer_handle(), result, 0, false,
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
// file_handle is closed whether or not DuplicateHandle succeeds.
- target_file_handle = INVALID_HANDLE_VALUE;
+ *result = INVALID_HANDLE_VALUE;
}
#else
- target_file_handle = file_handle;
+ *result = base::FileDescriptor(file_handle, true);
#endif
-
- ViewHostMsg_OpenFile::WriteReplyParams(
- reply_msg,
-#if defined(OS_WIN)
- target_file_handle
-#elif defined(OS_POSIX)
- base::FileDescriptor(target_file_handle, true)
-#endif
- );
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &FileUtilitiesDispatcherHost::Send, reply_msg));
}
-
-void FileUtilitiesDispatcherHost::Send(IPC::Message* message) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (!shutdown_ && message_sender_)
- message_sender_->Send(message);
- else
- delete message;
-}
« no previous file with comments | « chrome/browser/renderer_host/file_utilities_message_filter.h ('k') | chrome/browser/renderer_host/resource_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698