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

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

Issue 311733004: Introduce KeepAliveWhilePending to ScriptPromiseResolverWithContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@refactor-webmidi-initialization
Patch Set: Created 6 years, 6 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
Index: Source/modules/crypto/CrossThreadCryptoResult.h
diff --git a/Source/modules/crypto/CrossThreadCryptoResult.h b/Source/modules/crypto/CrossThreadCryptoResult.h
new file mode 100644
index 0000000000000000000000000000000000000000..c524a1d0c80dd3e5caf41b28c57d17fee30624f3
--- /dev/null
+++ b/Source/modules/crypto/CrossThreadCryptoResult.h
@@ -0,0 +1,71 @@
+// Copyright 2014 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 CrossThreadCryptoResult_h
+#define CrossThreadCryptoResult_h
+
+#include "core/dom/ExceptionCode.h"
+#include "platform/CryptoResult.h"
+#include "public/platform/WebCrypto.h"
+#include "wtf/WeakPtr.h"
+
+namespace WebCore {
+
+// Wrapper around a Promise to notify completion of the crypto operation.
+//
+// CrossThreadCryptoResult<T> inherits CryptoResult, where T must inherit
+// CryptoResult as well.
+// The thread on which CrossThreadCryptoResult 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.
+template<typename T>
+class CrossThreadCryptoResult FINAL : public CryptoResult {
+public:
+ ~CrossThreadCryptoResult() { }
+
+ static PassRefPtr<CrossThreadCryptoResult> create(WeakPtr<T> result)
+ {
+ return adoptRef(new CrossThreadCryptoResult(result));
+ }
+
+ // CryptoResult implementation
+ virtual void completeWithError(blink::WebCryptoErrorType type, const blink::WebString& message) OVERRIDE
+ {
+ if (m_result)
+ m_result->completeWithError(type, message);
+ }
+ virtual void completeWithBuffer(const blink::WebArrayBuffer& buffer) OVERRIDE
+ {
+ if (m_result)
+ m_result->completeWithBuffer(buffer);
+ }
+ virtual void completeWithBoolean(bool b) OVERRIDE
+ {
+ if (m_result)
+ m_result->completeWithBoolean(b);
+ }
+ virtual void completeWithKey(const blink::WebCryptoKey& key) OVERRIDE
+ {
+ if (m_result)
+ m_result->completeWithKey(key);
+ }
+ virtual void completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey) OVERRIDE
+ {
+ if (m_result)
+ m_result->completeWithKeyPair(publicKey, privateKey);
+ }
+
+private:
+ explicit CrossThreadCryptoResult(WeakPtr<T> result)
+ : m_result(result) { }
+
+ WeakPtr<T> m_result;
+};
+
+} // namespace WebCore
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698