summaryrefslogtreecommitdiffstats
path: root/chrome/browser/in_process_webkit
diff options
context:
space:
mode:
authorjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-27 14:41:27 +0000
committerjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-27 14:41:27 +0000
commit4b66898e0f7fc5864af489676cea60a9bf3e6e7f (patch)
tree40a8a7d439c9126f1bcfaefbd27ef6593f5ffb84 /chrome/browser/in_process_webkit
parent476c6d05c1abc015ff3b479f8f2132a0fc604b9e (diff)
downloadchromium_src-4b66898e0f7fc5864af489676cea60a9bf3e6e7f.zip
chromium_src-4b66898e0f7fc5864af489676cea60a9bf3e6e7f.tar.gz
chromium_src-4b66898e0f7fc5864af489676cea60a9bf3e6e7f.tar.bz2
Handle IDBDatabase sync calls.
Remove modify_database flag. Make sure we delete data structures on the WebKit thread. Handle single process mode. Review URL: http://codereview.chromium.org/2125017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48387 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/in_process_webkit')
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc121
-rw-r--r--chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h18
-rw-r--r--chrome/browser/in_process_webkit/webkit_context.cc6
3 files changed, 133 insertions, 12 deletions
diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
index 2e32dfb..e478219 100644
--- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
+++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc
@@ -4,24 +4,30 @@
#include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h"
+#include "base/command_line.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/in_process_webkit/indexed_db_callbacks.h"
+#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/render_messages.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDOMStringList.h"
using WebKit::WebIDBDatabase;
using WebKit::WebIDBDatabaseError;
using WebKit::WebSecurityOrigin;
+using WebKit::WebDOMStringList;
IndexedDBDispatcherHost::IndexedDBDispatcherHost(
IPC::Message::Sender* sender, WebKitContext* webkit_context)
: sender_(sender),
webkit_context_(webkit_context),
+ idb_database_map_(new IDMap<WebKit::WebIDBDatabase, IDMapOwnPointer>()),
process_handle_(0) {
DCHECK(sender_);
DCHECK(webkit_context_.get());
@@ -47,14 +53,15 @@ void IndexedDBDispatcherHost::Shutdown() {
bool success = ChromeThread::PostTask(
ChromeThread::WEBKIT, FROM_HERE,
NewRunnableMethod(this, &IndexedDBDispatcherHost::Shutdown));
- DCHECK(success); // The WebKit thread is always shutdown after the IO.
- return;
+ if (success)
+ return;
}
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT) ||
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess));
DCHECK(!sender_);
- // TODO(jorlow): Do we still need this?
+ idb_database_map_.reset();
}
bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message,
@@ -65,6 +72,14 @@ bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message,
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *msg_is_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_IndexedDatabaseOpen, OnIndexedDatabaseOpen)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseName,
+ OnIDBDatabaseName)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseDescription,
+ OnIDBDatabaseDescription)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseVersion,
+ OnIDBDatabaseVersion)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseObjectStores,
+ OnIDBDatabaseObjectStores)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseDestroyed,
OnIDBDatabaseDestroyed)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -95,7 +110,7 @@ void IndexedDBDispatcherHost::Send(IPC::Message* message) {
}
int32 IndexedDBDispatcherHost::AddIDBDatabase(WebIDBDatabase* idb_database) {
- return idb_database_map_.Add(idb_database);
+ return idb_database_map_->Add(idb_database);
}
class IndexedDatabaseOpenCallbacks : public IndexedDBCallbacks {
@@ -131,7 +146,7 @@ void IndexedDBDispatcherHost::OnIndexedDatabaseOpen(
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
int exception_code = 0;
Context()->GetIndexedDatabase()->open(
- params.name_, params.description_, params.modify_database_,
+ params.name_, params.description_,
new IndexedDatabaseOpenCallbacks(this, params.response_id_),
WebSecurityOrigin::createFromDatabaseIdentifier(params.origin_), NULL,
exception_code);
@@ -140,6 +155,86 @@ void IndexedDBDispatcherHost::OnIndexedDatabaseOpen(
DCHECK(exception_code == 0);
}
+void IndexedDBDispatcherHost::OnIDBDatabaseName(
+ int32 idb_database_id, IPC::Message* reply_msg) {
+ if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &IndexedDBDispatcherHost::OnIDBDatabaseName,
+ idb_database_id, reply_msg));
+ return;
+ }
+
+ WebIDBDatabase* idb_database = GetDatabaseOrTerminateProcess(
+ idb_database_id, reply_msg);
+ if (!idb_database)
+ return;
+
+ const string16& name = idb_database->name();
+ ViewHostMsg_IDBDatabaseName::WriteReplyParams(reply_msg, name);
+ Send(reply_msg);
+}
+
+void IndexedDBDispatcherHost::OnIDBDatabaseDescription(
+ int32 idb_database_id, IPC::Message* reply_msg) {
+ if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &IndexedDBDispatcherHost::OnIDBDatabaseDescription,
+ idb_database_id, reply_msg));
+ return;
+ }
+
+ WebIDBDatabase* idb_database = GetDatabaseOrTerminateProcess(
+ idb_database_id, reply_msg);
+ if (!idb_database)
+ return;
+
+ const string16& description = idb_database->description();
+ ViewHostMsg_IDBDatabaseDescription::WriteReplyParams(reply_msg, description);
+ Send(reply_msg);
+}
+
+void IndexedDBDispatcherHost::OnIDBDatabaseVersion(
+ int32 idb_database_id, IPC::Message* reply_msg) {
+ if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &IndexedDBDispatcherHost::OnIDBDatabaseVersion,
+ idb_database_id, reply_msg));
+ return;
+ }
+
+ WebIDBDatabase* idb_database = GetDatabaseOrTerminateProcess(
+ idb_database_id, reply_msg);
+ if (!idb_database)
+ return;
+
+ const string16& version = idb_database->version();
+ ViewHostMsg_IDBDatabaseVersion::WriteReplyParams(reply_msg, version);
+ Send(reply_msg);
+}
+
+void IndexedDBDispatcherHost::OnIDBDatabaseObjectStores(
+ int32 idb_database_id, IPC::Message* reply_msg) {
+ if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
+ this, &IndexedDBDispatcherHost::OnIDBDatabaseObjectStores,
+ idb_database_id, reply_msg));
+ return;
+ }
+
+ WebIDBDatabase* idb_database = GetDatabaseOrTerminateProcess(
+ idb_database_id, reply_msg);
+ if (!idb_database)
+ return;
+
+ WebDOMStringList web_object_stores = idb_database->objectStores();
+ std::vector<string16> object_stores;
+ for (unsigned i = 0; i < web_object_stores.length(); ++i)
+ object_stores[i] = web_object_stores.item(i);
+ ViewHostMsg_IDBDatabaseObjectStores::WriteReplyParams(reply_msg,
+ object_stores);
+ Send(reply_msg);
+}
+
void IndexedDBDispatcherHost::OnIDBDatabaseDestroyed(int32 idb_database_id) {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
@@ -149,5 +244,17 @@ void IndexedDBDispatcherHost::OnIDBDatabaseDestroyed(int32 idb_database_id) {
}
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
- idb_database_map_.Remove(idb_database_id);
+ idb_database_map_->Remove(idb_database_id);
+}
+
+WebIDBDatabase* IndexedDBDispatcherHost::GetDatabaseOrTerminateProcess(
+ int32 idb_database_id, IPC::Message* reply_msg) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+ WebIDBDatabase* idb_database = idb_database_map_->Lookup(idb_database_id);
+ if (!idb_database) {
+ BrowserRenderProcessHost::BadMessageTerminateProcess(
+ ViewHostMsg_DOMStorageGetItem::ID, process_handle_);
+ delete reply_msg;
+ }
+ return idb_database;
}
diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
index 2a70748..68e8141 100644
--- a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
+++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h
@@ -1,6 +1,6 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_
#define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_
@@ -58,6 +58,14 @@ class IndexedDBDispatcherHost
void OnIndexedDatabaseOpen(
const ViewHostMsg_IndexedDatabaseOpen_Params& params);
void OnIDBDatabaseDestroyed(int32 idb_database_id);
+ void OnIDBDatabaseName(int32 idb_database_id, IPC::Message* reply_msg);
+ void OnIDBDatabaseDescription(int32 idb_database_id, IPC::Message* reply_msg);
+ void OnIDBDatabaseVersion(int32 idb_database_id, IPC::Message* reply_msg);
+ void OnIDBDatabaseObjectStores(int32 idb_database_id,
+ IPC::Message* reply_msg);
+
+ WebKit::WebIDBDatabase* GetDatabaseOrTerminateProcess(
+ int32 idb_database_id, IPC::Message* reply_msg);
// Only use on the IO thread.
IPC::Message::Sender* sender_;
@@ -67,8 +75,8 @@ class IndexedDBDispatcherHost
// Maps from IDs we pass to the renderer and the actual WebKit objects.
// The map takes ownership and returns an ID. That ID is passed to the
- // renderer and used to reference it.
- IDMap<WebKit::WebIDBDatabase, IDMapOwnPointer>
+ // renderer and used to reference it. All access must be on WebKit thread.
+ scoped_ptr<IDMap<WebKit::WebIDBDatabase, IDMapOwnPointer> >
idb_database_map_;
// TODO(andreip/jorlow): Add other maps here.
diff --git a/chrome/browser/in_process_webkit/webkit_context.cc b/chrome/browser/in_process_webkit/webkit_context.cc
index b9cf36f..a5db03f 100644
--- a/chrome/browser/in_process_webkit/webkit_context.cc
+++ b/chrome/browser/in_process_webkit/webkit_context.cc
@@ -26,6 +26,12 @@ WebKitContext::~WebKitContext() {
// freeing the DOMStorageContext, so delete it manually.
delete dom_storage_context;
}
+
+ IndexedDBContext* indexed_db_context = indexed_db_context_.release();
+ if (!ChromeThread::DeleteSoon(
+ ChromeThread::WEBKIT, FROM_HERE, indexed_db_context)) {
+ delete indexed_db_context;
+ }
}
void WebKitContext::PurgeMemory() {