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

Unified Diff: Source/modules/crypto/CryptoResultImpl.h

Issue 253563002: [webcrypto] Make it safe to delete WebCryptoResult from any thread. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 8 months 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
« no previous file with comments | « no previous file | Source/modules/crypto/CryptoResultImpl.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/CryptoResultImpl.h
diff --git a/Source/modules/crypto/CryptoResultImpl.h b/Source/modules/crypto/CryptoResultImpl.h
index f4fa76bf8d38620bbb0cd41a51d33b7206ddcb13..94df5aabaf0f2e8c4746acca157963a5b30233e8 100644
--- a/Source/modules/crypto/CryptoResultImpl.h
+++ b/Source/modules/crypto/CryptoResultImpl.h
@@ -32,19 +32,24 @@
#define CryptoResultImpl_h
#include "bindings/v8/ScriptPromise.h"
-#include "bindings/v8/ScriptPromiseResolverWithContext.h"
-#include "core/dom/ContextLifecycleObserver.h"
#include "platform/CryptoResult.h"
#include "public/platform/WebCrypto.h"
-#include "wtf/Assertions.h"
#include "wtf/Forward.h"
-#include "wtf/Threading.h"
+#include "wtf/WeakPtr.h"
namespace WebCore {
// Wrapper around a Promise to notify completion of the crypto operation.
-// Platform cannot know about Promises which are declared in bindings.
-class CryptoResultImpl FINAL : public CryptoResult, public ContextLifecycleObserver {
+//
+// The thread on which CryptoResultImpl was created on is referred to as the
+// "origin thread".
+//
+// * At creation time there must be an active ExecutionContext.
+// * The CryptoResult interface must only be called from the origin thread.
+// * addref() and deref() can be called from any thread.
+// * One of the completeWith***() functions must be called, or the
+// PromiseState will be leaked until the ExecutionContext is destroyed.
+class CryptoResultImpl FINAL : public CryptoResult {
public:
~CryptoResultImpl();
@@ -57,27 +62,14 @@ public:
virtual void completeWithKey(const blink::WebCryptoKey&) OVERRIDE;
virtual void completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey) OVERRIDE;
- ScriptPromise promise() { return m_promiseResolver->promise(); }
+ // It is only valid to call this before completion.
+ ScriptPromise promise();
private:
- CryptoResultImpl(ExecutionContext*);
- void finish();
- void CheckValidThread() const;
+ explicit CryptoResultImpl(ExecutionContext*);
- // Override from ContextLifecycleObserver
- virtual void contextDestroyed() OVERRIDE;
-
- // Returns true if the ExecutionContext is still alive and running.
- bool canCompletePromise() const;
-
- void clearPromiseResolver();
-
- RefPtr<ScriptPromiseResolverWithContext> m_promiseResolver;
-
-#if !ASSERT_DISABLED
- ThreadIdentifier m_owningThread;
- bool m_finished;
-#endif
+ class PromiseState;
+ WeakPtr<PromiseState> m_promiseState;
};
} // namespace WebCore
« no previous file with comments | « no previous file | Source/modules/crypto/CryptoResultImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698