diff options
author | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 09:36:07 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 09:36:07 +0000 |
commit | 6ee12c40c7888500e87b33fb1993faf3d689eb09 (patch) | |
tree | 5db10a6c2c6d5466f906952d3c87f5c4534bf685 /chrome/browser/in_process_webkit | |
parent | c0f533f2784bb98483b29d68609a5118dd86c92a (diff) | |
download | chromium_src-6ee12c40c7888500e87b33fb1993faf3d689eb09.zip chromium_src-6ee12c40c7888500e87b33fb1993faf3d689eb09.tar.gz chromium_src-6ee12c40c7888500e87b33fb1993faf3d689eb09.tar.bz2 |
Fix SessionStorage
Apparently the session storage code was pretty horribly broken. It didn't correctly handle tabs being restored, didn't have the proper lifetime (this was the issue exposed in the bug), and had many leaks.
To fix this, things had to be plumbed fairly differently. We need to pass session storage in on TabContents creation to ensure that the first RenderView will have the correct session storage id. When closing a tab, we need to save the session storage with the restoration service. When restoring a tab, we pass it back into the tab contents class. When duplicating a tab, we clone the storage.
Lifetimes are now handled by standard reference counting code. A SessionStorageNamespace object wraps an ID. When it's instantiated, it allocates an ID. When it's destroyed, it deletes the ID. IDs make this process very lightweight (the heavyweight stuff is allocated on first use of SessionStorage) and it seperates the more complex lifetimes of SessionStorage namespaces (where less deterministic shutdown is more tollerable) from the LocalStorage namespace which needs to shutdown very precisely.
BUG=52393
TEST=Set some variable on session storage; close the tab; re-open the tab; the variable should still be set. You can also run through the repro steps in the bug.
Review URL: http://codereview.chromium.org/3325012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59350 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/in_process_webkit')
4 files changed, 81 insertions, 2 deletions
diff --git a/chrome/browser/in_process_webkit/session_storage_namespace.cc b/chrome/browser/in_process_webkit/session_storage_namespace.cc new file mode 100644 index 0000000..cfa2a5a --- /dev/null +++ b/chrome/browser/in_process_webkit/session_storage_namespace.cc @@ -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. + +#include "chrome/browser/in_process_webkit/session_storage_namespace.h" + +#include "chrome/browser/in_process_webkit/dom_storage_context.h" +#include "chrome/browser/in_process_webkit/webkit_context.h" +#include "chrome/browser/profile.h" + +SessionStorageNamespace::SessionStorageNamespace(Profile* profile) + : webkit_context_(profile->GetWebKitContext()), + id_(webkit_context_->dom_storage_context() + ->AllocateSessionStorageNamespaceId()) { +} + +SessionStorageNamespace::SessionStorageNamespace(WebKitContext* webkit_context, + int64 id) + : webkit_context_(webkit_context), + id_(id) { +} + +SessionStorageNamespace::~SessionStorageNamespace() { + webkit_context_->DeleteSessionStorageNamespace(id_); +} + +SessionStorageNamespace* SessionStorageNamespace::Clone() { + return new SessionStorageNamespace( + webkit_context_, + webkit_context_->dom_storage_context()->CloneSessionStorage(id_)); +} diff --git a/chrome/browser/in_process_webkit/session_storage_namespace.h b/chrome/browser/in_process_webkit/session_storage_namespace.h new file mode 100644 index 0000000..364882a --- /dev/null +++ b/chrome/browser/in_process_webkit/session_storage_namespace.h @@ -0,0 +1,46 @@ +// 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_SESSION_STORAGE_NAMESPACE_H_ +#define CHROME_BROWSER_IN_PROCESS_WEBKIT_SESSION_STORAGE_NAMESPACE_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/ref_counted.h" + +class Profile; +class WebKitContext; + +// This is a ref-counted class that represents a SessionStorageNamespace. +// On destruction it ensures that the storage namespace is destroyed. +// NOTE: That if we're shutting down, we don't strictly need to do this, but +// it keeps valgrind happy. +class SessionStorageNamespace + : public base::RefCountedThreadSafe<SessionStorageNamespace> { + public: + explicit SessionStorageNamespace(Profile* profile); + + int64 id() const { return id_; } + + // The session storage namespace parameter allows multiple render views and + // tab contentses to share the same session storage (part of the WebStorage + // spec) space. Passing in NULL simply allocates a new one which is often the + // correct thing to do (especially in tests. + SessionStorageNamespace* Clone(); + + private: + SessionStorageNamespace(WebKitContext* webkit_context, int64 id); + + friend class base::RefCountedThreadSafe<SessionStorageNamespace>; + ~SessionStorageNamespace(); + + scoped_refptr<WebKitContext> webkit_context_; + + // The session storage namespace id. + int64 id_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(SessionStorageNamespace); +}; + +#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_SESSION_STORAGE_NAMESPACE_H_ diff --git a/chrome/browser/in_process_webkit/webkit_context.cc b/chrome/browser/in_process_webkit/webkit_context.cc index ae1665a..0af2c2d 100644 --- a/chrome/browser/in_process_webkit/webkit_context.cc +++ b/chrome/browser/in_process_webkit/webkit_context.cc @@ -4,8 +4,10 @@ #include "chrome/browser/in_process_webkit/webkit_context.h" +#include "base/command_line.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/profile.h" +#include "chrome/common/chrome_switches.h" WebKitContext::WebKitContext(Profile* profile) : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), diff --git a/chrome/browser/in_process_webkit/webkit_context.h b/chrome/browser/in_process_webkit/webkit_context.h index 26e0621..be20825c 100644 --- a/chrome/browser/in_process_webkit/webkit_context.h +++ b/chrome/browser/in_process_webkit/webkit_context.h @@ -56,8 +56,8 @@ class WebKitContext : public base::RefCountedThreadSafe<WebKitContext> { const char* url_scheme_to_be_skipped, const std::vector<string16>& protected_origins); - // Delete the session storage namespace associated with this id. Called from - // the UI thread. + // Delete the session storage namespace associated with this id. Can be + // called from any thread. void DeleteSessionStorageNamespace(int64 session_storage_namespace_id); private: |