| Index: chrome/browser/renderer_host/database_message_filter.cc
|
| ===================================================================
|
| --- chrome/browser/renderer_host/database_message_filter.cc (revision 68877)
|
| +++ chrome/browser/renderer_host/database_message_filter.cc (working copy)
|
| @@ -2,17 +2,15 @@
|
| // 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/database_dispatcher_host.h"
|
| +#include "chrome/browser/renderer_host/database_message_filter.h"
|
|
|
| #include <string>
|
|
|
| #include "base/string_util.h"
|
| #include "base/thread.h"
|
| -#include "chrome/browser/browser_thread.h"
|
| #include "chrome/browser/content_settings/host_content_settings_map.h"
|
| #include "chrome/browser/net/chrome_url_request_context.h"
|
| -#include "chrome/browser/renderer_host/browser_render_process_host.h"
|
| -#include "chrome/common/render_messages.h"
|
| +#include "chrome/common/database_messages.h"
|
| #include "googleurl/src/gurl.h"
|
| #include "third_party/sqlite/sqlite3.h"
|
| #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
|
| @@ -31,45 +29,31 @@
|
| const int kNumDeleteRetries = 2;
|
| const int kDelayDeleteRetryMs = 100;
|
|
|
| -DatabaseDispatcherHost::DatabaseDispatcherHost(
|
| - DatabaseTracker* db_tracker,
|
| - IPC::Message::Sender* sender,
|
| +DatabaseMessageFilter::DatabaseMessageFilter(
|
| + webkit_database::DatabaseTracker* db_tracker,
|
| HostContentSettingsMap *host_content_settings_map)
|
| : db_tracker_(db_tracker),
|
| - message_sender_(sender),
|
| - process_handle_(0),
|
| observer_added_(false),
|
| - shutdown_(false),
|
| host_content_settings_map_(host_content_settings_map) {
|
| DCHECK(db_tracker_);
|
| - DCHECK(message_sender_);
|
| }
|
|
|
| -void DatabaseDispatcherHost::Init(base::ProcessHandle process_handle) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - DCHECK(!shutdown_);
|
| - DCHECK(!process_handle_);
|
| - DCHECK(process_handle);
|
| - process_handle_ = process_handle;
|
| -}
|
| -
|
| -void DatabaseDispatcherHost::Shutdown() {
|
| - shutdown_ = true;
|
| - message_sender_ = NULL;
|
| +void DatabaseMessageFilter::OnChannelClosing() {
|
| + BrowserMessageFilter::OnChannelClosing();
|
| if (observer_added_) {
|
| observer_added_ = false;
|
| BrowserThread::PostTask(
|
| BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this, &DatabaseDispatcherHost::RemoveObserver));
|
| + NewRunnableMethod(this, &DatabaseMessageFilter::RemoveObserver));
|
| }
|
| }
|
|
|
| -void DatabaseDispatcherHost::AddObserver() {
|
| +void DatabaseMessageFilter::AddObserver() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| db_tracker_->AddObserver(this);
|
| }
|
|
|
| -void DatabaseDispatcherHost::RemoveObserver() {
|
| +void DatabaseMessageFilter::RemoveObserver() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
|
|
| // If the renderer process died without closing all databases,
|
| @@ -80,79 +64,50 @@
|
| db_tracker_->RemoveObserver(this);
|
| }
|
|
|
| -bool DatabaseDispatcherHost::OnMessageReceived(
|
| - const IPC::Message& message, bool* message_was_ok) {
|
| - DCHECK(!shutdown_);
|
| - *message_was_ok = true;
|
| +void DatabaseMessageFilter::OverrideThreadForMessage(
|
| + const IPC::Message& message,
|
| + BrowserThread::ID* thread) {
|
| + if (IPC_MESSAGE_CLASS(message) == DatabaseMsgStart &&
|
| + message.type() != DatabaseHostMsg_Allow::ID) {
|
| + *thread = BrowserThread::FILE;
|
| + }
|
| +
|
| + if (message.type() == DatabaseHostMsg_OpenFile::ID && !observer_added_) {
|
| + observer_added_ = true;
|
| + BrowserThread::PostTask(
|
| + BrowserThread::FILE, FROM_HERE,
|
| + NewRunnableMethod(this, &DatabaseMessageFilter::AddObserver));
|
| + }
|
| +}
|
| +
|
| +bool DatabaseMessageFilter::OnMessageReceived(
|
| + const IPC::Message& message,
|
| + bool* message_was_ok) {
|
| bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP_EX(DatabaseDispatcherHost, message, *message_was_ok)
|
| - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DatabaseOpenFile,
|
| + IPC_BEGIN_MESSAGE_MAP_EX(DatabaseMessageFilter, message, *message_was_ok)
|
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_OpenFile,
|
| OnDatabaseOpenFile)
|
| - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DatabaseDeleteFile,
|
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_DeleteFile,
|
| OnDatabaseDeleteFile)
|
| - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DatabaseGetFileAttributes,
|
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_GetFileAttributes,
|
| OnDatabaseGetFileAttributes)
|
| - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DatabaseGetFileSize,
|
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_GetFileSize,
|
| OnDatabaseGetFileSize)
|
| - IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseOpened, OnDatabaseOpened)
|
| - IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseModified, OnDatabaseModified)
|
| - IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseClosed, OnDatabaseClosed)
|
| - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_AllowDatabase, OnAllowDatabase)
|
| + IPC_MESSAGE_HANDLER(DatabaseHostMsg_Opened, OnDatabaseOpened)
|
| + IPC_MESSAGE_HANDLER(DatabaseHostMsg_Modified, OnDatabaseModified)
|
| + IPC_MESSAGE_HANDLER(DatabaseHostMsg_Closed, OnDatabaseClosed)
|
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_Allow, OnAllowDatabase)
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| IPC_END_MESSAGE_MAP_EX()
|
| return handled;
|
| }
|
|
|
| -void DatabaseDispatcherHost::ReceivedBadMessage(uint32 msg_type) {
|
| - BrowserRenderProcessHost::BadMessageTerminateProcess(
|
| - msg_type, process_handle_);
|
| +DatabaseMessageFilter::~DatabaseMessageFilter() {
|
| }
|
|
|
| -void DatabaseDispatcherHost::Send(IPC::Message* message) {
|
| - if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
|
| - if (!BrowserThread::PostTask(
|
| - BrowserThread::IO, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &DatabaseDispatcherHost::Send,
|
| - message)))
|
| - delete message;
|
| - return;
|
| - }
|
| -
|
| - if (!shutdown_ && message_sender_)
|
| - message_sender_->Send(message);
|
| - else
|
| - delete message;
|
| -}
|
| -
|
| -DatabaseDispatcherHost::~DatabaseDispatcherHost() {}
|
| -
|
| -void DatabaseDispatcherHost::OnDatabaseOpenFile(const string16& vfs_file_name,
|
| - int desired_flags,
|
| - IPC::Message* reply_msg) {
|
| - if (!observer_added_) {
|
| - observer_added_ = true;
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this, &DatabaseDispatcherHost::AddObserver));
|
| - }
|
| -
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &DatabaseDispatcherHost::DatabaseOpenFile,
|
| - vfs_file_name,
|
| - desired_flags,
|
| - reply_msg));
|
| -}
|
| -
|
| -// Scheduled by the IO thread on the file thread.
|
| -// Opens the given database file, then schedules
|
| -// a task on the IO thread's message loop to send an IPC back to
|
| -// corresponding renderer process with the file handle.
|
| -void DatabaseDispatcherHost::DatabaseOpenFile(const string16& vfs_file_name,
|
| - int desired_flags,
|
| - IPC::Message* reply_msg) {
|
| +void DatabaseMessageFilter::OnDatabaseOpenFile(const string16& vfs_file_name,
|
| + int desired_flags,
|
| + IPC::Message* reply_msg) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
|
| base::PlatformFile target_handle = base::kInvalidPlatformFileValue;
|
| @@ -194,10 +149,10 @@
|
| // process. The original handle is closed, unless we saved it in the
|
| // database tracker.
|
| bool auto_close = !db_tracker_->HasSavedIncognitoFileHandle(vfs_file_name);
|
| - VfsBackend::GetFileHandleForProcess(process_handle_, file_handle,
|
| + VfsBackend::GetFileHandleForProcess(peer_handle(), file_handle,
|
| &target_handle, auto_close);
|
|
|
| - ViewHostMsg_DatabaseOpenFile::WriteReplyParams(
|
| + DatabaseHostMsg_OpenFile::WriteReplyParams(
|
| reply_msg,
|
| #if defined(OS_WIN)
|
| target_handle
|
| @@ -208,27 +163,16 @@
|
| Send(reply_msg);
|
| }
|
|
|
| -void DatabaseDispatcherHost::OnDatabaseDeleteFile(const string16& vfs_file_name,
|
| - const bool& sync_dir,
|
| - IPC::Message* reply_msg) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &DatabaseDispatcherHost::DatabaseDeleteFile,
|
| - vfs_file_name,
|
| - sync_dir,
|
| - reply_msg,
|
| - kNumDeleteRetries));
|
| +void DatabaseMessageFilter::OnDatabaseDeleteFile(const string16& vfs_file_name,
|
| + const bool& sync_dir,
|
| + IPC::Message* reply_msg) {
|
| + DatabaseDeleteFile(vfs_file_name, sync_dir, reply_msg, kNumDeleteRetries);
|
| }
|
|
|
| -// Scheduled by the IO thread on the file thread.
|
| -// Deletes the given database file, then schedules
|
| -// a task on the IO thread's message loop to send an IPC back to
|
| -// corresponding renderer process with the error code.
|
| -void DatabaseDispatcherHost::DatabaseDeleteFile(const string16& vfs_file_name,
|
| - bool sync_dir,
|
| - IPC::Message* reply_msg,
|
| - int reschedule_count) {
|
| +void DatabaseMessageFilter::DatabaseDeleteFile(const string16& vfs_file_name,
|
| + bool sync_dir,
|
| + IPC::Message* reply_msg,
|
| + int reschedule_count) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
|
|
| // Return an error if the file name is invalid or if the file could not
|
| @@ -251,7 +195,7 @@
|
| BrowserThread::PostDelayedTask(
|
| BrowserThread::FILE, FROM_HERE,
|
| NewRunnableMethod(this,
|
| - &DatabaseDispatcherHost::DatabaseDeleteFile,
|
| + &DatabaseMessageFilter::DatabaseDeleteFile,
|
| vfs_file_name,
|
| sync_dir,
|
| reply_msg,
|
| @@ -261,28 +205,13 @@
|
| }
|
| }
|
|
|
| - ViewHostMsg_DatabaseDeleteFile::WriteReplyParams(reply_msg, error_code);
|
| + DatabaseHostMsg_DeleteFile::WriteReplyParams(reply_msg, error_code);
|
| Send(reply_msg);
|
| }
|
|
|
| -void DatabaseDispatcherHost::OnDatabaseGetFileAttributes(
|
| +void DatabaseMessageFilter::OnDatabaseGetFileAttributes(
|
| const string16& vfs_file_name,
|
| IPC::Message* reply_msg) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &DatabaseDispatcherHost::DatabaseGetFileAttributes,
|
| - vfs_file_name,
|
| - reply_msg));
|
| -}
|
| -
|
| -// Scheduled by the IO thread on the file thread.
|
| -// Gets the attributes of the given database file, then schedules
|
| -// a task on the IO thread's message loop to send an IPC back to
|
| -// corresponding renderer process.
|
| -void DatabaseDispatcherHost::DatabaseGetFileAttributes(
|
| - const string16& vfs_file_name,
|
| - IPC::Message* reply_msg) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| int32 attributes = -1;
|
| FilePath db_file =
|
| @@ -290,27 +219,13 @@
|
| if (!db_file.empty())
|
| attributes = VfsBackend::GetFileAttributes(db_file);
|
|
|
| - ViewHostMsg_DatabaseGetFileAttributes::WriteReplyParams(
|
| + DatabaseHostMsg_GetFileAttributes::WriteReplyParams(
|
| reply_msg, attributes);
|
| Send(reply_msg);
|
| }
|
|
|
| -void DatabaseDispatcherHost::OnDatabaseGetFileSize(
|
| +void DatabaseMessageFilter::OnDatabaseGetFileSize(
|
| const string16& vfs_file_name, IPC::Message* reply_msg) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &DatabaseDispatcherHost::DatabaseGetFileSize,
|
| - vfs_file_name,
|
| - reply_msg));
|
| -}
|
| -
|
| -// Scheduled by the IO thread on the file thread.
|
| -// Gets the size of the given file, then schedules a task
|
| -// on the IO thread's message loop to send an IPC back to
|
| -// the corresponding renderer process.
|
| -void DatabaseDispatcherHost::DatabaseGetFileSize(const string16& vfs_file_name,
|
| - IPC::Message* reply_msg) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| int64 size = 0;
|
| FilePath db_file =
|
| @@ -318,76 +233,55 @@
|
| if (!db_file.empty())
|
| size = VfsBackend::GetFileSize(db_file);
|
|
|
| - ViewHostMsg_DatabaseGetFileSize::WriteReplyParams(reply_msg, size);
|
| + DatabaseHostMsg_GetFileSize::WriteReplyParams(reply_msg, size);
|
| Send(reply_msg);
|
| }
|
|
|
| -void DatabaseDispatcherHost::OnDatabaseOpened(const string16& origin_identifier,
|
| - const string16& database_name,
|
| - const string16& description,
|
| - int64 estimated_size) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &DatabaseDispatcherHost::DatabaseOpened,
|
| - origin_identifier,
|
| - database_name,
|
| - description,
|
| - estimated_size));
|
| -}
|
| -
|
| -void DatabaseDispatcherHost::DatabaseOpened(const string16& origin_identifier,
|
| - const string16& database_name,
|
| - const string16& description,
|
| - int64 estimated_size) {
|
| +void DatabaseMessageFilter::OnDatabaseOpened(const string16& origin_identifier,
|
| + const string16& database_name,
|
| + const string16& description,
|
| + int64 estimated_size) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| int64 database_size = 0;
|
| int64 space_available = 0;
|
| database_connections_.AddConnection(origin_identifier, database_name);
|
| db_tracker_->DatabaseOpened(origin_identifier, database_name, description,
|
| estimated_size, &database_size, &space_available);
|
| - Send(new ViewMsg_DatabaseUpdateSize(origin_identifier, database_name,
|
| - database_size, space_available));
|
| + Send(new DatabaseMsg_UpdateSize(origin_identifier, database_name,
|
| + database_size, space_available));
|
| }
|
|
|
| -void DatabaseDispatcherHost::OnDatabaseModified(
|
| +void DatabaseMessageFilter::OnDatabaseModified(
|
| const string16& origin_identifier,
|
| const string16& database_name) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &DatabaseDispatcherHost::DatabaseModified,
|
| - origin_identifier,
|
| - database_name));
|
| -}
|
| -
|
| -void DatabaseDispatcherHost::DatabaseModified(const string16& origin_identifier,
|
| - const string16& database_name) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| if (!database_connections_.IsDatabaseOpened(
|
| origin_identifier, database_name)) {
|
| - ReceivedBadMessage(ViewHostMsg_DatabaseModified::ID);
|
| + BadMessageReceived(DatabaseHostMsg_Modified::ID);
|
| return;
|
| }
|
|
|
| db_tracker_->DatabaseModified(origin_identifier, database_name);
|
| }
|
|
|
| -void DatabaseDispatcherHost::OnDatabaseClosed(const string16& origin_identifier,
|
| - const string16& database_name) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - NewRunnableMethod(this,
|
| - &DatabaseDispatcherHost::DatabaseClosed,
|
| - origin_identifier,
|
| - database_name));
|
| +void DatabaseMessageFilter::OnDatabaseClosed(const string16& origin_identifier,
|
| + const string16& database_name) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| + if (!database_connections_.IsDatabaseOpened(
|
| + origin_identifier, database_name)) {
|
| + BadMessageReceived(DatabaseHostMsg_Closed::ID);
|
| + return;
|
| + }
|
| +
|
| + db_tracker_->DatabaseClosed(origin_identifier, database_name);
|
| + database_connections_.RemoveConnection(origin_identifier, database_name);
|
| }
|
|
|
| -void DatabaseDispatcherHost::OnAllowDatabase(const std::string& origin_url,
|
| - const string16& name,
|
| - const string16& display_name,
|
| - unsigned long estimated_size,
|
| - IPC::Message* reply_msg) {
|
| +void DatabaseMessageFilter::OnAllowDatabase(const std::string& origin_url,
|
| + const string16& name,
|
| + const string16& display_name,
|
| + unsigned long estimated_size,
|
| + IPC::Message* reply_msg) {
|
| GURL url = GURL(origin_url);
|
| ContentSetting content_setting =
|
| host_content_settings_map_->GetContentSetting(
|
| @@ -395,44 +289,31 @@
|
| AllowDatabaseResponse(reply_msg, content_setting);
|
| }
|
|
|
| -void DatabaseDispatcherHost::AllowDatabaseResponse(
|
| +void DatabaseMessageFilter::AllowDatabaseResponse(
|
| IPC::Message* reply_msg, ContentSetting content_setting) {
|
| DCHECK((content_setting == CONTENT_SETTING_ALLOW) ||
|
| (content_setting == CONTENT_SETTING_BLOCK) ||
|
| (content_setting == CONTENT_SETTING_SESSION_ONLY));
|
| - ViewHostMsg_AllowDatabase::WriteReplyParams(
|
| + DatabaseHostMsg_Allow::WriteReplyParams(
|
| reply_msg, content_setting != CONTENT_SETTING_BLOCK);
|
| Send(reply_msg);
|
| }
|
|
|
| -void DatabaseDispatcherHost::DatabaseClosed(const string16& origin_identifier,
|
| - const string16& database_name) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| - if (!database_connections_.IsDatabaseOpened(
|
| - origin_identifier, database_name)) {
|
| - ReceivedBadMessage(ViewHostMsg_DatabaseClosed::ID);
|
| - return;
|
| - }
|
| -
|
| - db_tracker_->DatabaseClosed(origin_identifier, database_name);
|
| - database_connections_.RemoveConnection(origin_identifier, database_name);
|
| -}
|
| -
|
| -void DatabaseDispatcherHost::OnDatabaseSizeChanged(
|
| +void DatabaseMessageFilter::OnDatabaseSizeChanged(
|
| const string16& origin_identifier,
|
| const string16& database_name,
|
| int64 database_size,
|
| int64 space_available) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| if (database_connections_.IsOriginUsed(origin_identifier)) {
|
| - Send(new ViewMsg_DatabaseUpdateSize(origin_identifier, database_name,
|
| - database_size, space_available));
|
| + Send(new DatabaseMsg_UpdateSize(origin_identifier, database_name,
|
| + database_size, space_available));
|
| }
|
| }
|
|
|
| -void DatabaseDispatcherHost::OnDatabaseScheduledForDeletion(
|
| +void DatabaseMessageFilter::OnDatabaseScheduledForDeletion(
|
| const string16& origin_identifier,
|
| const string16& database_name) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| - Send(new ViewMsg_DatabaseCloseImmediately(origin_identifier, database_name));
|
| + Send(new DatabaseMsg_CloseImmediately(origin_identifier, database_name));
|
| }
|
|
|