From 70c19a930beddde0e382777cb8799e7c8ebb1625 Mon Sep 17 00:00:00 2001 From: "jorlow@chromium.org" Date: Fri, 14 May 2010 12:59:11 +0000 Subject: Implement IndexedDatabase::open up until re-entrance into WebKit. That (and the rest of IndexedDB) will be done in subsequent patches. Included in this patch is a lot of other infrastructure for making IndexedDB work. Included is a conversion from the DOMStorageDispatcherHost into a dispatcher host for all APIs that have a backend in WebKit. I named it WebKitAPIDispatcherHost. Since it's in browser/in_process_webkit and it is for APIs that connect up to the WebKit API and it's used for APIs whose backend is implemented in WebKit I thought the name was decent and not _too_ confusing, but if you have better ideas, please let me know. This includes some code that you've already reviewed (darin), but a lot has changed so please take a look at all of it. TEST=Not much to test yet + behind a flag. BUG=none Review URL: http://codereview.chromium.org/1599009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47268 0039d316-1c4b-4281-b951-d872f2087c98 --- .../dom_storage_dispatcher_host.cc | 57 +++----- .../dom_storage_dispatcher_host.h | 8 +- .../in_process_webkit/indexed_db_callbacks.cc | 29 ++++ .../in_process_webkit/indexed_db_callbacks.h | 37 +++++ .../in_process_webkit/indexed_db_context.cc | 24 ++++ .../browser/in_process_webkit/indexed_db_context.h | 31 +++++ .../indexed_db_dispatcher_host.cc | 150 +++++++++++++++++++++ .../in_process_webkit/indexed_db_dispatcher_host.h | 85 ++++++++++++ chrome/browser/in_process_webkit/webkit_context.cc | 10 +- chrome/browser/in_process_webkit/webkit_context.h | 12 +- .../in_process_webkit/webkit_context_unittest.cc | 21 +-- 11 files changed, 408 insertions(+), 56 deletions(-) create mode 100644 chrome/browser/in_process_webkit/indexed_db_callbacks.cc create mode 100644 chrome/browser/in_process_webkit/indexed_db_callbacks.h create mode 100644 chrome/browser/in_process_webkit/indexed_db_context.cc create mode 100644 chrome/browser/in_process_webkit/indexed_db_context.h create mode 100644 chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc create mode 100644 chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h (limited to 'chrome/browser/in_process_webkit') diff --git a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc index bb28bff..965623e 100644 --- a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc +++ b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc @@ -9,7 +9,6 @@ #include "chrome/browser/in_process_webkit/dom_storage_area.h" #include "chrome/browser/in_process_webkit/dom_storage_context.h" #include "chrome/browser/in_process_webkit/dom_storage_namespace.h" -#include "chrome/browser/in_process_webkit/webkit_thread.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/renderer_host/browser_render_process_host.h" #include "chrome/browser/renderer_host/render_view_host_notification_task.h" @@ -45,14 +44,11 @@ ScopedStorageEventContext::~ScopedStorageEventContext() { DOMStorageDispatcherHost::DOMStorageDispatcherHost( ResourceMessageFilter* resource_message_filter, - WebKitContext* webkit_context, - WebKitThread* webkit_thread) + WebKitContext* webkit_context) : webkit_context_(webkit_context), - webkit_thread_(webkit_thread), resource_message_filter_(resource_message_filter), process_handle_(0) { DCHECK(webkit_context_.get()); - DCHECK(webkit_thread_); DCHECK(resource_message_filter_); } @@ -71,24 +67,11 @@ void DOMStorageDispatcherHost::Init(int process_id, } void DOMStorageDispatcherHost::Shutdown() { - if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { - if (process_handle_) // Init() was called - Context()->UnregisterDispatcherHost(this); - resource_message_filter_ = NULL; - - // The task will only execute if the WebKit thread is already running. - ChromeThread::PostTask( - ChromeThread::WEBKIT, FROM_HERE, - NewRunnableMethod(this, &DOMStorageDispatcherHost::Shutdown)); - return; - } - - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); - DCHECK(!resource_message_filter_); - - // TODO(jorlow): Do stuff that needs to be run on the WebKit thread. Locks - // and others will likely need this, so let's not delete this - // code even though it doesn't do anyting yet. + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + // This is not always true during testing. + if (process_handle_) + Context()->UnregisterDispatcherHost(this); + resource_message_filter_ = NULL; } /* static */ @@ -114,7 +97,7 @@ void DOMStorageDispatcherHost::DispatchStorageEvent(const NullableString16& key, } bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message, - bool *msg_is_ok) { + bool* msg_is_ok) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(process_handle_); @@ -139,21 +122,25 @@ int64 DOMStorageDispatcherHost::CloneSessionStorage(int64 original_id) { } void DOMStorageDispatcherHost::Send(IPC::Message* message) { - if (!resource_message_filter_) { - delete message; + if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { + // TODO(jorlow): Even if we successfully post, I believe it's possible for + // the task to never run (if the IO thread is already shutting + // down). We may want to handle this case, though + // realistically it probably doesn't matter. + if (!ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableMethod( + this, &DOMStorageDispatcherHost::Send, message))) { + // The IO thread is dead. + delete message; + } return; } - if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + if (!resource_message_filter_) + delete message; + else resource_message_filter_->Send(message); - return; - } - - // The IO thread can't go away while the WebKit thread is still running. - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); - ChromeThread::PostTask( - ChromeThread::IO, FROM_HERE, - NewRunnableMethod(this, &DOMStorageDispatcherHost::Send, message)); } void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id, diff --git a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h index fea147a..dad174e 100644 --- a/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h +++ b/chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h @@ -18,7 +18,6 @@ class GURL; class HostContentSettingsMap; class ResourceMessageFilter; class Task; -class WebKitThread; struct ViewMsg_DOMStorageEvent_Params; // This class handles the logistics of DOM Storage within the browser process. @@ -30,7 +29,7 @@ class DOMStorageDispatcherHost // Only call the constructor from the UI thread. DOMStorageDispatcherHost( ResourceMessageFilter* resource_message_filter_, - WebKitContext* webkit_context, WebKitThread* webkit_thread); + WebKitContext* webkit_context); // Only call from ResourceMessageFilter on the IO thread. void Init(int process_id, base::ProcessHandle process_handle); @@ -40,7 +39,7 @@ class DOMStorageDispatcherHost void Shutdown(); // Only call from ResourceMessageFilter on the IO thread. - bool OnMessageReceived(const IPC::Message& message, bool *msg_is_ok); + bool OnMessageReceived(const IPC::Message& message, bool* msg_is_ok); // Clones a session storage namespace and returns the cloned namespaces' id. // Only call on the IO thread. @@ -101,9 +100,6 @@ class DOMStorageDispatcherHost // Data shared between renderer processes with the same profile. scoped_refptr webkit_context_; - // ResourceDispatcherHost takes care of destruction. Immutable. - WebKitThread* webkit_thread_; - // Only set and use on the IO thread. ResourceMessageFilter* resource_message_filter_; diff --git a/chrome/browser/in_process_webkit/indexed_db_callbacks.cc b/chrome/browser/in_process_webkit/indexed_db_callbacks.cc new file mode 100644 index 0000000..82a48aa --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_callbacks.cc @@ -0,0 +1,29 @@ +// 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. + +#include "chrome/browser/in_process_webkit/indexed_db_callbacks.h" + +#include "base/logging.h" +#include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h" + +using WebKit::WebIDBDatabase; +using WebKit::WebSerializedScriptValue; + +IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* parent, + int32 response_id) + : parent_(parent), + response_id_(response_id) { +} + +IndexedDBCallbacks::~IndexedDBCallbacks() { +} + +void IndexedDBCallbacks::onSuccess(WebIDBDatabase* idb_database) { + NOTREACHED(); +} + +void IndexedDBCallbacks::onSuccess(const WebSerializedScriptValue& value) { + NOTREACHED(); +} + diff --git a/chrome/browser/in_process_webkit/indexed_db_callbacks.h b/chrome/browser/in_process_webkit/indexed_db_callbacks.h new file mode 100644 index 0000000..4b104a7 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_callbacks.h @@ -0,0 +1,37 @@ +// 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_CALLBACKS_H_ +#define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ + +#include "base/basictypes.h" +#include "base/ref_counted.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h" + +class IndexedDBDispatcherHost; + +class IndexedDBCallbacks : public WebKit::WebIDBCallbacks { + public: + IndexedDBCallbacks(IndexedDBDispatcherHost* parent, int32 response_id); + virtual ~IndexedDBCallbacks(); + + // We define default versions of these functions which simply DCHECK. + // For each WebIDBCallbacks implementation, there should only be one success + // callback that can possibly be called. + virtual void onSuccess(WebKit::WebIDBDatabase* idb_database); + virtual void onSuccess(const WebKit::WebSerializedScriptValue& value); + + protected: + IndexedDBDispatcherHost* parent() { return parent_.get(); } + int32 response_id() const { return response_id_; } + + private: + scoped_refptr parent_; + int32 response_id_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); +}; + +#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ + diff --git a/chrome/browser/in_process_webkit/indexed_db_context.cc b/chrome/browser/in_process_webkit/indexed_db_context.cc new file mode 100644 index 0000000..6235833 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_context.cc @@ -0,0 +1,24 @@ +// 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. + +#include "chrome/browser/in_process_webkit/indexed_db_context.h" + +#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" +#include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h" + +using WebKit::WebIDBDatabase; +using WebKit::WebIndexedDatabase; + +IndexedDBContext::IndexedDBContext() { +} + +IndexedDBContext::~IndexedDBContext() { +} + +WebIndexedDatabase* IndexedDBContext::GetIndexedDatabase() { + if (!indexed_database_.get()) + indexed_database_.reset(WebIndexedDatabase::create()); + DCHECK(indexed_database_.get()); + return indexed_database_.get(); +} diff --git a/chrome/browser/in_process_webkit/indexed_db_context.h b/chrome/browser/in_process_webkit/indexed_db_context.h new file mode 100644 index 0000000..07edd88 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_context.h @@ -0,0 +1,31 @@ +// 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_CONTEXT_H_ +#define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CONTEXT_H_ + +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/scoped_ptr.h" + +namespace WebKit { +class WebIndexedDatabase; +} + +class IndexedDBContext { + public: + IndexedDBContext(); + ~IndexedDBContext(); + + // TODO(jorlow): If this is all this class ever does, then we should kill it + // and move this variable to WebKitContext. + WebKit::WebIndexedDatabase* GetIndexedDatabase(); + + private: + scoped_ptr indexed_database_; + + DISALLOW_COPY_AND_ASSIGN(IndexedDBContext); +}; + +#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CONTEXT_H_ diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc new file mode 100644 index 0000000..7a114b1 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.cc @@ -0,0 +1,150 @@ +// 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. + +#include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h" + +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/in_process_webkit/indexed_db_callbacks.h" +#include "chrome/browser/renderer_host/resource_message_filter.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" + +using WebKit::WebIDBDatabase; +using WebKit::WebIDBDatabaseError; + +IndexedDBDispatcherHost::IndexedDBDispatcherHost( + IPC::Message::Sender* sender, WebKitContext* webkit_context) + : sender_(sender), + webkit_context_(webkit_context), + process_handle_(0) { + DCHECK(sender_); + DCHECK(webkit_context_.get()); +} + +IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { +} + +void IndexedDBDispatcherHost::Init(int process_id, + base::ProcessHandle process_handle) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + DCHECK(sender_); // Ensure Shutdown() has not been called. + DCHECK(!process_handle_); // Make sure Init() has not yet been called. + DCHECK(process_handle); + process_id_ = process_id; + process_handle_ = process_handle; +} + +void IndexedDBDispatcherHost::Shutdown() { + if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { + sender_ = NULL; + + bool success = ChromeThread::PostTask( + ChromeThread::WEBKIT, FROM_HERE, + NewRunnableMethod(this, &IndexedDBDispatcherHost::Shutdown)); + DCHECK(success); // The WebKit thread is always shutdown after the IO. + return; + } + + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); + DCHECK(!sender_); + + // TODO(jorlow): Do we still need this? +} + +bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message, + bool* msg_is_ok) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + DCHECK(process_handle_); + + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *msg_is_ok) + IPC_MESSAGE_HANDLER(ViewHostMsg_IndexedDatabaseOpen, OnIndexedDatabaseOpen) + IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseDestroyed, + OnIDBDatabaseDestroyed) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void IndexedDBDispatcherHost::Send(IPC::Message* message) { + if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { + // TODO(jorlow): Even if we successfully post, I believe it's possible for + // the task to never run (if the IO thread is already shutting + // down). We may want to handle this case, though + // realistically it probably doesn't matter. + if (!ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableMethod( + this, &IndexedDBDispatcherHost::Send, message))) { + // The IO thread is dead. + delete message; + } + return; + } + + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + if (!sender_) + delete message; + else + sender_->Send(message); +} + +int32 IndexedDBDispatcherHost::AddIDBDatabase(WebIDBDatabase* idb_database) { + return idb_database_map_.Add(idb_database); +} + +class IndexedDatabaseOpenCallbacks : public IndexedDBCallbacks { + public: + IndexedDatabaseOpenCallbacks(IndexedDBDispatcherHost* parent, + int32 response_id) + : IndexedDBCallbacks(parent, response_id) { + } + + virtual void onError(const WebIDBDatabaseError& error) { + parent()->Send(new ViewMsg_IndexedDatabaseOpenError( + response_id(), error.code(), error.message())); + } + + virtual void onSuccess(WebIDBDatabase* idb_database) { + int32 idb_database_id = parent()->AddIDBDatabase(idb_database); + parent()->Send(new ViewMsg_IndexedDatabaseOpenSuccess(response_id(), + idb_database_id)); + } +}; + +void IndexedDBDispatcherHost::OnIndexedDatabaseOpen( + const ViewHostMsg_IndexedDatabaseOpen_Params& params) { + // TODO(jorlow): Check the content settings map and use params.routing_id_ + // if it's necessary to ask the user for permission. + + if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { + ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( + this, &IndexedDBDispatcherHost::OnIndexedDatabaseOpen, params)); + return; + } + + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); + int exception_code = 0; + Context()->GetIndexedDatabase()->open( + params.name_, params.description_, params.modify_database_, + new IndexedDatabaseOpenCallbacks(this, params.response_id_), + params.origin_, NULL, exception_code); + // ViewHostMsg_IndexedDatabaseOpen is async because we assume the exception + // code is always 0 in the renderer side. + DCHECK(exception_code == 0); +} + +void IndexedDBDispatcherHost::OnIDBDatabaseDestroyed(int32 idb_database_id) { + if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { + ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( + this, &IndexedDBDispatcherHost::OnIDBDatabaseDestroyed, + idb_database_id)); + return; + } + + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); + idb_database_map_.Remove(idb_database_id); +} diff --git a/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h new file mode 100644 index 0000000..2a70748 --- /dev/null +++ b/chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h @@ -0,0 +1,85 @@ +// 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_ + +#include "base/basictypes.h" +#include "base/id_map.h" +#include "base/process.h" +#include "base/ref_counted.h" +#include "chrome/browser/in_process_webkit/webkit_context.h" +#include "ipc/ipc_message.h" + +struct ViewHostMsg_IndexedDatabaseOpen_Params; + +namespace WebKit { +class WebIDBDatabase; +} + +// Handles all IndexedDB related messages from a particular renderer process. +class IndexedDBDispatcherHost + : public base::RefCountedThreadSafe { + public: + // Only call the constructor from the UI thread. + IndexedDBDispatcherHost(IPC::Message::Sender* sender, + WebKitContext* webkit_context); + + // Only call from ResourceMessageFilter on the IO thread. + void Init(int process_id, base::ProcessHandle process_handle); + + // Only call from ResourceMessageFilter on the IO thread. Calls self on the + // WebKit thread in some cases. + void Shutdown(); + + // Only call from ResourceMessageFilter on the IO thread. + bool OnMessageReceived(const IPC::Message& message, bool* msg_is_ok); + + // Send a message to the renderer process associated with our sender_ via the + // IO thread. May be called from any thread. + void Send(IPC::Message* message); + + // A shortcut for accessing our context. + IndexedDBContext* Context() { + return webkit_context_->indexed_db_context(); + } + + // The various IndexedDBCallbacks children call these methods to add the + // results into the applicable map. See below for more details. + int32 AddIDBDatabase(WebKit::WebIDBDatabase* idb_database); + // TODO(andreip/jorlow): Add functions for other maps here. + + private: + friend class base::RefCountedThreadSafe; + ~IndexedDBDispatcherHost(); + + // IndexedDB message handlers. + void OnIndexedDatabaseOpen( + const ViewHostMsg_IndexedDatabaseOpen_Params& params); + void OnIDBDatabaseDestroyed(int32 idb_database_id); + + // Only use on the IO thread. + IPC::Message::Sender* sender_; + + // Data shared between renderer processes with the same profile. + scoped_refptr webkit_context_; + + // 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 + idb_database_map_; + // TODO(andreip/jorlow): Add other maps here. + + // If we get a corrupt message from a renderer, we need to kill it using this + // handle. + base::ProcessHandle process_handle_; + + // Used to dispatch messages to the correct view host. + int process_id_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); +}; + +#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_DISPATCHER_HOST_H_ diff --git a/chrome/browser/in_process_webkit/webkit_context.cc b/chrome/browser/in_process_webkit/webkit_context.cc index be07568..b9cf36f 100644 --- a/chrome/browser/in_process_webkit/webkit_context.cc +++ b/chrome/browser/in_process_webkit/webkit_context.cc @@ -5,12 +5,14 @@ #include "chrome/browser/in_process_webkit/webkit_context.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/profile.h" -WebKitContext::WebKitContext(const FilePath& data_path, bool is_incognito) - : data_path_(data_path), - is_incognito_(is_incognito), +WebKitContext::WebKitContext(Profile* profile) + : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), + is_incognito_(profile->IsOffTheRecord()), ALLOW_THIS_IN_INITIALIZER_LIST( - dom_storage_context_(new DOMStorageContext(this))) { + dom_storage_context_(new DOMStorageContext(this))), + indexed_db_context_(new IndexedDBContext()) { } WebKitContext::~WebKitContext() { diff --git a/chrome/browser/in_process_webkit/webkit_context.h b/chrome/browser/in_process_webkit/webkit_context.h index 82fa12d..7f18f88 100644 --- a/chrome/browser/in_process_webkit/webkit_context.h +++ b/chrome/browser/in_process_webkit/webkit_context.h @@ -10,8 +10,9 @@ #include "base/scoped_ptr.h" #include "base/time.h" #include "chrome/browser/in_process_webkit/dom_storage_context.h" +#include "chrome/browser/in_process_webkit/indexed_db_context.h" -class WebKitThread; +class Profile; // There's one WebKitContext per profile. Various DispatcherHost classes // have a pointer to the Context to store shared state. Unfortunately, this @@ -22,14 +23,19 @@ class WebKitThread; // threads. class WebKitContext : public base::RefCountedThreadSafe { public: - WebKitContext(const FilePath& data_path, bool is_incognito); + explicit WebKitContext(Profile* profile); const FilePath& data_path() const { return data_path_; } bool is_incognito() const { return is_incognito_; } + DOMStorageContext* dom_storage_context() { return dom_storage_context_.get(); } + IndexedDBContext* indexed_db_context() { + return indexed_db_context_.get(); + } + #ifdef UNIT_TEST // For unit tests, allow specifying a DOMStorageContext directly so it can be // mocked. @@ -60,6 +66,8 @@ class WebKitContext : public base::RefCountedThreadSafe { scoped_ptr dom_storage_context_; + scoped_ptr indexed_db_context_; + DISALLOW_IMPLICIT_CONSTRUCTORS(WebKitContext); }; diff --git a/chrome/browser/in_process_webkit/webkit_context_unittest.cc b/chrome/browser/in_process_webkit/webkit_context_unittest.cc index 98ccfd0..9158495 100644 --- a/chrome/browser/in_process_webkit/webkit_context_unittest.cc +++ b/chrome/browser/in_process_webkit/webkit_context_unittest.cc @@ -5,6 +5,7 @@ #include "chrome/browser/chrome_thread.h" #include "chrome/browser/in_process_webkit/dom_storage_context.h" #include "chrome/browser/in_process_webkit/webkit_context.h" +#include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" class MockDOMStorageContext : public DOMStorageContext { @@ -27,14 +28,15 @@ class MockDOMStorageContext : public DOMStorageContext { }; TEST(WebKitContextTest, Basic) { - FilePath file_path; - scoped_refptr context1(new WebKitContext(file_path, true)); - EXPECT_TRUE(file_path == context1->data_path()); - EXPECT_TRUE(context1->is_incognito()); - - scoped_refptr context2(new WebKitContext(file_path, false)); - EXPECT_TRUE(file_path == context2->data_path()); - EXPECT_FALSE(context2->is_incognito()); + TestingProfile profile; + + scoped_refptr context1(new WebKitContext(&profile)); + EXPECT_TRUE(profile.GetPath() == context1->data_path()); + EXPECT_TRUE(profile.IsOffTheRecord() == context1->is_incognito()); + + scoped_refptr context2(new WebKitContext(&profile)); + EXPECT_TRUE(context1->data_path() == context2->data_path()); + EXPECT_TRUE(context1->is_incognito() == context2->is_incognito()); } TEST(WebKitContextTest, PurgeMemory) { @@ -44,7 +46,8 @@ TEST(WebKitContextTest, PurgeMemory) { webkit_thread.Start(); // Create the contexts. - scoped_refptr context(new WebKitContext(FilePath(), false)); + TestingProfile profile; + scoped_refptr context(new WebKitContext(&profile)); MockDOMStorageContext* mock_context = new MockDOMStorageContext(context.get()); context->set_dom_storage_context(mock_context); // Takes ownership. -- cgit v1.1