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

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

Issue 1228373006: Reliably cancel in-progress CryptoResult(Impl) upon shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: have WebCryptoResult::commit*() be gated on cancellation status Created 5 years, 5 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 b6cb6e90126c8290fdfbbd3a2172afc230868247..a8b99af7b81cb9c10b33d574d0d35c65971f4d92 100644
--- a/Source/modules/crypto/CryptoResultImpl.h
+++ b/Source/modules/crypto/CryptoResultImpl.h
@@ -40,7 +40,6 @@
namespace blink {
-class ScriptPromiseResolver;
MODULES_EXPORT ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType);
// Wrapper around a Promise to notify completion of the crypto operation.
@@ -50,27 +49,36 @@ MODULES_EXPORT ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType);
//
// * At creation time there must be an active ExecutionContext.
// * The CryptoResult interface must only be called from the origin thread.
-// * ref(), deref(), cancelled() and cancel() can be called from any thread.
+// * cancel() can only be called from the origin thread.
+// * ref(), deref() can be called from any thread.
// * One of the completeWith***() functions must be called, or the
// m_resolver will be leaked until the ExecutionContext is destroyed.
class CryptoResultImpl final : public CryptoResult {
public:
- ~CryptoResultImpl();
-
static PassRefPtrWillBeRawPtr<CryptoResultImpl> create(ScriptState*);
+ ~CryptoResultImpl();
+
void completeWithError(WebCryptoErrorType, const WebString&) override;
void completeWithBuffer(const void* bytes, unsigned bytesSize) override;
void completeWithJson(const char* utf8Data, unsigned length) override;
void completeWithBoolean(bool) override;
void completeWithKey(const WebCryptoKey&) override;
void completeWithKeyPair(const WebCryptoKey& publicKey, const WebCryptoKey& privateKey) override;
- bool cancelled() const override;
// If called after completion (including cancellation) will return an empty
// ScriptPromise.
ScriptPromise promise();
+ WebCryptoResult result()
+ {
+ return WebCryptoResult(this);
+ }
+
+ void assignedTo(WebCryptoResult*) override;
+
+ DECLARE_VIRTUAL_TRACE();
+
private:
class Resolver;
explicit CryptoResultImpl(ScriptState*);
@@ -78,12 +86,21 @@ private:
void clearResolver();
void cancel();
- // FIXME: ScriptPromiseResolver should not be exported.
- // Instead, use ScriptPromise.
- ScriptPromiseResolver* m_resolver;
- volatile int m_cancelled;
+ RawPtrWillBeMember<Resolver> m_resolver;
+
+ // To reliably allow a WebCrypto-using execution context to shut down while
+ // crypto operations it has issued are still underway, keep track of the
+ // WebCrypto reference that keeps each CryptoResultImpl alive.
+ //
+ // Should the execution context be stop()ped, this keep-alive reference is
+ // eagerly cancelled and cleared out. The execution context can then
+ // proceed and shut down tidily.
+ //
+ // When the corresponding crypto operation eventually completes, it'll
+ // notice the cancellation and act accordingly.
+ WebCryptoResult* m_resultOwner;
eroman 2015/07/15 21:34:06 This doesn't make sense. WebCryptoResult is a cop
};
} // namespace blink
-#endif
+#endif // CryptoResultImpl_h
« 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